Skip to content

Commit

Permalink
Merge pull request cypht-org#1251 from Baraka24/update-setup_database…
Browse files Browse the repository at this point in the history
….php

[FIX]setup_database.php: Check if the required MySQL extensions are loaded
  • Loading branch information
Yannick243 authored Sep 23, 2024
2 parents c52b2c2 + b026888 commit 25107b5
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions scripts/setup_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,39 @@

// NOTE: these sql commands could be db agnostic if we change the blobs to text

// Check if the required extensions for the configured DB driver are loaded
if ($db_driver == 'mysql') {
$required_extensions = ['mysqli', 'mysqlnd', 'pdo_mysql'];
$missing_extensions = [];

foreach ($required_extensions as $extension) {
if (!extension_loaded($extension)) {
$missing_extensions[] = $extension;
}
}

if (!empty($missing_extensions)) {
error_log('The following required MySQL extensions are missing: ' . implode(', ', $missing_extensions) . ". Please install them.\n");
exit(1);
}
} elseif ($db_driver == 'pgsql') {
$required_extensions = ['pgsql', 'pdo_pgsql'];
$missing_extensions = [];

foreach ($required_extensions as $extension) {
if (!extension_loaded($extension)) {
$missing_extensions[] = $extension;
}
}

if (!empty($missing_extensions)) {
error_log('The following required PostgreSQL extensions are missing: ' . implode(', ', $missing_extensions) . ". Please install them.\n");
exit(1);
}
} else {
error_log("Unsupported DB driver: {$db_driver}");
exit(1);
}

$connection_tries=0;
$max_tries=10;
Expand All @@ -43,7 +76,7 @@
printf("Attempting to connect to database ... ({$connection_tries}/{$max_tries})\n");
sleep(1);
}

if ($connection_tries >= $max_tries) {
error_log('Unable to connect to database');
exit(1);
Expand Down Expand Up @@ -85,7 +118,7 @@

}
if (strcasecmp($user_config_type, 'DB')==0) {

printf("Creating database table hm_user_settings ...\n");

if ($db_driver == 'mysql' || $db_driver == 'sqlite') {
Expand All @@ -95,7 +128,7 @@
} else {
die($bad_driver);
}

$conn->exec($stmt);
}

Expand Down

0 comments on commit 25107b5

Please sign in to comment.