From 3a8656289ef2fcc407d3b01382b796f4022e6432 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 9 Jan 2025 13:50:00 +1300 Subject: [PATCH] ENH Remove code that had been retained for backwards compatibility We don't need to retain this compatibility anymore. Some of this is dead code, and some is just tech debt that should have been properly deprecated. --- src/Forms/Form.php | 19 ++----------------- src/Forms/FormRequestHandler.php | 2 +- src/ORM/Connect/MySQLDatabase.php | 11 ++--------- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 440ba4b5224..c53d6d51d7a 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -1334,27 +1334,12 @@ public function validate(): ValidationResult * do not want them parsed as submitted data. MERGE_AS_SUBMITTED_VALUE does the opposite and forces the data to be * parsed as it would be submitted from a form. * - * For backwards compatibility reasons, this parameter can also be set to === true, which is the same as passing - * MERGE_CLEAR_MISSING - * * @param array $fieldList An optional list of fields to process. This can be useful when you have a * 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) { - $mergeStrategy = Form::MERGE_CLEAR_MISSING; - } elseif ($mergeStrategy === false) { - $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 @@ -1383,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/FormRequestHandler.php b/src/Forms/FormRequestHandler.php index b72df564d7e..8d7bec85d44 100644 --- a/src/Forms/FormRequestHandler.php +++ b/src/Forms/FormRequestHandler.php @@ -133,7 +133,7 @@ public function httpSubmission($request) $allowedFields = array_keys($this->form->Fields()->saveableFields() ?? []); // Populate the form - $this->form->loadDataFrom($vars, true, $allowedFields); + $this->form->loadDataFrom($vars, Form::MERGE_CLEAR_MISSING, $allowedFields); // Protection against CSRF attacks $token = $this->form->getSecurityToken(); 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;