catch process exceptions
This commit is contained in:
parent
2d4d429758
commit
d415cd6ae8
@ -61,7 +61,7 @@ class UpdateAll extends Command
|
|||||||
|
|
||||||
$command = "update {$alias} {$company_id}";
|
$command = "update {$alias} {$company_id}";
|
||||||
|
|
||||||
if (true !== $result = Console::run($command, true)) {
|
if (true !== $result = Console::run($command)) {
|
||||||
$message = !empty($result) ? $result : trans('modules.errors.finish', ['module' => $alias]);
|
$message = !empty($result) ? $result : trans('modules.errors.finish', ['module' => $alias]);
|
||||||
|
|
||||||
$this->error($message);
|
$this->error($message);
|
||||||
|
@ -3,29 +3,48 @@
|
|||||||
namespace App\Utilities;
|
namespace App\Utilities;
|
||||||
|
|
||||||
use Illuminate\Console\Application;
|
use Illuminate\Console\Application;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Process\Exception\LogicException;
|
||||||
|
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||||
|
use Symfony\Component\Process\Exception\RuntimeException;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
class Console
|
class Console
|
||||||
{
|
{
|
||||||
public static function run($string, $all_output = false, $timeout = 0)
|
public static function run($string, $timeout = 0)
|
||||||
{
|
{
|
||||||
$command = Application::formatCommandString($string);
|
$command = Application::formatCommandString($string);
|
||||||
|
|
||||||
logger('Console command:: ' . $command);
|
logger('Console command:: ' . $command);
|
||||||
|
|
||||||
$process = Process::fromShellCommandline($command, base_path());
|
try {
|
||||||
$process->setTimeout($timeout);
|
$process = Process::fromShellCommandline($command, base_path());
|
||||||
|
$process->setTimeout($timeout);
|
||||||
|
|
||||||
$process->run();
|
$process->mustRun();
|
||||||
|
|
||||||
if ($process->isSuccessful()) {
|
$output = $process->getOutput();
|
||||||
return true;
|
|
||||||
|
if (static::isValidOutput($output)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (InvalidArgumentException | LogicException | ProcessFailedException | RuntimeException $e) {
|
||||||
|
$output = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = $all_output ? $process->getOutput() : $process->getErrorOutput();
|
|
||||||
|
|
||||||
logger('Console output:: ' . $output);
|
logger('Console output:: ' . $output);
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function isValidOutput($output)
|
||||||
|
{
|
||||||
|
$errors = [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'CSRF token mismatch',
|
||||||
|
];
|
||||||
|
|
||||||
|
return !Str::contains($output, $errors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user