fix: installer showing feeding failed, as well as adding proper error handling (#929)

This commit is contained in:
Dennis 2024-02-28 12:18:32 +01:00 committed by GitHub
commit 0e29eb171a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 24 deletions

View file

@ -29,8 +29,7 @@ if (isset($_POST['checkDB'])) {
try {
$db = new mysqli($_POST['databasehost'], $_POST['databaseuser'], $_POST['databaseuserpass'], $_POST['database'], $_POST['databaseport']);
}
catch (mysqli_sql_exception $e) {
} catch (mysqli_sql_exception $e) {
wh_log($e->getMessage(), 'error');
header('LOCATION: index.php?step=2&message=' . $e->getMessage());
exit();
@ -69,6 +68,7 @@ if (isset($_POST['feedDB'])) {
wh_log('Feeding the Database', 'debug');
$logs = '';
try {
//$logs .= run_console(setenv('COMPOSER_HOME', dirname(__FILE__, 3) . '/vendor/bin/composer'));
//$logs .= run_console('composer install --no-dev --optimize-autoloader');
if (!str_contains(getenv('APP_KEY'), 'base64')) {
@ -83,12 +83,11 @@ if (isset($_POST['feedDB'])) {
wh_log($logs, 'debug');
if (str_contains(getenv('APP_KEY'), 'base64')) {
wh_log('Feeding the Database successful', 'debug');
header('LOCATION: index.php?step=3');
} else {
wh_log('Feeding the Database failed', 'debug');
header('LOCATION: index.php?step=2.5&message=There was an error. Please check the installer.log file in /var/www/controlpanel/storage/logs !');
} catch (\Throwable $th) {
wh_log('Feeding the Database failed', 'error');
header("LOCATION: index.php?step=2.5&message=" . $th->getMessage() . " <br>Please check the installer.log file in /var/www/controlpanel/storage/logs !");
}
}

View file

@ -150,7 +150,8 @@ function checkExtensions(): array
return $not_ok;
}
function removeQuotes($string){
function removeQuotes($string)
{
return str_replace('"', "", $string);
}
@ -236,9 +237,16 @@ function run_console(string $command, array $descriptors = null, string $cwd = n
$path = dirname(__FILE__, 3);
$descriptors = $descriptors ?? [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
$handle = proc_open("cd '$path' && bash -c 'exec -a ServerCPP $command'", $descriptors, $pipes, $cwd, null, $options);
$output = stream_get_contents($pipes[1]);
$exit_code = proc_close($handle);
wh_log('command result: ' . stream_get_contents($pipes[1]), 'debug');
return stream_get_contents($pipes[1]);
if ($exit_code > 0) {
wh_log('command result: ' . $output, 'error');
throw new Exception("There was an error after running command `$command`", $exit_code);
return $output;
} else {
return $output;
}
}
/**