Skip to content

Commit 504727b

Browse files
committed
fix(install): disable db check prior upgrade
only when upgrading from a version < 2.13.0
1 parent 7420cdc commit 504727b

File tree

2 files changed

+31
-66
lines changed

2 files changed

+31
-66
lines changed

install/install.php

Lines changed: 26 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public function upgrade(Migration $migration, $args = []): bool {
142142
// Check schema of tables before upgrading
143143
if (!isset($args['skip-db-check'])) {
144144
$oldVersion = Config::getConfigurationValue('formcreator', 'previous_version');
145-
$log = '';
146145
if ($oldVersion !== null) {
147146
$checkResult = true;
148147
if (version_compare($oldVersion, '2.13.0') >= 0) {
@@ -154,43 +153,29 @@ public function upgrade(Migration $migration, $args = []): bool {
154153
false,
155154
false,
156155
false,
157-
false,
158-
$log
156+
false
159157
);
160-
} else {
161-
// Upgrading from GLPI 9.5 to GLPI 10
162-
// check only columns format
163-
// $checkResult = $this->checkSchema(
164-
// $oldVersion,
165-
// true,
166-
// false,
167-
// false,
168-
// true,
169-
// true,
170-
// true,
171-
// $log
172-
// );
173158
}
174159
if (!$checkResult) {
160+
$message = sprintf(
161+
__('The database schema is not consistent with the installed Formcreator %s. To see the logs run the command %s', 'formcreator'),
162+
$oldVersion,
163+
'bin/console glpi:plugin:install formcreator -f'
164+
);
175165
if (!isCommandLine()) {
176-
Session::addMessageAfterRedirect(sprintf(
177-
__('The database schema is not consistent with the installed Formcreator %s. To see the logs run the command %s', 'formcreator'),
178-
$oldVersion,
179-
'bin/console glpi:plugin:install formcreator'
180-
), false, ERROR);
166+
Session::addMessageAfterRedirect($message, false, ERROR);
181167
} else {
168+
echo $message . PHP_EOL;
169+
// echo 'Some tables have an incorrect schema. Please review them in the above log.' . PHP_EOL;
170+
// echo 'Some of those errors are handled in the upgrade step from 2.12.5 to 2.13.0. ' . PHP_EOL;
171+
// echo 'Please _take a snapshot of your complete database_, then try to run the upgrade with the following command: ' . PHP_EOL;
172+
// echo 'bin/console glpi:plugin:install formcreator -f -p skip-db-check' . PHP_EOL;
173+
// echo 'The upgrade procedure will try to solve known errors before upgrading the tables to 2.13.0 version.' . PHP_EOL;
174+
// echo 'Finally a check of the tables will be executed to report unhandled inconsistencies.' . PHP_EOL;
182175
echo sprintf(
183-
__('The database schema is not consistent with the installed Formcreator %s. To see the logs run the command %s', 'formcreator'),
184-
$oldVersion,
185-
'bin/console glpi:plugin:install formcreator'
176+
__('To ignore the inconsistencies and upgrade anyway run %s', 'formcreator'),
177+
'bin/console glpi:plugin:install formcreator -f -p skip-db-check'
186178
) . PHP_EOL;
187-
echo $log . PHP_EOL;
188-
echo 'Some tables have an incorrect schema. Please review them in the above log.' . PHP_EOL;
189-
echo 'Some of those errors are handled in the upgrade step from 2.12.5 to 2.13.0. ' . PHP_EOL;
190-
echo 'Please _take a snapshot of your complete database_, then try to run the upgrade with the following command: ' . PHP_EOL;
191-
echo 'bin/console glpi:plugin:install formcreator -f -p skip-db-check' . PHP_EOL;
192-
echo 'The upgrade procedure will try to solve known errors before upgrading the tables to 2.13.0 version.' . PHP_EOL;
193-
echo 'Finally a check of the tables will be executed to report unhandled inconsistencies.' . PHP_EOL;
194179
}
195180
return false;
196181
}
@@ -241,31 +226,25 @@ public function upgrade(Migration $migration, $args = []): bool {
241226
}
242227

243228
// Check schema of tables after upgrade
244-
$log = '';
245229
$checkResult = $this->checkSchema(
246230
PLUGIN_FORMCREATOR_VERSION,
247-
true,
248231
false,
249232
false,
250233
false,
251234
false,
252235
false,
253-
$log
236+
false
254237
);
255238
if (!$checkResult) {
239+
$message = sprintf(
240+
__('The database schema is not consistent with the installed Formcreator %s. To see the logs enable the plugin and run the command %s', 'formcreator'),
241+
PLUGIN_FORMCREATOR_VERSION,
242+
'bin/console glpi:database:check_schema_integrity -p formcreator'
243+
);
256244
if (!isCommandLine()) {
257-
Session::addMessageAfterRedirect(sprintf(
258-
__('The database schema is not consistent with the installed Formcreator %s. To see the logs enable the plugin and run the command %s', 'formcreator'),
259-
PLUGIN_FORMCREATOR_VERSION,
260-
'bin/console glpi:database:check_schema_integrity -p formcreator'
261-
), false, ERROR);
245+
Session::addMessageAfterRedirect($message, false, ERROR);
262246
} else {
263-
echo sprintf(
264-
__('The database schema is not consistent with the installed Formcreator %s. To see the logs run the command %s', 'formcreator'),
265-
PLUGIN_FORMCREATOR_VERSION,
266-
'bin/console glpi:database:check_schema_integrity -p formcreator'
267-
) . PHP_EOL;
268-
echo $log . PHP_EOL;
247+
echo $message . PHP_EOL;
269248
}
270249
}
271250

@@ -836,8 +815,8 @@ public function checkSchema(
836815
bool $ignore_timestamps_migration = false,
837816
bool $ignore_utf8mb4_migration = false,
838817
bool $ignore_dynamic_row_format_migration = false,
839-
bool $ignore_unsigned_keys_migration = false,
840-
string &$log = ''): bool {
818+
bool $ignore_unsigned_keys_migration = false
819+
): bool {
841820
global $DB;
842821

843822
$schemaFile = plugin_formcreator_getSchemaPath($version);
@@ -865,25 +844,6 @@ public function checkSchema(
865844
}
866845

867846
if (count($differences) > 0) {
868-
if (isCommandLine()) {
869-
foreach ($differences as $table_name => $difference) {
870-
$message = null;
871-
switch ($difference['type']) {
872-
case DatabaseSchemaIntegrityChecker::RESULT_TYPE_ALTERED_TABLE:
873-
$message = sprintf(__('Table schema differs for table "%s".'), $table_name);
874-
break;
875-
case DatabaseSchemaIntegrityChecker::RESULT_TYPE_MISSING_TABLE:
876-
$message = sprintf(__('Table "%s" is missing.'), $table_name);
877-
break;
878-
case DatabaseSchemaIntegrityChecker::RESULT_TYPE_UNKNOWN_TABLE:
879-
$message = sprintf(__('Unknown table "%s" has been found in database.'), $table_name);
880-
break;
881-
}
882-
$log .= $message . PHP_EOL;
883-
$log .= $difference['diff'] . PHP_EOL;
884-
}
885-
}
886-
887847
return false;
888848
}
889849

install/upgrade_to_2.13.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ public function upgrade(Migration $migration) {
5757
/**
5858
* Fix possible inconsistencies accumulated over years from 2.5.0 to 2.12.5
5959
* At the end of this method the schema shall match the version 2.12.5
60+
* except for the type of IDs and FK which are immediateli migrated to unsigned int
6061
* Modifications are immediately applied to tables as the state of the schema is the expected
6162
* basis for changes required to migrate to 2.13.0
6263
*
6364
* @return void
6465
*/
6566
public function fixTables(): void {
6667
global $DB;
68+
6769
// Based on schema from version 2.12.5, try to fix some harlmess inconsistencies
70+
// To avoid annoying warnings, and contrary to the original 2.12.5 schema, the foreign keys are updated
71+
// with unsigned integer, with assumption that the admin aloready migrated IDs
72+
// and FK to unsigned with the GLPI Core CLI command
6873

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

0 commit comments

Comments
 (0)