diff --git a/application/Espo/Core/Upgrades/Actions/Base.php b/application/Espo/Core/Upgrades/Actions/Base.php index 9d92531963..e5344a57b1 100644 --- a/application/Espo/Core/Upgrades/Actions/Base.php +++ b/application/Espo/Core/Upgrades/Actions/Base.php @@ -159,7 +159,8 @@ abstract class Base public function throwErrorAndRemovePackage( string $errorMessage = '', bool $deletePackage = true, - bool $systemRebuild = true + bool $systemRebuild = true, + ?Throwable $exception = null ): void { if ($deletePackage) { @@ -173,7 +174,11 @@ abstract class Base $this->systemRebuild(); } - throw new Error($errorMessage); + if ($exception && !$errorMessage) { + $errorMessage = $exception->getMessage(); + } + + throw new Error($errorMessage, 0, $exception); } abstract public function run(mixed $data): mixed; @@ -393,7 +398,7 @@ abstract class Base $script->run($this->getContainer(), $this->scriptParams); } catch (Throwable $e) { - $this->throwErrorAndRemovePackage($e->getMessage()); + $this->throwErrorAndRemovePackage(exception: $e); } } @@ -411,7 +416,7 @@ abstract class Base return null; } - $beforeInstallScript = Util::concatPath(array($packagePath, self::SCRIPTS, $scriptName)) . '.php'; + $beforeInstallScript = Util::concatPath([$packagePath, self::SCRIPTS, $scriptName]) . '.php'; if (file_exists($beforeInstallScript)) { return $beforeInstallScript; @@ -623,7 +628,7 @@ abstract class Base return $this->getFileManager()->copy($sourcePath, $destPath, $recursively, $fileList, $copyOnlyFiles); } catch (Throwable $e) { - $this->throwErrorAndRemovePackage($e->getMessage()); + $this->throwErrorAndRemovePackage(exception: $e); } return false; @@ -749,7 +754,7 @@ abstract class Base $manifestPath = Util::concatPath($packagePath, $this->manifestName); if (!file_exists($manifestPath)) { - $this->throwErrorAndRemovePackage('It\'s not an Installation package.'); + $this->throwErrorAndRemovePackage("It's not an Installation package."); } $manifestJson = $this->getFileManager()->getContents($manifestPath); @@ -818,7 +823,7 @@ abstract class Base $res = $this->getZipUtil()->unzip($packageArchivePath, $packagePath); if ($res === false) { - $this->throwErrorAndRemovePackage('Unable to unzip the file - '.$packagePath.'.', false, false); + $this->throwErrorAndRemovePackage("Unable to unzip the file $packagePath.", false, false); } } @@ -858,9 +863,8 @@ abstract class Base } catch (Throwable $e) { try { - $this->getLog()->error('Database rebuild failure, details: '. $e->getMessage() .'.'); - } - catch (Throwable) {} + $this->getLog()->error("Database rebuild failure, details: {$e->getMessage()}."); + } catch (Throwable) {} } return false; diff --git a/application/Espo/Core/Upgrades/Actions/Base/Install.php b/application/Espo/Core/Upgrades/Actions/Base/Install.php index ef043a0785..940d77b2d7 100644 --- a/application/Espo/Core/Upgrades/Actions/Base/Install.php +++ b/application/Espo/Core/Upgrades/Actions/Base/Install.php @@ -32,6 +32,7 @@ namespace Espo\Core\Upgrades\Actions\Base; use Espo\Core\Exceptions\Error; use Espo\Core\Upgrades\Actions\Base; use Espo\Core\Utils\Util; +use Throwable; class Install extends Base { @@ -324,15 +325,17 @@ class Install extends Base } /** - * @param string $errorMessage - * @param bool $deletePackage - * @param bool $systemRebuild * @throws Error */ - public function throwErrorAndRemovePackage($errorMessage = '', $deletePackage = true, $systemRebuild = true): void - { + public function throwErrorAndRemovePackage( + string $errorMessage = '', + bool $deletePackage = true, + bool $systemRebuild = true, + ?Throwable $exception = null + ): void { + $this->restoreFiles(); - parent::throwErrorAndRemovePackage($errorMessage, $deletePackage, $systemRebuild); + parent::throwErrorAndRemovePackage($errorMessage, $deletePackage, $systemRebuild, $exception); } } diff --git a/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php b/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php index 6ad3ad5f6d..99283a5f76 100644 --- a/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php +++ b/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php @@ -33,6 +33,7 @@ use Espo\Core\Exceptions\Error; use Espo\Core\Upgrades\Actions\Base; use Espo\Core\Utils\Util; use Espo\Core\Utils\Json; +use Throwable; class Uninstall extends Base { @@ -182,16 +183,18 @@ class Uninstall extends Base } /** - * @param string $errorMessage - * @param bool $deletePackage - * @param bool $systemRebuild * @throws Error */ - public function throwErrorAndRemovePackage($errorMessage = '', $deletePackage = true, $systemRebuild = true): void - { + public function throwErrorAndRemovePackage( + string $errorMessage = '', + bool $deletePackage = true, + bool $systemRebuild = true, + ?Throwable $exception = null + ): void { + $this->restoreFiles(); - parent::throwErrorAndRemovePackage($errorMessage, false, $systemRebuild); + parent::throwErrorAndRemovePackage($errorMessage, false, $systemRebuild, $exception); } /**