upgrade error previous exception

This commit is contained in:
Yuri Kuznetsov
2024-09-05 12:50:09 +03:00
parent a2668bb3a2
commit a7bd9f2741
3 changed files with 32 additions and 22 deletions
+14 -10
View File
@@ -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;
@@ -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);
}
}
@@ -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);
}
/**