From 3d6917cda11efb98c09412068d3bc5bdea84d67d Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Sun, 9 Sep 2018 23:48:10 +0200 Subject: [PATCH] fix(isntal): fix upgrade to 2.5.0 Signed-off-by: Thierry Bugier --- install/update_0.0_2.5.php | 31 ++-------------------------- install/update_2.5_2.6.php | 42 ++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 51 deletions(-) diff --git a/install/update_0.0_2.5.php b/install/update_0.0_2.5.php index 067b620b8..9a43a22ad 100644 --- a/install/update_0.0_2.5.php +++ b/install/update_0.0_2.5.php @@ -200,32 +200,7 @@ function plugin_formcreator_updateForm_Answer_2_5(Migration $migration) { $migration->addKey('glpi_plugin_formcreator_forms_answers', 'requester_id'); $migration->addKey('glpi_plugin_formcreator_forms_answers', 'validator_id'); $migration->addField('glpi_plugin_formcreator_forms_answers', 'is_deleted', 'bool'); - - // Update Form Answers - $table = 'glpi_plugin_formcreator_forms_answers'; - - if ($DB->fieldExists($table, 'validator_id', false)) { - $migration->addField($table, 'users_id_validator', 'integer', ['after' => 'requester_id']); - $migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']); - $migration->addKey($table, 'users_id_validator'); - $migration->addKey($table, 'groups_id_validator'); - $migration->migrationOneTable($table); - - $formTable = 'glpi_plugin_formcreator_forms'; - $query = "UPDATE `$table` - INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `users_id_validator` = 'validator_id' - WHERE `$formTable`.`validation_required` = '1'"; - $DB->query($query) or plugin_formcreator_upgrade_error($migration); - $query = "UPDATE `$table` - INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `groups_id_validator` = 'validator_id' - WHERE `$formTable`.`validation_required` = '2'"; - $DB->query($query) or plugin_formcreator_upgrade_error($migration); - - $migration->dropKey($table, 'validator_id'); - $migration->dropField($table, 'validator_id'); - } + $migration->migrationOneTable('glpi_plugin_formcreator_forms_answers'); } function plugin_formcreator_updateForm_Profile_2_5(Migration $migration) { @@ -453,7 +428,7 @@ function plugin_formcreator_updateIssue_2_5(Migration $migration) { `fanswer`.`entities_id` AS `entities_id`, `fanswer`.`is_recursive` AS `is_recursive`, `fanswer`.`requester_id` AS `requester_id`, - `fanswer`.`users_id_validator` AS `validator_id`, + `fanswer`.`validator_id` AS `validator_id`, `fanswer`.`comment` AS `comment` FROM `glpi_plugin_formcreator_forms_answers` AS `fanswer` LEFT JOIN `glpi_plugin_formcreator_forms` AS `f` @@ -464,9 +439,7 @@ function plugin_formcreator_updateIssue_2_5(Migration $migration) { WHERE `fanswer`.`is_deleted` = '0' GROUP BY `original_id` HAVING COUNT(`itic`.`tickets_id`) != 1 - UNION - SELECT DISTINCT NULL AS `id`, CONCAT('t_',`tic`.`id`) AS `display_id`, diff --git a/install/update_2.5_2.6.php b/install/update_2.5_2.6.php index 2cee84dbf..0ce0bc29f 100644 --- a/install/update_2.5_2.6.php +++ b/install/update_2.5_2.6.php @@ -63,29 +63,27 @@ function plugin_formcreator_update_2_6(Migration $migration) { $table = 'glpi_plugin_formcreator_forms_answers'; $migration->displayMessage("Upgrade $table"); - if ($DB->fieldExists($table, 'validator_id', false)) { - $migration->addField($table, 'users_id_validator', 'integer', ['after' => 'requester_id']); - $migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']); - $migration->addKey($table, 'users_id_validator'); - $migration->addKey($table, 'groups_id_validator'); - $migration->migrationOneTable($table); - - $formTable = 'glpi_plugin_formcreator_forms'; - $query = "UPDATE `$table` - INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `users_id_validator` = 'validator_id' - WHERE `$formTable`.`validation_required` = '1'"; - $DB->query($query) or plugin_formcreator_upgrade_error($migration); - $query = "UPDATE `$table` - INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) - SET `groups_id_validator` = 'validator_id' - WHERE `$formTable`.`validation_required` = '2'"; - $DB->query($query) or plugin_formcreator_upgrade_error($migration); + $migration->addField($table, 'users_id_validator', 'integer', ['after' => 'requester_id']); + $migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']); + $migration->addKey($table, 'users_id_validator'); + $migration->addKey($table, 'groups_id_validator'); + $migration->migrationOneTable($table); + + $formTable = 'glpi_plugin_formcreator_forms'; + $query = "UPDATE `$table` + INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) + SET `users_id_validator` = 'validator_id' + WHERE `$formTable`.`validation_required` = '1'"; + $DB->query($query) or plugin_formcreator_upgrade_error($migration); + $query = "UPDATE `$table` + INNER JOIN `$formTable` ON (`$table`.`plugin_formcreator_forms_id` = `$formTable`.`id`) + SET `groups_id_validator` = 'validator_id' + WHERE `$formTable`.`validation_required` = '2'"; + $DB->query($query) or plugin_formcreator_upgrade_error($migration); + + $migration->dropKey($table, 'validator_id'); + $migration->dropField($table, 'validator_id'); - $migration->dropKey($table, 'validator_id'); - $migration->dropField($table, 'validator_id'); - } - // add location rule $enum_location_rule = "'".implode("', '", array_keys(PluginFormcreatorTargetTicket::getEnumLocationRule()))."'"; if (!$DB->fieldExists('glpi_plugin_formcreator_targettickets', 'location_rule', false)) {