diff --git a/install/install.php b/install/install.php index 96ffc5a31..b7e47bcac 100644 --- a/install/install.php +++ b/install/install.php @@ -142,7 +142,6 @@ public function upgrade(Migration $migration, $args = []): bool { // Check schema of tables before upgrading if (!isset($args['skip-db-check'])) { $oldVersion = Config::getConfigurationValue('formcreator', 'previous_version'); - $log = ''; if ($oldVersion !== null) { $checkResult = true; if (version_compare($oldVersion, '2.13.0') >= 0) { @@ -154,43 +153,29 @@ public function upgrade(Migration $migration, $args = []): bool { false, false, false, - false, - $log + false ); - } else { - // Upgrading from GLPI 9.5 to GLPI 10 - // check only columns format - // $checkResult = $this->checkSchema( - // $oldVersion, - // true, - // false, - // false, - // true, - // true, - // true, - // $log - // ); } if (!$checkResult) { + $message = sprintf( + __('The database schema is not consistent with the installed Formcreator %s. To see the logs run the command %s', 'formcreator'), + $oldVersion, + 'bin/console glpi:plugin:install formcreator -f' + ); if (!isCommandLine()) { - Session::addMessageAfterRedirect(sprintf( - __('The database schema is not consistent with the installed Formcreator %s. To see the logs run the command %s', 'formcreator'), - $oldVersion, - 'bin/console glpi:plugin:install formcreator' - ), false, ERROR); + Session::addMessageAfterRedirect($message, false, ERROR); } else { + echo $message . PHP_EOL; + // echo 'Some tables have an incorrect schema. Please review them in the above log.' . PHP_EOL; + // echo 'Some of those errors are handled in the upgrade step from 2.12.5 to 2.13.0. ' . PHP_EOL; + // echo 'Please _take a snapshot of your complete database_, then try to run the upgrade with the following command: ' . PHP_EOL; + // echo 'bin/console glpi:plugin:install formcreator -f -p skip-db-check' . PHP_EOL; + // echo 'The upgrade procedure will try to solve known errors before upgrading the tables to 2.13.0 version.' . PHP_EOL; + // echo 'Finally a check of the tables will be executed to report unhandled inconsistencies.' . PHP_EOL; echo sprintf( - __('The database schema is not consistent with the installed Formcreator %s. To see the logs run the command %s', 'formcreator'), - $oldVersion, - 'bin/console glpi:plugin:install formcreator' + __('To ignore the inconsistencies and upgrade anyway run %s', 'formcreator'), + 'bin/console glpi:plugin:install formcreator -f -p skip-db-check' ) . PHP_EOL; - echo $log . PHP_EOL; - echo 'Some tables have an incorrect schema. Please review them in the above log.' . PHP_EOL; - echo 'Some of those errors are handled in the upgrade step from 2.12.5 to 2.13.0. ' . PHP_EOL; - echo 'Please _take a snapshot of your complete database_, then try to run the upgrade with the following command: ' . PHP_EOL; - echo 'bin/console glpi:plugin:install formcreator -f -p skip-db-check' . PHP_EOL; - echo 'The upgrade procedure will try to solve known errors before upgrading the tables to 2.13.0 version.' . PHP_EOL; - echo 'Finally a check of the tables will be executed to report unhandled inconsistencies.' . PHP_EOL; } return false; } @@ -241,31 +226,25 @@ public function upgrade(Migration $migration, $args = []): bool { } // Check schema of tables after upgrade - $log = ''; $checkResult = $this->checkSchema( PLUGIN_FORMCREATOR_VERSION, - true, false, false, false, false, false, - $log + false ); if (!$checkResult) { + $message = sprintf( + __('The database schema is not consistent with the installed Formcreator %s. To see the logs enable the plugin and run the command %s', 'formcreator'), + PLUGIN_FORMCREATOR_VERSION, + 'bin/console glpi:database:check_schema_integrity -p formcreator' + ); if (!isCommandLine()) { - Session::addMessageAfterRedirect(sprintf( - __('The database schema is not consistent with the installed Formcreator %s. To see the logs enable the plugin and run the command %s', 'formcreator'), - PLUGIN_FORMCREATOR_VERSION, - 'bin/console glpi:database:check_schema_integrity -p formcreator' - ), false, ERROR); + Session::addMessageAfterRedirect($message, false, ERROR); } else { - echo sprintf( - __('The database schema is not consistent with the installed Formcreator %s. To see the logs run the command %s', 'formcreator'), - PLUGIN_FORMCREATOR_VERSION, - 'bin/console glpi:database:check_schema_integrity -p formcreator' - ) . PHP_EOL; - echo $log . PHP_EOL; + echo $message . PHP_EOL; } } @@ -836,8 +815,8 @@ public function checkSchema( bool $ignore_timestamps_migration = false, bool $ignore_utf8mb4_migration = false, bool $ignore_dynamic_row_format_migration = false, - bool $ignore_unsigned_keys_migration = false, - string &$log = ''): bool { + bool $ignore_unsigned_keys_migration = false + ): bool { global $DB; $schemaFile = plugin_formcreator_getSchemaPath($version); @@ -865,25 +844,6 @@ public function checkSchema( } if (count($differences) > 0) { - if (isCommandLine()) { - foreach ($differences as $table_name => $difference) { - $message = null; - switch ($difference['type']) { - case DatabaseSchemaIntegrityChecker::RESULT_TYPE_ALTERED_TABLE: - $message = sprintf(__('Table schema differs for table "%s".'), $table_name); - break; - case DatabaseSchemaIntegrityChecker::RESULT_TYPE_MISSING_TABLE: - $message = sprintf(__('Table "%s" is missing.'), $table_name); - break; - case DatabaseSchemaIntegrityChecker::RESULT_TYPE_UNKNOWN_TABLE: - $message = sprintf(__('Unknown table "%s" has been found in database.'), $table_name); - break; - } - $log .= $message . PHP_EOL; - $log .= $difference['diff'] . PHP_EOL; - } - } - return false; } diff --git a/install/upgrade_to_2.13.php b/install/upgrade_to_2.13.php index c5e1227b0..b529d6e8c 100644 --- a/install/upgrade_to_2.13.php +++ b/install/upgrade_to_2.13.php @@ -57,6 +57,7 @@ public function upgrade(Migration $migration) { /** * Fix possible inconsistencies accumulated over years from 2.5.0 to 2.12.5 * At the end of this method the schema shall match the version 2.12.5 + * except for the type of IDs and FK which are immediateli migrated to unsigned int * Modifications are immediately applied to tables as the state of the schema is the expected * basis for changes required to migrate to 2.13.0 * @@ -64,7 +65,11 @@ public function upgrade(Migration $migration) { */ public function fixTables(): void { global $DB; + // Based on schema from version 2.12.5, try to fix some harlmess inconsistencies + // To avoid annoying warnings, and contrary to the original 2.12.5 schema, the foreign keys are updated + // 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";