Changes for Schema Check

This commit is contained in:
Félix Suárez 2024-04-10 08:30:25 -06:00
parent cee3d3b64b
commit 32755235e9

View File

@ -164,28 +164,53 @@ function extension_db_status_execute_checks($db_user, $db_password, $db_host, $d
$db_name = explode(' ', $db_name);
$db_name = $db_name[0];
if ($config['mysqli'] === true) {
try {
if ($config['mysqli']) {
$connection_test = mysqli_connect($db_host, $db_user, $db_password);
} else {
$connection_test = mysql_connect($db_host, $db_user, $db_password);
}
} catch (Exception $e) {
$connection_test = false;
}
if (!$connection_test) {
ui_print_error_message(
__('Unsuccessful connected to the DB')
);
ui_print_error_message(__('Unsuccessful connected to the DB'));
return;
}
try {
$query = "SELECT IF(EXISTS(SELECT 1 FROM information_schema.SCHEMATA WHERE schema_name = '$db_name'), 'true', 'false') AS result";
if ($config['mysqli']) {
$exist_db = mysqli_fetch_assoc(mysqli_query($connection_test, $query))['result'];
} else {
if ($config['mysqli'] === true) {
$exist_db = mysql_fetch_assoc(mysqli_query($connection_test, $query))['result'];
}
} catch (Exception $e) {
ui_print_error_message(__("There was a problem during verification of the existence of the `$db_name` table"));
return;
}
if ($exist_db == 'true') {
ui_print_error_message(__("The testing DB `$db_name` already exists"));
return;
}
try {
if ($config['mysqli']) {
$create_db = mysqli_query($connection_test, "CREATE DATABASE `$db_name`");
} else {
$create_db = mysql_query("CREATE DATABASE `$db_name`");
}
} catch (Exception $e) {
$connection_test = false;
}
if (!$create_db) {
ui_print_error_message(
__('Unsuccessful created the testing DB')
);
} else {
ui_print_error_message(__('Unsuccessful created the testing DB'));
return;
}
if ($config['mysqli'] === true) {
mysqli_select_db($connection_test, $db_name);
} else {
@ -198,17 +223,17 @@ function extension_db_status_execute_checks($db_user, $db_password, $db_host, $d
);
if (!$install_tables) {
ui_print_error_message(
__('Unsuccessful installed tables into the testing DB')
);
} else {
ui_print_error_message(__('Unsuccessful installed tables into the testing DB'));
return;
}
extension_db_check_tables_differences(
$connection_test,
$connection_system,
$db_name,
$config['dbname']
);
}
if ($config['mysqli'] === true) {
mysqli_select_db($connection_test, $db_name);
@ -218,8 +243,6 @@ function extension_db_status_execute_checks($db_user, $db_password, $db_host, $d
mysql_query("DROP DATABASE IF EXISTS `$db_name`", $connection_test);
}
}
}
}
function extension_db_check_tables_differences(