Skip to content

Commit

Permalink
fix(install): handle invalid values before changing columns, add poss…
Browse files Browse the repository at this point in the history
…ibly missing index
  • Loading branch information
btry committed Jul 18, 2022
1 parent 54b2467 commit f5369f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions install/upgrade_to_2.13.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public function fixTables(): void {
$table = 'glpi_plugin_formcreator_answers';
$this->migration->changeField($table, 'plugin_formcreator_formanswers_id', 'plugin_formcreator_formanswers_id', $unsignedIntType);
$this->migration->changeField($table, 'plugin_formcreator_questions_id', 'plugin_formcreator_questions_id', $unsignedIntType);
$this->migration->dropKey($table, 'plugin_formcreator_question_id');
$this->migration->addKey($table, 'plugin_formcreator_questions_id', 'plugin_formcreator_questions_id');
$this->migration->migrationOneTable($table);

$table = 'glpi_plugin_formcreator_forms';
Expand Down
1 change: 1 addition & 0 deletions install/upgrade_to_2.7.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ public function upgrade(Migration $migration) {
'glpi_plugin_formcreator_issues',
];
foreach ($tables as $table) {
$DB->query("UPDATE `$table` SET `name`='' WHERE `name` IS NULL");
$migration->changeField($table, 'name', 'name', 'VARCHAR(255) NOT NULL DEFAULT \'\' AFTER `id`');
}

Expand Down
4 changes: 4 additions & 0 deletions install/upgrade_to_2.9.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ public function upgrade(Migration $migration) {
$migration->changeField($table, 'plugin_formcreator_questions_id', 'items_id', 'integer', ['comment' => 'item ID of the item affected by the condition']);
}
$migration->migrationOneTable($table);

// Fix possible nulls (despite those lines are definetely broken not usable; maybe a form does not behaves properly showing / hiding a question)
$DB->query("UPDATE `$table` SET `show_field` = 0 WHERE `show_field` IS NULL");

$migration->changeField($table, 'show_field', 'plugin_formcreator_questions_id', 'integer', ['value' => '0', 'comment' => 'question to test for the condition']);
$migration->dropKey($table, 'plugin_formcreator_questions_id');
$migration->migrationOneTable($table);
Expand Down

0 comments on commit f5369f6

Please sign in to comment.