Skip to content

Commit

Permalink
fix(install): fix possible schema errors coming from version older th…
Browse files Browse the repository at this point in the history
…an 2.5.0
  • Loading branch information
btry committed Jul 18, 2022
1 parent 98e292f commit c9338cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 21 additions & 1 deletion install/upgrade_to_2.13.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function fixTables(): void {
// with unsigned integer, with assumption that the admin aloready migrated IDs
// and FK to unsigned with the GLPI Core CLI command

$unsignedIntType = "INT " . DBConnection::getDefaultPrimaryKeySignOption() . " NOT NULL DEFAULT 0";
$unsignedIntType = "INT UNSIGNED NOT NULL DEFAULT '0'";

$table = 'glpi_plugin_formcreator_answers';
$this->migration->changeField($table, 'plugin_formcreator_formanswers_id', 'plugin_formcreator_formanswers_id', $unsignedIntType);
Expand All @@ -98,9 +98,15 @@ public function fixTables(): void {
);
$this->migration->changeField($table, 'users_id_validator', 'users_id_validator', $unsignedIntType);
$this->migration->changeField($table, 'groups_id_validator', 'groups_id_validator', $unsignedIntType);
$this->migration->changeField($table, 'name', 'name', 'string', ['value' => '']);
$this->migration->migrationOneTable($table);

$table = 'glpi_plugin_formcreator_questions';
$DB->update(
$table,
['name' => ''],
['name' => null]
);
$this->migration->changeField($table, 'name', 'name', 'string', ['value' => '']);
$this->migration->changeField($table, 'description', 'description', 'mediumtext');
// Assume the content of the 2 following columns is out of date
Expand All @@ -109,7 +115,19 @@ public function fixTables(): void {
$this->migration->dropField($table, 'range_max');
$this->migration->migrationOneTable($table);

$table = 'glpi_plugin_formcreator_issues';
$this->migration->addField($table, 'users_id_validator', 'integer', ['after' => 'requester_id']);
$this->migration->addField($table, 'groups_id_validator', 'integer', ['after' => 'users_id_validator']);
$this->migration->addKey($table, 'users_id_validator', 'users_id_validator');
$this->migration->addKey($table, 'groups_id_validator', 'groups_id_validator');
$this->migration->changeField($table, 'itemtype', 'itemtype', 'string', ['value' => '']);

$table = 'glpi_plugin_formcreator_sections';
$DB->update(
$table,
['name' => ''],
['name' => null]
);
$this->migration->changeField($table, 'name', 'name', 'string', ['value' => '']);
$this->migration->migrationOneTable($table);

Expand Down Expand Up @@ -333,6 +351,7 @@ protected function migrateFkToUnsignedInt() {
],
'glpi_plugin_formcreator_issues' => [
'users_id_recipient',
'plugin_formcreator_categories_id',
],
'glpi_plugin_formcreator_questions' => [
'plugin_formcreator_sections_id',
Expand Down Expand Up @@ -437,6 +456,7 @@ public function fixissues() {
$table = 'glpi_plugin_formcreator_issues';

$this->migration->changeField($table, 'name', 'name', 'string', ['after' => 'id', 'nodefault' => true]);
$this->migration->changeField($table, 'status', 'status', 'string', ['value' => '']);
}

public function isResyncIssuesRequiresd() {
Expand Down
3 changes: 3 additions & 0 deletions install/upgrade_to_2.8.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class PluginFormcreatorUpgradeTo2_8_1 {
* @param Migration $migration
*/
public function upgrade(Migration $migration) {
global $DB;

$table = 'glpi_plugin_formcreator_issues';
$DB->query("UPDATE `$table` SET `name`='' WHERE `name` IS NULL");
$migration->changeField($table, 'name', 'name', 'string', ['after' => 'id', 'value' => '']);
}

Expand Down

0 comments on commit c9338cd

Please sign in to comment.