|
@@ -10,7 +10,7 @@ use Monolog\Handler\StreamHandler;
|
|
use Monolog\Logger;
|
|
use Monolog\Logger;
|
|
|
|
|
|
if (!file_exists('../../.env')) {
|
|
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();
|
|
(new DotEnv(dirname(__FILE__, 3) . '/.env'))->load();
|
|
@@ -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);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -162,7 +163,7 @@ function removeQuotes($string){
|
|
*/
|
|
*/
|
|
function setenv($envKey, $envValue)
|
|
function setenv($envKey, $envValue)
|
|
{
|
|
{
|
|
- $envFile = dirname(__FILE__, 3).'/.env';
|
|
|
|
|
|
+ $envFile = dirname(__FILE__, 3) . '/.env';
|
|
$str = file_get_contents($envFile);
|
|
$str = file_get_contents($envFile);
|
|
|
|
|
|
$str .= "\n"; // In case the searched variable is in the last line without \n
|
|
$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);
|
|
$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);
|
|
-
|
|
|
|
- wh_log('command result: ' . stream_get_contents($pipes[1]), 'debug');
|
|
|
|
- return stream_get_contents($pipes[1]);
|
|
|
|
|
|
+ $output = stream_get_contents($pipes[1]);
|
|
|
|
+ $exit_code = proc_close($handle);
|
|
|
|
+
|
|
|
|
+ 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)) {
|
|
switch (strtolower($level)) {
|
|
case 'debug': // Only log debug messages if APP_DEBUG is true
|
|
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);
|
|
$log->debug($message, $context);
|
|
break;
|
|
break;
|
|
case 'info':
|
|
case 'info':
|