diff --git a/public/install/forms.php b/public/install/forms.php index 98f05657..96f1dfa1 100644 --- a/public/install/forms.php +++ b/public/install/forms.php @@ -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,26 +68,26 @@ if (isset($_POST['feedDB'])) { wh_log('Feeding the Database', 'debug'); $logs = ''; - //$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')) { - $logs .= run_console('php artisan key:generate --force'); - } else { - $logs .= "Key already exists. Skipping\n"; - } - $logs .= run_console('php artisan storage:link'); - $logs .= run_console('php artisan migrate --seed --force'); - $logs .= run_console('php artisan db:seed --class=ExampleItemsSeeder --force'); - $logs .= run_console('php artisan db:seed --class=PermissionsSeeder --force'); + 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')) { + $logs .= run_console('php artisan key:generate --force'); + } else { + $logs .= "Key already exists. Skipping\n"; + } + $logs .= run_console('php artisan storage:link'); + $logs .= run_console('php artisan migrate --seed --force'); + $logs .= run_console('php artisan db:seed --class=ExampleItemsSeeder --force'); + $logs .= run_console('php artisan db:seed --class=PermissionsSeeder --force'); - wh_log($logs, 'debug'); + 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() . "
Please check the installer.log file in /var/www/controlpanel/storage/logs !"); } } diff --git a/public/install/functions.php b/public/install/functions.php index 8eb1318c..451d8b95 100644 --- a/public/install/functions.php +++ b/public/install/functions.php @@ -10,7 +10,7 @@ use Monolog\Handler\StreamHandler; use Monolog\Logger; if (!file_exists('../../.env')) { - echo run_console('cp .env.example .env'); + echo run_console('cp .env.example .env'); } (new DotEnv(dirname(__FILE__, 3) . '/.env'))->load(); @@ -150,7 +150,8 @@ function checkExtensions(): array return $not_ok; } -function removeQuotes($string){ +function removeQuotes($string) +{ return str_replace('"', "", $string); } @@ -162,7 +163,7 @@ function removeQuotes($string){ */ function setenv($envKey, $envValue) { - $envFile = dirname(__FILE__, 3).'/.env'; + $envFile = dirname(__FILE__, 3) . '/.env'; $str = file_get_contents($envFile); $str .= "\n"; // In case the searched variable is in the last line without \n @@ -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; + } } /** @@ -259,7 +267,7 @@ function wh_log(string $message, string $level = 'info', array $context = []): v switch (strtolower($level)) { case 'debug': // Only log debug messages if APP_DEBUG is true - if(getenv('APP_DEBUG') === false) return; + if (getenv('APP_DEBUG') === false) return; $log->debug($message, $context); break; case 'info':