mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2025-03-31 10:30:22 +02:00
upgrade improvements regarding error handling and display
This commit is contained in:
parent
e4773da6f0
commit
264bc56365
@ -210,7 +210,6 @@ if ($argc > 1) {
|
|||||||
echo("\n");
|
echo("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo("--------------- Comparison complete. ---------------\n");
|
echo("--------------- Comparison complete. ---------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,13 +219,23 @@ if ($argc > 1) {
|
|||||||
|
|
||||||
$upgrade_sql = array();
|
$upgrade_sql = array();
|
||||||
|
|
||||||
$result = mustal_calculate_db_upgrade($compare_def, $db_def, $upgrade_sql);
|
$result = mustal_calculate_db_upgrade($compare_def, $db_def, $upgrade_sql, $mustal_replacers);
|
||||||
|
|
||||||
if ($result != 0) {
|
if ($result != 0) {
|
||||||
echo("Error: $result\n");
|
echo("Error: $result\n");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($result)) {
|
||||||
|
echo(count($result)." errors.\n");
|
||||||
|
if ($verbose) {
|
||||||
|
foreach($result as $error) {
|
||||||
|
echo("Code: ".$error[0]." '".$error[1]."'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
echo("--------------- Database upgrade for '$schema@$host'... ---------------\n");
|
echo("--------------- Database upgrade for '$schema@$host'... ---------------\n");
|
||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
foreach($upgrade_sql as $statement) {
|
foreach($upgrade_sql as $statement) {
|
||||||
@ -281,7 +290,7 @@ if ($argc > 1) {
|
|||||||
$db_def = mustal_load_tables_from_db($host, $schema, $user, $passwd, $mustal_replacers);
|
$db_def = mustal_load_tables_from_db($host, $schema, $user, $passwd, $mustal_replacers);
|
||||||
|
|
||||||
echo("--------------- Comparing database '$schema@$host' vs. JSON '".$compare_def['database']."@".$compare_def['host']."' ---------------\n");
|
echo("--------------- Comparing database '$schema@$host' vs. JSON '".$compare_def['database']."@".$compare_def['host']."' ---------------\n");
|
||||||
$compare_differences = compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
$compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
||||||
echo((empty($compare_differences)?0:count($compare_differences))." differences.\n");
|
echo((empty($compare_differences)?0:count($compare_differences))." differences.\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -438,6 +438,7 @@ function mustal_implode_with_quote(string $quote, string $delimiter, array $arra
|
|||||||
|
|
||||||
|
|
||||||
// Calculate the sql neccessary to update the database
|
// Calculate the sql neccessary to update the database
|
||||||
|
// returns array(code,text)
|
||||||
// Error codes:
|
// Error codes:
|
||||||
// 0 ok
|
// 0 ok
|
||||||
// 1 Upgrade type of table not supported
|
// 1 Upgrade type of table not supported
|
||||||
@ -452,7 +453,10 @@ function mustal_implode_with_quote(string $quote, string $delimiter, array $arra
|
|||||||
// 10 Error on key definition upgrade
|
// 10 Error on key definition upgrade
|
||||||
// 11 Table type upgrade not supported
|
// 11 Table type upgrade not supported
|
||||||
// 12 Upgrade type not supported
|
// 12 Upgrade type not supported
|
||||||
function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql, array $replacers) : int {
|
|
||||||
|
function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql, array $replacers) : array {
|
||||||
|
|
||||||
|
$result = array();
|
||||||
$upgrade_sql = array();
|
$upgrade_sql = array();
|
||||||
|
|
||||||
$compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
$compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
||||||
@ -507,13 +511,11 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
|
|||||||
$upgrade_sql[] = $sql;
|
$upgrade_sql[] = $sql;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//echo("Upgrade type '".$table['type']."' on table '".$table['name']."' not supported.\n");
|
$result[] = array(1,"Upgrade type '".$table['type']."' on table '".$table['name']."' not supported.");
|
||||||
return(1);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// echo("Error table_key while creating upgrade for table existence `$table_name`.\n");
|
$result[] = array(2,"Error table_key while creating upgrade for table existence `$table_name`.");
|
||||||
return(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -533,13 +535,11 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
|
|||||||
$upgrade_sql[] = $sql;
|
$upgrade_sql[] = $sql;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// echo("Error column_key while creating column '$column_name' in table '".$table['name']."'\n");
|
$result[] = array(3,"Error column_key while creating column '$column_name' in table '".$table['name']."'.");
|
||||||
return(3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// echo("Error table_key while creating upgrade for column existence '$column_name' in table '$table_name'.\n");
|
$result[] = array(4,"Error table_key while creating upgrade for column existence '$column_name' in table '$table_name'.");
|
||||||
return(4);
|
|
||||||
}
|
}
|
||||||
// Add Column in DB
|
// Add Column in DB
|
||||||
break;
|
break;
|
||||||
@ -563,12 +563,11 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
|
|||||||
$upgrade_sql[] = $sql;
|
$upgrade_sql[] = $sql;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//echo("Error column_key while modifying column '$column_name' in table '".$table['name']."'\n");
|
$result[] = array(5,"Error column_key while modifying column '$column_name' in table '".$table['name']."'.");
|
||||||
return(5);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// echo("Error table_key while modifying column '$column_name' in table '$table_name'.\n");
|
$result[] = array(6,"Error table_key while modifying column '$column_name' in table '$table_name'.");
|
||||||
return(6);
|
return(6);
|
||||||
}
|
}
|
||||||
// Modify Column in DB
|
// Modify Column in DB
|
||||||
@ -594,13 +593,11 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
|
|||||||
$upgrade_sql[] = $sql;
|
$upgrade_sql[] = $sql;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//echo("Error key_key while adding key '$key_name' in table '".$table['name']."'\n");
|
$result[] = array(7,"Error key_key while adding key '$key_name' in table '".$table['name']."'.");
|
||||||
return(7);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//echo("Error table_key while adding key '$key_name' in table '$table_name'.\n");
|
$result[] = array(8,"Error table_key while adding key '$key_name' in table '$table_name'.");
|
||||||
return(8);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Key definition":
|
case "Key definition":
|
||||||
@ -626,29 +623,26 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
|
|||||||
$upgrade_sql[] = $sql;
|
$upgrade_sql[] = $sql;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//echo("Error key_key while changing key '$key_name' in table '".$table['name']."'\n");
|
$result[] = array(9, "Error key_key while changing key '$key_name' in table '".$table['name']."'.");
|
||||||
return(9);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// echo("Error table_key while changing key '$key_name' in table '$table_name'.\n");
|
$result[] = array(10,"Error table_key while changing key '$key_name' in table '$table_name'.");
|
||||||
return(10);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Table count':
|
case 'Table count':
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
break;
|
break;
|
||||||
case 'Table type':
|
case 'Table type':
|
||||||
// echo("Upgrade type '".$compare_difference['type']."' on table '".$compare_difference['table']."' not supported.\n");
|
$result[] = array(11,"Upgrade type '".$compare_difference['type']."' on table '".$compare_difference['table']."' not supported.");
|
||||||
return(11);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// echo("Upgrade type '".$compare_difference['type']."' not supported.\n");
|
$result[] = array(12,"Upgrade type '".$compare_difference['type']."' not supported.");
|
||||||
return(12);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$upgrade_sql = array_unique($upgrade_sql);
|
$upgrade_sql = array_unique($upgrade_sql);
|
||||||
return(0);
|
|
||||||
|
return($result);
|
||||||
}
|
}
|
||||||
|
@ -221,15 +221,18 @@ function upgrade_main(string $directory,bool $verbose, bool $do_upgrade, bool $f
|
|||||||
|
|
||||||
$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);
|
||||||
|
|
||||||
if ($result != 0) {
|
if (!empty($result)) {
|
||||||
abort("Error: $result\n");
|
abort(count($result)." errors.\n");
|
||||||
|
if ($verbose) {
|
||||||
|
foreach($result as $error) {
|
||||||
|
echo("Code: ".$error[0]." '".$error[1]."'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo(count($upgrade_sql)." upgrade statements\n");
|
echo(count($upgrade_sql)." upgrade statements\n");
|
||||||
|
|
||||||
echo("--------------- Executing database upgrade for '$schema@$host' database... ---------------\n");
|
echo("--------------- Executing database upgrade for '$schema@$host' database... ---------------\n");
|
||||||
|
|
||||||
// First get the contents of the database table structure
|
// First get the contents of the database table structure
|
||||||
$mysqli = mysqli_connect($host, $user, $passwd, $schema);
|
$mysqli = mysqli_connect($host, $user, $passwd, $schema);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user