Skip to content

Commit

Permalink
Move dropdown field SQL name handling at right place
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Jun 3, 2022
1 parent 233180c commit 1991086
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
19 changes: 0 additions & 19 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']));
}
Expand All @@ -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) {
Expand All @@ -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']);
}
Expand Down
3 changes: 3 additions & 0 deletions inc/migration.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 1991086

Please sign in to comment.