Skip to content

Commit

Permalink
fix(install): use modern settings for tables
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jul 27, 2022
1 parent 001d12f commit f04e418
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 6 additions & 2 deletions install/upgrade_to_2.6.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ public function upgrade(Migration $migration) {
$migration->dropKey($table, 'plugin_formcreator_question_id');
$migration->addKey($table, 'plugin_formcreator_questions_id', 'plugin_formcreator_questions_id');

$defaultCharset = DBConnection::getDefaultCharset();
$defaultCollation = DBConnection::getDefaultCollation();
$defaultKeySign = DBConnection::getDefaultPrimaryKeySignOption();

$table = 'glpi_plugin_formcreator_items_targettickets';
if (!$DB->tableExists($table)) {
$query = "CREATE TABLE `$table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id` int(11) $defaultKeySign NOT NULL AUTO_INCREMENT,
`plugin_formcreator_targettickets_id` int(11) NOT NULL DEFAULT '0',
`link` int(11) NOT NULL DEFAULT '0',
`itemtype` varchar(255) NOT NULL DEFAULT '',
Expand All @@ -130,7 +134,7 @@ public function upgrade(Migration $migration) {
PRIMARY KEY (`id`),
INDEX `plugin_formcreator_targettickets_id` (`plugin_formcreator_targettickets_id`),
INDEX `item` (`itemtype`,`items_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
) ENGINE=InnoDB DEFAULT CHARSET=$defaultCharset COLLATE=$defaultCollation ROW_FORMAT=DYNAMIC;";
$DB->query($query) or plugin_formcreator_upgrade_error($migration);
}

Expand Down
11 changes: 7 additions & 4 deletions install/upgrade_to_2.7.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,21 @@ public function upgrade(Migration $migration) {
$migration->dropField($table, 'changetemplates_id');

// Migrate regex question parameters
$defaultCharset = DBConnection::getDefaultCharset();
$defaultCollation = DBConnection::getDefaultCollation();
$defaultKeySign = DBConnection::getDefaultPrimaryKeySignOption();
$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,
`id` int(11) $defaultKeySign 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;"
) ENGINE=InnoDB DEFAULT CHARSET=$defaultCharset COLLATE=$defaultCollation ROW_FORMAT=DYNAMIC;"
);
$request = [
'FROM' => $table,
Expand All @@ -156,15 +159,15 @@ public function upgrade(Migration $migration) {
if ($DB->fieldExists($table, 'range_min')) {
$DB->query(
"CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questionranges` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id` int(11) $defaultKeySign 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;"
) ENGINE=InnoDB DEFAULT CHARSET=$defaultCharset COLLATE=$defaultCollation ROW_FORMAT=DYNAMIC;"
);
$request = [
'FROM' => $table,
Expand Down
2 changes: 1 addition & 1 deletion tests/script-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ plugin_test_upgrade() {
php ../../bin/console glpi:migration:myisam_to_innodb --no-interaction --config-dir=../../$TEST_GLPI_CONFIG_DIR
php ../../bin/console glpi:plugin:install formcreator --username=glpi --config-dir=../../$TEST_GLPI_CONFIG_DIR
# Upgrading from < 2.6 will create a MyISAM table, then re-run innoDB migration
php ../../bin/console glpi:migration:myisam_to_innodb --no-interaction --config-dir=../../$TEST_GLPI_CONFIG_DIR
# php ../../bin/console glpi:migration:myisam_to_innodb --no-interaction --config-dir=../../$TEST_GLPI_CONFIG_DIR
php ../../bin/console glpi:migration:unsigned_keys --no-interaction --config-dir=../../$TEST_GLPI_CONFIG_DIR
php ../../bin/console glpi:migration:utf8mb4 --no-interaction --config-dir=../../$TEST_GLPI_CONFIG_DIR
}
Expand Down

0 comments on commit f04e418

Please sign in to comment.