From 19910869cfff033caefde5386d552788eb577376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Fri, 3 Jun 2022 11:13:19 +0200 Subject: [PATCH] Move dropdown field SQL name handling at right place --- inc/field.class.php | 19 ------------------- inc/migration.class.php | 3 +++ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/inc/field.class.php b/inc/field.class.php index febe0e26..7488bd26 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -171,10 +171,6 @@ function prepareInputForAdd($input) { ); return false; } - - $oldname = $input['name']; - $input['name'] = getForeignKeyFieldForItemType( - PluginFieldsDropdown::getClassname($input['name'])); } // Before adding, add the ranking of the new field @@ -192,10 +188,6 @@ function prepareInputForAdd($input) { } } - if (isset($oldname)) { - $input['name'] = $oldname; - } - if (isset($input['allowed_values'])) { $input['allowed_values'] = Sanitizer::dbEscape(json_encode($input['allowed_values'])); } @@ -210,13 +202,6 @@ function pre_deleteItem() { if ($this->fields['type'] !== "header" && !isset($_SESSION['uninstall_fields']) && !isset($_SESSION['delete_container'])) { - - if ($this->fields['type'] === "dropdown") { - $oldname = $this->fields['name']; - $this->fields['name'] = getForeignKeyFieldForItemType( - PluginFieldsDropdown::getClassname($this->fields['name'])); - } - $container_obj = new PluginFieldsContainer; $container_obj->getFromDB($this->fields['plugin_fields_containers_id']); foreach (json_decode($container_obj->fields['itemtypes']) as $itemtype) { @@ -232,10 +217,6 @@ function pre_deleteItem() { 'items_id' => $this->fields['id'] ]); - if (isset($oldname)) { - $this->fields['name'] = $oldname; - } - if ($this->fields['type'] === "dropdown") { return PluginFieldsDropdown::destroy($this->fields['name']); } diff --git a/inc/migration.class.php b/inc/migration.class.php index 102cafba..376d21a0 100644 --- a/inc/migration.class.php +++ b/inc/migration.class.php @@ -96,6 +96,9 @@ public static function getSQLFields(string $field_name, string $field_type): arr break; case $field_type === 'dropdown': case preg_match('/^dropdown-.+/i', $field_type): + if ($field_type === 'dropdown') { + $field_name = getForeignKeyFieldForItemType(PluginFieldsDropdown::getClassname($field_name)); + } $fields[$field_name] = "INT {$default_key_sign} NOT NULL DEFAULT 0"; break; case $field_type === 'textarea':