From 9bf7c6b6404a05dc0db1cb84cb9c83bcd679586f Mon Sep 17 00:00:00 2001 From: btry Date: Fri, 7 Dec 2018 14:42:55 +0100 Subject: [PATCH] fix(install): create tables before filling them Signed-off-by: Thierry Bugier --- install/install.php | 6 ++++-- install/upgrade_to_2.7.php | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/install/install.php b/install/install.php index 30dba88def..d0a6907374 100644 --- a/install/install.php +++ b/install/install.php @@ -92,6 +92,10 @@ public function install(Migration $migration) { */ public function upgrade(Migration $migration) { $this->migration = $migration; + + // if the schema contains new tables + $this->installSchema(); + if (isset($_SESSION['plugin_formcreator']['cli']) && $_SESSION['plugin_formcreator']['cli'] == 'force-upgrade') { // Might return false $fromSchemaVersion = array_search(PLUGIN_FORMCREATOR_SCHEMA_VERSION, $this->upgradeSteps); @@ -105,8 +109,6 @@ public function upgrade(Migration $migration) { } $this->migration->executeMigration(); - // if the schema contains new tables - $this->installSchema(); $this->configureExistingEntities(); $this->createRequestType(); $this->createDefaultDisplayPreferences(); diff --git a/install/upgrade_to_2.7.php b/install/upgrade_to_2.7.php index 15d05eb0e3..e58e11ac37 100644 --- a/install/upgrade_to_2.7.php +++ b/install/upgrade_to_2.7.php @@ -116,6 +116,17 @@ public function upgrade(Migration $migration) { // Migrate regex question parameters $table = 'glpi_plugin_formcreator_questions'; if ($DB->fieldExists($table, 'regex')) { + $DB->query( + "CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questionregexes` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_questions_id` int(11) NOT NULL, + `regex` text DEFAULT NULL, + `fieldname` varchar(255) DEFAULT NULL, + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" + ); $request = [ 'FROM' => $table, 'WHERE' => ['fieldtype' => ['float', 'integer', 'text', 'textarea']] @@ -134,6 +145,18 @@ public function upgrade(Migration $migration) { // Migrate range question parameters $table = 'glpi_plugin_formcreator_questions'; if ($DB->fieldExists($table, 'range_min')) { + $DB->query( + "CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questionranges` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `plugin_formcreator_questions_id` int(11) NOT NULL, + `range_min` varchar(255) DEFAULT NULL, + `range_max` varchar(255) DEFAULT NULL, + `fieldname` varchar(255) DEFAULT NULL, + `uuid` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `plugin_formcreator_questions_id` (`plugin_formcreator_questions_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" + ); $request = [ 'FROM' => $table, 'WHERE' => ['fieldtype' => ['float', 'integer', 'checkboxes', 'multiselect', 'text']]