fix: installer showing feeding failed, as well as adding proper error handling.

This commit is contained in:
Vikas Dongre 2024-02-17 23:38:30 +05:30
parent 6d61ca5cef
commit 9cc6e83819
2 changed files with 31 additions and 24 deletions

View file

@ -29,8 +29,7 @@ if (isset($_POST['checkDB'])) {
try { try {
$db = new mysqli($_POST['databasehost'], $_POST['databaseuser'], $_POST['databaseuserpass'], $_POST['database'], $_POST['databaseport']); $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'); wh_log($e->getMessage(), 'error');
header('LOCATION: index.php?step=2&message=' . $e->getMessage()); header('LOCATION: index.php?step=2&message=' . $e->getMessage());
exit(); exit();
@ -69,6 +68,7 @@ if (isset($_POST['feedDB'])) {
wh_log('Feeding the Database', 'debug'); wh_log('Feeding the Database', 'debug');
$logs = ''; $logs = '';
try {
//$logs .= run_console(setenv('COMPOSER_HOME', dirname(__FILE__, 3) . '/vendor/bin/composer')); //$logs .= run_console(setenv('COMPOSER_HOME', dirname(__FILE__, 3) . '/vendor/bin/composer'));
//$logs .= run_console('composer install --no-dev --optimize-autoloader'); //$logs .= run_console('composer install --no-dev --optimize-autoloader');
if (!str_contains(getenv('APP_KEY'), 'base64')) { if (!str_contains(getenv('APP_KEY'), 'base64')) {
@ -83,12 +83,11 @@ if (isset($_POST['feedDB'])) {
wh_log($logs, 'debug'); wh_log($logs, 'debug');
if (str_contains(getenv('APP_KEY'), 'base64')) {
wh_log('Feeding the Database successful', 'debug'); wh_log('Feeding the Database successful', 'debug');
header('LOCATION: index.php?step=3'); header('LOCATION: index.php?step=3');
} else { } catch (\Throwable $th) {
wh_log('Feeding the Database failed', 'debug'); wh_log('Feeding the Database failed', 'error');
header('LOCATION: index.php?step=2.5&message=There was an error. Please check the installer.log file in /var/www/controlpanel/storage/logs !'); 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; return $not_ok;
} }
function removeQuotes($string){ function removeQuotes($string)
{
return str_replace('"', "", $string); return str_replace('"', "", $string);
} }
@ -236,9 +237,16 @@ function run_console(string $command, array $descriptors = null, string $cwd = n
$path = dirname(__FILE__, 3); $path = dirname(__FILE__, 3);
$descriptors = $descriptors ?? [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; $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); $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'); if ($exit_code > 0) {
return stream_get_contents($pipes[1]); wh_log('command result: ' . $output, 'error');
throw new Exception("There was an error after running command `$command`", $exit_code);
return $output;
} else {
return $output;
}
} }
/** /**