diff --git a/src/Dev/Deprecation.php b/src/Dev/Deprecation.php index 81d9be590b3..16c94b02575 100644 --- a/src/Dev/Deprecation.php +++ b/src/Dev/Deprecation.php @@ -144,6 +144,9 @@ public static function withSuppressedNotice(callable $func): mixed */ protected static function get_called_method_from_trace($backtrace, $level = 1) { + if ($backtrace === null) { + return ''; + } $level = (int)$level; if (!$level) { $level = 1; @@ -188,8 +191,11 @@ private static function get_called_from_trace(array $backtrace, int $level): arr return $called; } - private static function isCalledFromSupportedCode(array $backtrace): bool + private static function isCalledFromSupportedCode(?array $backtrace): bool { + if ($backtrace === null) { + return false; + } $called = Deprecation::get_called_from_trace($backtrace, 1); $file = $called['file'] ?? ''; if (!$file) { diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 07c4fc9eda2..c53d6d51d7a 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -1338,32 +1338,8 @@ public function validate(): ValidationResult * form that has some fields that save to one object, and some that save to another. * @return $this */ - public function loadDataFrom($data, $mergeStrategy = 0, $fieldList = null) + public function loadDataFrom(object|array $data, int $mergeStrategy = 0, array $fieldList = []) { - if (!is_object($data) && !is_array($data)) { - user_error("Form::loadDataFrom() not passed an array or an object", E_USER_WARNING); - return $this; - } - - // Handle the backwards compatible case of passing "true" as the second argument - if ($mergeStrategy === true) { - Deprecation::notice( - '5.4.0', - 'Passing `true` to the $mergeStrategy argument in ' . Form::class . '::loadDataFrom() is deprecated.' - . ' Pass ' . Form::class . '::MERGE_CLEAR_MISSING instead.', - Deprecation::SCOPE_GLOBAL - ); - $mergeStrategy = Form::MERGE_CLEAR_MISSING; - } elseif ($mergeStrategy === false) { - Deprecation::notice( - '5.4.0', - 'Passing `false` to the $mergeStrategy argument in ' . Form::class . '::loadDataFrom() is deprecated.' - . ' Pass 0 instead.', - Deprecation::SCOPE_GLOBAL - ); - $mergeStrategy = 0; - } - // If an object is passed, save it for historical reference through {@link getRecord()} // Also use this to determine if we are loading a submitted form, or loading // from a record @@ -1392,7 +1368,7 @@ public function loadDataFrom($data, $mergeStrategy = 0, $fieldList = null) $name = $field->getName(); // Skip fields that have been excluded - if ($fieldList && !in_array($name, $fieldList ?? [])) { + if (!empty($fieldList) && !in_array($name, $fieldList)) { continue; } diff --git a/src/Forms/SearchableDropdownField.php b/src/Forms/SearchableDropdownField.php index 5f459ad6634..371b527f491 100644 --- a/src/Forms/SearchableDropdownField.php +++ b/src/Forms/SearchableDropdownField.php @@ -27,18 +27,6 @@ public function __construct( $this->setHasEmptyDefault(true); } - /** - * @param string $string - * @return $this - * - * @deprecated 5.2.0 Use setPlaceholder() instead - */ - public function setEmptyString($string) - { - Deprecation::notice('5.2.0', 'Use setPlaceholder() instead'); - return parent::setEmptyString($string); - } - public function getValueForValidation(): mixed { $arr = $this->getValueArray(); diff --git a/src/Forms/SearchableDropdownTrait.php b/src/Forms/SearchableDropdownTrait.php index a01697aabf2..b5d794726db 100644 --- a/src/Forms/SearchableDropdownTrait.php +++ b/src/Forms/SearchableDropdownTrait.php @@ -158,8 +158,7 @@ public function getPlaceholder(): string * Calling this will also call setHasEmptyDefault(true), if the method exists on the class, * which is required for the placeholder functionality to work on SearchableDropdownField * - * In the case of SearchableDropField this method should be used instead of setEmptyString() which - * will be remvoved in a future version + * In the case of SearchableDropField this method should be used instead of setEmptyString() */ public function setPlaceholder(string $placeholder): static { diff --git a/src/ORM/Connect/MySQLDatabase.php b/src/ORM/Connect/MySQLDatabase.php index 075c44eaf4f..45efc2482ea 100644 --- a/src/ORM/Connect/MySQLDatabase.php +++ b/src/ORM/Connect/MySQLDatabase.php @@ -207,16 +207,9 @@ public function searchEngine( } } - // Always ensure that only pages with ShowInSearch = 1 can be searched + // Always ensure that only pages/files with ShowInSearch = 1 can be searched $extraFilters[$pageClass] .= " AND ShowInSearch <> 0"; - - // File.ShowInSearch was added later, keep the database driver backwards compatible - // by checking for its existence first - $fileTable = DataObject::getSchema()->tableName($fileClass); - $fields = $this->getSchemaManager()->fieldList($fileTable); - if (array_key_exists('ShowInSearch', $fields ?? [])) { - $extraFilters[$fileClass] .= " AND ShowInSearch <> 0"; - } + $extraFilters[$fileClass] .= " AND ShowInSearch <> 0"; $limit = (int)$start . ", " . (int)$pageLength; diff --git a/src/ORM/Connect/MySQLiConnector.php b/src/ORM/Connect/MySQLiConnector.php index e480f5db9bf..2c60d57ca1f 100644 --- a/src/ORM/Connect/MySQLiConnector.php +++ b/src/ORM/Connect/MySQLiConnector.php @@ -315,7 +315,12 @@ public function preparedQuery($sql, $parameters, $errorLevel = E_USER_ERROR) } // Safely execute the statement - $statement->execute(); + try { + $statement->execute(); + } catch (mysqli_sql_exception $e) { + $success = false; + $this->databaseError($e->getMessage(), E_USER_ERROR, $sql, $parameters); + } } if (!$success || $statement->error) { diff --git a/src/ORM/DataObject.php b/src/ORM/DataObject.php index 28da655b35b..2f0903d4c9b 100644 --- a/src/ORM/DataObject.php +++ b/src/ORM/DataObject.php @@ -2682,21 +2682,7 @@ public function getCMSActions() public function getCMSCompositeValidator(): CompositeValidator { $compositeValidator = CompositeValidator::create(); - - // Support for the old method during the deprecation period - if ($this->hasMethod('getCMSValidator')) { - Deprecation::notice( - '5.4.0', - 'The getCMSValidator() method is deprecated and won\'t be supported in a future major release.' - . ' Override getCMSCompositeValidator() instead.', - Deprecation::SCOPE_GLOBAL - ); - $compositeValidator->addValidator($this->getCMSValidator()); - } - - // Extend validator - forward support, will be supported beyond 5.0.0 $this->invokeWithExtensions('updateCMSCompositeValidator', $compositeValidator); - return $compositeValidator; } diff --git a/tests/php/Forms/GridField/GridFieldDetailFormTest/Person.php b/tests/php/Forms/GridField/GridFieldDetailFormTest/Person.php index ce97268c0e6..2717fed2019 100644 --- a/tests/php/Forms/GridField/GridFieldDetailFormTest/Person.php +++ b/tests/php/Forms/GridField/GridFieldDetailFormTest/Person.php @@ -5,6 +5,7 @@ use SilverStripe\Dev\TestOnly; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; +use SilverStripe\Forms\Validation\CompositeValidator; use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObjectSchema; @@ -65,14 +66,16 @@ public function getCMSFields() return $fields; } - public function getCMSValidator() + public function getCMSCompositeValidator(): CompositeValidator { - return new RequiredFieldsValidator( + $validator = parent::getCMSCompositeValidator(); + $validator->addValidator(new RequiredFieldsValidator( [ 'FirstName', 'Surname' ] - ); + )); + return $validator; } public function getCMSEditLink(): ?string diff --git a/tests/php/i18n/i18nTextCollectorTest.php b/tests/php/i18n/i18nTextCollectorTest.php index 5c96f1e6637..ca30c10713c 100644 --- a/tests/php/i18n/i18nTextCollectorTest.php +++ b/tests/php/i18n/i18nTextCollectorTest.php @@ -83,7 +83,7 @@ public function testCollectFromNewTemplateSyntaxUsingParserSubclass() $mymodule = ModuleLoader::inst()->getManifest()->getModule('i18ntestmodule'); $html = << + <%t Test.SINGLEQUOTE 'Single Quote' %> <%t i18nTestModule.NEWMETHODSIG "New _t method signature test" %> <%t i18nTestModule.INJECTIONS_0 "Hello {name} {greeting}, and {goodbye}" name="Mark" greeting="welcome" goodbye="bye" %> <%t i18nTestModule.INJECTIONS_1 "Hello {name} {greeting}, and {goodbye}" name="Paul" greeting="welcome" goodbye="cya" %>