From 7ffb9a86a56af684d0fef24b4dd94e5d92137454 Mon Sep 17 00:00:00 2001 From: OpenXE <> Date: Thu, 7 Dec 2023 13:38:59 +0100 Subject: [PATCH] upgrade added strict DB mode --- upgrade/data/upgrade.php | 23 +++++++-- vendor/mustal/mustal_mysql_upgrade_tool.php | 10 ++-- www/pages/upgrade.php | 54 ++++++++++++++++++--- 3 files changed, 74 insertions(+), 13 deletions(-) diff --git a/upgrade/data/upgrade.php b/upgrade/data/upgrade.php index 25bcbb0a..a7332c78 100644 --- a/upgrade/data/upgrade.php +++ b/upgrade/data/upgrade.php @@ -112,6 +112,12 @@ if (php_sapi_name() == "cli") { $check_db = true; } else { } + + if (in_array('-strict', $argv)) { + $strict_db = true; + } else { + $strict_db = false; + } if (in_array('-do', $argv)) { if (!$check_git && !$check_db) { @@ -127,7 +133,17 @@ if (php_sapi_name() == "cli") { } if ($check_git || $check_db || $do_git || $do_db) { - upgrade_main($directory,$verbose,$check_git,$do_git,$export_db,$check_db,$do_db,$force,$connection,$origin); + upgrade_main( directory: $directory, + verbose: $verbose, + check_git: $check_git, + do_git: $do_git, + export_db: $export_db, + check_db: $check_db, + strict_db: $strict_db, + do_db: $do_db, + force: $force, + connection: $connection, + origin: $origin); } else { info(); } @@ -139,7 +155,7 @@ if (php_sapi_name() == "cli") { } // -------------------------------- END -function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do_git, bool $export_db, bool $check_db, bool $do_db, bool $force, bool $connection, bool $origin) { +function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do_git, bool $export_db, bool $check_db, bool $strict_db, bool $do_db, bool $force, bool $connection, bool $origin) { $mainfolder = dirname($directory); $datafolder = $directory."/data"; @@ -379,7 +395,7 @@ function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do echo_out("--------------- Calculating database upgrade for '$schema@$host'... ---------------\n"); $upgrade_sql = array(); - $result = mustal_calculate_db_upgrade($compare_def, $db_def, $upgrade_sql, $mustal_replacers); + $result = mustal_calculate_db_upgrade($compare_def, $db_def, $upgrade_sql, $mustal_replacers, $strict_db); if (!empty($result)) { abort(count($result)." errors.\n"); @@ -482,6 +498,7 @@ function info() { echo_out("\t-f: force override of existing files\n"); echo_out("\t-o: update from origin instead of remote.json\n"); echo_out("\t-connection use connection.json in data folder instead of user.inc.php\n"); + echo_out("\t-strict: innodb_strict_mode=ON\n"); echo_out("\t-clean: (not yet implemented) create the needed SQL to remove items from the database not in the JSON\n"); echo_out("\n"); } diff --git a/vendor/mustal/mustal_mysql_upgrade_tool.php b/vendor/mustal/mustal_mysql_upgrade_tool.php index fd97bb5d..d231443a 100644 --- a/vendor/mustal/mustal_mysql_upgrade_tool.php +++ b/vendor/mustal/mustal_mysql_upgrade_tool.php @@ -21,7 +21,7 @@ function mustal_compare_table_array(array $nominal, string $nominal_name, array Compare two database structures Returns a structured array containing information on all the differences. -function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql) : int +function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql, bool $strict) : int Generate the SQL needed to upgrade the database to match the definition, based on a comparison. Data structure in Array and JSON @@ -542,7 +542,7 @@ function mustal_implode_with_quote(string $quote, string $delimiter, array $arra // 11 Table type upgrade not supported // 12 Upgrade type not supported -function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql, array $replacers) : array { +function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql, array $replacers, bool $strict) : array { $result = array(); $upgrade_sql = array(); @@ -752,8 +752,10 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$ $upgrade_sql = array_unique($upgrade_sql); if (count($upgrade_sql) > 0) { - - array_unshift($upgrade_sql,"SET SQL_MODE='ALLOW_INVALID_DATES';","SET SESSION innodb_strict_mode=OFF;"); + array_unshift($upgrade_sql,"SET SQL_MODE='ALLOW_INVALID_DATES';"); + if (!$strict) { + array_unshift($upgrade_sql,"SET SESSION innodb_strict_mode=OFF;"); + } } return($result); diff --git a/www/pages/upgrade.php b/www/pages/upgrade.php index 400d22fd..2c76754f 100644 --- a/www/pages/upgrade.php +++ b/www/pages/upgrade.php @@ -41,29 +41,71 @@ class upgrade { $this->app->Tpl->Set('UPGRADE_VISIBLE', "hidden"); $this->app->Tpl->Set('UPGRADE_DB_VISIBLE', "hidden"); - //function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do_git, bool $export_db, bool $check_db, bool $do_db, bool $force, bool $connection, bool $origin) { - $directory = dirname(getcwd())."/upgrade"; switch ($submit) { case 'check_upgrade': $this->app->Tpl->Set('UPGRADE_VISIBLE', ""); unlink($logfile); - upgrade_main($directory,$verbose,true,false,false,true,false,$force,false,false); + upgrade_main( directory: $directory, + verbose: $verbose, + check_git: true, + do_git: false, + export_db: false, + check_db: true, + strict_db: false, + do_db: false, + force: $force, + connection: false, + origin: false + ); break; case 'do_upgrade': unlink($logfile); - upgrade_main($directory,$verbose,true,true,false,true,true,$force,false,false); + upgrade_main( directory: $directory, + verbose: $verbose, + check_git: true, + do_git: true, + export_db: false, + check_db: true, + strict_db: false, + do_db: true, + force: $force, + connection: false, + origin: false + ); break; case 'check_db': $this->app->Tpl->Set('UPGRADE_DB_VISIBLE', ""); unlink($logfile); - upgrade_main($directory,$db_verbose,false,false,false,true,false,$force,false,false); + upgrade_main( directory: $directory, + verbose: $db_verbose, + check_git: false, + do_git: false, + export_db: false, + check_db: true, + strict_db: false, + do_db: false, + force: $force, + connection: false, + origin: false + ); break; case 'do_db_upgrade': $this->app->Tpl->Set('UPGRADE_DB_VISIBLE', ""); unlink($logfile); - upgrade_main($directory,$db_verbose,false,false,false,true,true,$force,false,false); + upgrade_main( directory: $directory, + verbose: $db_verbose, + check_git: false, + do_git: false, + export_db: false, + check_db: true, + strict_db: false, + do_db: true, + force: $force, + connection: false, + origin: false + ); break; case 'refresh': break;