Skip to content

Commit

Permalink
Return exit code on unhandled exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Jul 2, 2024
1 parent dd83cb6 commit 9ba589d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions classes/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function exceptionHandler(Throwable $e): void
{
$message = get_class($e) . ': ' . $e->getMessage();
$this->report($e->getFile(), $e->getLine(), Logger::CRITICAL, $message, $e->getTraceAsString(), true);
exit(64);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion cli-rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/

use PrestaShop\Module\AutoUpgrade\ErrorHandler;

if (PHP_SAPI !== 'cli') {
echo 'This script must be called from CLI';
exit(1);
Expand All @@ -32,7 +35,9 @@
require_once realpath(dirname(__FILE__) . '/../../modules/autoupgrade') . '/ajax-upgradetabconfig.php';
$container = autoupgrade_init_container(dirname(__FILE__));

$container->setLogger(new PrestaShop\Module\AutoUpgrade\Log\StreamedLogger());
$logger = new PrestaShop\Module\AutoUpgrade\Log\StreamedLogger();
$container->setLogger($logger);
(new ErrorHandler($logger))->enable();
$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback\AllRollbackTasks($container);
$controller->setOptions(getopt('', ['backup::']));
$controller->init();
Expand Down
6 changes: 5 additions & 1 deletion cli-upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/

use PrestaShop\Module\AutoUpgrade\ErrorHandler;

if (PHP_SAPI !== 'cli') {
echo 'This script must be called from CLI';
exit(1);
Expand All @@ -40,6 +43,7 @@

$logger = new PrestaShop\Module\AutoUpgrade\Log\StreamedLogger();
$container->setLogger($logger);
(new ErrorHandler($logger))->enable();
$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\AllUpgradeTasks($container);
$controller->setOptions(getopt('', ['action::', 'channel::', 'data::']));
$controller->init();
Expand All @@ -54,7 +58,7 @@

if ($chain && strpos($logger->getLastInfo(), 'cli-upgrade.php') !== false) {
$new_string = str_replace('INFO - $ ', '', $logger->getLastInfo());
system('php ' . $new_string . ' 2>&1', $exitCode);
system('php ' . $new_string, $exitCode);
}

exit($exitCode);
Expand Down

0 comments on commit 9ba589d

Please sign in to comment.