Skip to content

Commit 001d12f

Browse files
committed
fix(install): prevent useless warnings
1 parent 66571b8 commit 001d12f

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

install/install.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public function upgrade(Migration $migration, $args = []): bool {
139139
}
140140

141141
// Check schema of tables before upgrading
142+
$oldVersion = Config::getConfigurationValue('formcreator', 'previous_version');
142143
if (!isset($args['skip-db-check'])) {
143-
$oldVersion = Config::getConfigurationValue('formcreator', 'previous_version');
144144
if ($oldVersion !== null) {
145145
$checkResult = true;
146146
if (version_compare($oldVersion, '2.13.0') >= 0) {
@@ -219,15 +219,17 @@ public function upgrade(Migration $migration, $args = []): bool {
219219
PluginFormcreatorIssue::cronSyncIssues($task);
220220
}
221221

222+
$lazyCheck = false;
223+
// $lazyCheck = (version_compare($oldVersion, '2.13.0') < 0);
222224
// Check schema of tables after upgrade
223225
$checkResult = $this->checkSchema(
224226
PLUGIN_FORMCREATOR_VERSION,
225227
false,
226-
false,
227-
false,
228-
false,
229-
false,
230-
false
228+
$lazyCheck,
229+
$lazyCheck,
230+
$lazyCheck,
231+
$lazyCheck,
232+
$lazyCheck
231233
);
232234
if (!$checkResult) {
233235
$message = sprintf(

install/mysql/plugin_formcreator_2.13.0_empty.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_answers` (
1313
CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_categories` (
1414
`id` int unsigned NOT NULL AUTO_INCREMENT,
1515
`name` varchar(255) NOT NULL DEFAULT '',
16-
`comment` text,
16+
`comment` mediumtext,
1717
`completename` varchar(255) DEFAULT NULL,
1818
`plugin_formcreator_categories_id` int unsigned NOT NULL DEFAULT '0',
1919
`level` int(11) NOT NULL DEFAULT '1',
@@ -81,7 +81,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_formanswers` (
8181
`groups_id_validator` int unsigned NOT NULL DEFAULT '0' COMMENT 'Group in charge of validation',
8282
`request_date` timestamp NULL,
8383
`status` int(11) NOT NULL DEFAULT '101',
84-
`comment` text,
84+
`comment` mediumtext,
8585
PRIMARY KEY (`id`),
8686
INDEX `plugin_formcreator_forms_id` (`plugin_formcreator_forms_id`),
8787
INDEX `entities_id_is_recursive` (`entities_id`, `is_recursive`),
@@ -329,7 +329,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questiondependencies` (
329329
CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questionregexes` (
330330
`id` int unsigned NOT NULL AUTO_INCREMENT,
331331
`plugin_formcreator_questions_id` int unsigned NOT NULL DEFAULT '0',
332-
`regex` text DEFAULT NULL,
332+
`regex` mediumtext DEFAULT NULL,
333333
`fieldname` varchar(255) DEFAULT NULL,
334334
`uuid` varchar(255) DEFAULT NULL,
335335
PRIMARY KEY (`id`),

install/upgrade_to_2.13.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class PluginFormcreatorUpgradeTo2_13 {
3838
public function upgrade(Migration $migration) {
3939
$this->migration = $migration;
4040
$this->fixTables();
41+
$this->updateShortText();
4142
$this->migrateEntityConfig();
4243
$this->addDefaultFormListMode();
4344
$this->addDashboardVisibility();
@@ -160,13 +161,30 @@ public function fixTables(): void {
160161
$this->migration->migrationOneTable($table);
161162

162163
$table = 'glpi_plugin_formcreator_questiondependencies';
163-
$this->migration->changeField($table, 'plugin_formcreator_questions_id', 'plugin_formcreator_questions_id', $unsignedIntType);
164-
$this->migration->changeField($table, 'plugin_formcreator_questions_id_2', 'plugin_formcreator_questions_id_2', $unsignedIntType);
165-
$this->migration->migrationOneTable($table);
164+
if ($DB->tableExists($table)) {
165+
// Table may be created at the very end when upgrading from < 2.12
166+
$this->migration->changeField($table, 'plugin_formcreator_questions_id', 'plugin_formcreator_questions_id', $unsignedIntType);
167+
$this->migration->changeField($table, 'plugin_formcreator_questions_id_2', 'plugin_formcreator_questions_id_2', $unsignedIntType);
168+
$this->migration->migrationOneTable($table);
169+
}
166170

167171
$table = 'glpi_plugin_formcreator_forms_languages';
168-
$this->migration->changeField($table, 'plugin_formcreator_forms_id', 'plugin_formcreator_forms_id', $unsignedIntType);
169-
$this->migration->migrationOneTable($table);
172+
if ($DB->tableExists($table)) {
173+
// Table may be created at the very end when upgrading from < 2.12
174+
$this->migration->changeField($table, 'plugin_formcreator_forms_id', 'plugin_formcreator_forms_id', $unsignedIntType);
175+
$this->migration->migrationOneTable($table);
176+
}
177+
}
178+
179+
public function updateShortText() {
180+
$table = 'glpi_plugin_formcreator_categories';
181+
$this->migration->changeField($table, 'comment', 'comment', 'mediumtext');
182+
183+
$table = 'glpi_plugin_formcreator_formanswers';
184+
$this->migration->changeField($table, 'comment', 'comment', 'mediumtext');
185+
186+
$table = 'glpi_plugin_formcreator_questionregexes';
187+
$this->migration->changeField($table, 'regex', 'regex', 'mediumtext');
170188
}
171189

172190
public function addEntityOption() {
@@ -399,6 +417,9 @@ protected function migrateFkToUnsignedInt() {
399417
];
400418

401419
foreach ($tables as $table => $fields) {
420+
if (!$DB->tableExists($table)) {
421+
continue;
422+
}
402423
foreach ($fields as $field) {
403424
if ($field == 'id') {
404425
$type = 'autoincrement';

tests/script-functions.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ plugin_test_upgrade() {
5959
mysql -h$DB_HOST -u$DB_USER -p$DB_PASSWD $OLD_DB_NAME < tests/plugin_formcreator_empty_2.5.0.sql
6060
php ../../bin/console glpi:migration:myisam_to_innodb --no-interaction --config-dir=../../$TEST_GLPI_CONFIG_DIR
6161
php ../../bin/console glpi:plugin:install formcreator --username=glpi --config-dir=../../$TEST_GLPI_CONFIG_DIR
62+
# Upgrading from < 2.6 will create a MyISAM table, then re-run innoDB migration
63+
php ../../bin/console glpi:migration:myisam_to_innodb --no-interaction --config-dir=../../$TEST_GLPI_CONFIG_DIR
6264
php ../../bin/console glpi:migration:unsigned_keys --no-interaction --config-dir=../../$TEST_GLPI_CONFIG_DIR
65+
php ../../bin/console glpi:migration:utf8mb4 --no-interaction --config-dir=../../$TEST_GLPI_CONFIG_DIR
6366
}
6467

6568
# Plugin test

0 commit comments

Comments
 (0)