Initial commit
This commit is contained in:
1106
application/Espo/Core/Upgrades/Actions/Base.php
Normal file
1106
application/Espo/Core/Upgrades/Actions/Base.php
Normal file
File diff suppressed because it is too large
Load Diff
78
application/Espo/Core/Upgrades/Actions/Base/Delete.php
Normal file
78
application/Espo/Core/Upgrades/Actions/Base/Delete.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
class Delete extends Base
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(mixed $data): mixed
|
||||
{
|
||||
$processId = $data['id'];
|
||||
|
||||
$this->getLog()->debug('Delete package process ['.$processId.']: start run.');
|
||||
|
||||
if (empty($processId)) {
|
||||
throw new Error('Delete package package ID was not specified.');
|
||||
}
|
||||
|
||||
$this->initialize();
|
||||
$this->setProcessId($processId);
|
||||
|
||||
if (isset($data['parentProcessId'])) {
|
||||
$this->setParentProcessId($data['parentProcessId']);
|
||||
}
|
||||
|
||||
$this->beforeRunAction();
|
||||
/* delete a package */
|
||||
$this->deletePackage();
|
||||
$this->afterRunAction();
|
||||
$this->finalize();
|
||||
|
||||
$this->getLog()->debug('Delete package process ['.$processId.']: end run.');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
protected function deletePackage(): bool
|
||||
{
|
||||
$packageArchivePath = $this->getPackagePath(true);
|
||||
|
||||
return $this->getFileManager()->removeFile($packageArchivePath);
|
||||
}
|
||||
}
|
||||
341
application/Espo/Core/Upgrades/Actions/Base/Install.php
Normal file
341
application/Espo/Core/Upgrades/Actions/Base/Install.php
Normal file
@@ -0,0 +1,341 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
* Main installation process.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(mixed $data): mixed
|
||||
{
|
||||
$processId = $data['id'];
|
||||
|
||||
$this->getLog()->debug("Installation process [$processId]: start run.");
|
||||
|
||||
$this->stepInit($data);
|
||||
$this->stepCopyBefore($data);
|
||||
|
||||
if ($this->getCopyFilesPath('before')) {
|
||||
$this->stepRebuild($data);
|
||||
}
|
||||
|
||||
$this->stepBeforeInstallScript($data);
|
||||
|
||||
if ($this->getScriptPath('before')) {
|
||||
$this->stepRebuild($data);
|
||||
}
|
||||
|
||||
$this->stepCopy($data);
|
||||
$this->stepRebuild($data);
|
||||
|
||||
$this->stepCopyAfter($data);
|
||||
|
||||
if ($this->getCopyFilesPath('after')) {
|
||||
$this->stepRebuild($data);
|
||||
}
|
||||
|
||||
$this->stepAfterInstallScript($data);
|
||||
if ($this->getScriptPath('after')) {
|
||||
$this->stepRebuild($data);
|
||||
}
|
||||
|
||||
$this->stepFinalize($data);
|
||||
|
||||
$this->getLog()->debug("Installation process [$processId]: end run.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
protected function initPackage(array $data): void
|
||||
{
|
||||
$processId = $data['id'];
|
||||
|
||||
if (empty($processId)) {
|
||||
throw new Error('Installation package ID was not specified.');
|
||||
}
|
||||
|
||||
$this->setProcessId($processId);
|
||||
|
||||
if (isset($data['parentProcessId'])) {
|
||||
$this->setParentProcessId($data['parentProcessId']);
|
||||
}
|
||||
|
||||
/** check if an archive is unzipped, if no then unzip */
|
||||
$packagePath = $this->getPackagePath();
|
||||
|
||||
if (!file_exists($packagePath)) {
|
||||
$this->unzipArchive();
|
||||
$this->isAcceptable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepInit(array $data): void
|
||||
{
|
||||
$this->initPackage($data);
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: Start \"init\" step.");
|
||||
|
||||
if (!$this->systemRebuild()) {
|
||||
$this->throwErrorAndRemovePackage('Rebuild is failed. Fix all errors before upgrade.');
|
||||
}
|
||||
|
||||
$this->initialize();
|
||||
$this->checkIsWritable();
|
||||
$this->enableMaintenanceMode();
|
||||
$this->beforeRunAction();
|
||||
$this->backupExistingFiles();
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: End \"init\" step.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepCopyBefore(array $data): void
|
||||
{
|
||||
$this->initPackage($data);
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: Start \"copyBefore\" step.");
|
||||
|
||||
if (!$this->copyFiles('before')) {
|
||||
$this->throwErrorAndRemovePackage('Cannot copy beforeInstall files.');
|
||||
}
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: End \"copyBefore\" step.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepBeforeInstallScript(array $data): void
|
||||
{
|
||||
$this->initPackage($data);
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: Start \"beforeInstallScript\" step.");
|
||||
|
||||
if (!isset($data['skipBeforeScript']) || !$data['skipBeforeScript']) {
|
||||
$this->runScript('before');
|
||||
}
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: End \"beforeInstallScript\" step.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepCopy(array $data): void
|
||||
{
|
||||
$this->initPackage($data);
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: Start \"copy\" step.");
|
||||
|
||||
/* remove files defined in a manifest */
|
||||
if (!$this->deleteFiles('delete', true)) {
|
||||
$this->throwErrorAndRemovePackage('Cannot delete files.');
|
||||
}
|
||||
|
||||
/* copy files from directory "Files" to EspoCRM files */
|
||||
if (!$this->copyFiles()) {
|
||||
$this->throwErrorAndRemovePackage('Cannot copy files.');
|
||||
}
|
||||
|
||||
if (!$this->deleteFiles('vendor')) {
|
||||
$this->throwErrorAndRemovePackage('Cannot delete vendor files.');
|
||||
}
|
||||
|
||||
if (!$this->copyFiles('vendor')) {
|
||||
$this->throwErrorAndRemovePackage('Cannot copy vendor files.');
|
||||
}
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: End \"copy\" step.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepRebuild(array $data): void
|
||||
{
|
||||
$this->initPackage($data);
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: Start \"rebuild\" step.");
|
||||
|
||||
if (!isset($data['skipSystemRebuild']) || !$data['skipSystemRebuild']) {
|
||||
if (!$this->systemRebuild()) {
|
||||
$this->throwErrorAndRemovePackage('Error occurred while EspoCRM rebuild. More detail in the log.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: End \"rebuild\" step.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepCopyAfter(array $data): void
|
||||
{
|
||||
$this->initPackage($data);
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: Start \"copyAfter\" step.");
|
||||
|
||||
//afterInstallFiles
|
||||
if (!$this->copyFiles('after')) {
|
||||
$this->throwErrorAndRemovePackage('Cannot copy afterInstall files.');
|
||||
}
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: End \"copyAfter\" step.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepAfterInstallScript(array $data): void
|
||||
{
|
||||
$this->initPackage($data);
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: Start \"afterInstallScript\" step.");
|
||||
|
||||
/* run after install script */
|
||||
if (!isset($data['skipAfterScript']) || !$data['skipAfterScript']) {
|
||||
$this->runScript('after');
|
||||
}
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: End \"afterInstallScript\" step.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepFinalize(array $data): void
|
||||
{
|
||||
$this->initPackage($data);
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: Start \"finalize\" step.");
|
||||
|
||||
$this->disableMaintenanceMode();
|
||||
$this->afterRunAction();
|
||||
$this->finalize();
|
||||
|
||||
/* delete unzipped files */
|
||||
$this->deletePackageFiles();
|
||||
|
||||
if ($this->getManifestParam('skipBackup')) {
|
||||
$path = Util::concatPath($this->getPath('backupPath'), self::FILES);
|
||||
|
||||
$this->getFileManager()->removeInDir($path);
|
||||
}
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: End \"finalize\" step.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepRevert(array $data): void
|
||||
{
|
||||
$this->initPackage($data);
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: Start \"revert\" step.");
|
||||
|
||||
$this->restoreFiles();
|
||||
|
||||
$this->getLog()->info("Installation process [{$this->getProcessId()}]: End \"revert\" step.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
protected function restoreFiles(): bool
|
||||
{
|
||||
$this->getLog()->info('Installer: Restore previous files.');
|
||||
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
$backupFilePath = Util::concatPath($backupPath, self::FILES);
|
||||
|
||||
if (!file_exists($backupFilePath)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$backupFileList = $this->getRestoreFileList();
|
||||
$copyFileList = $this->getCopyFileList();
|
||||
$deleteFileList = array_diff($copyFileList, $backupFileList);
|
||||
|
||||
$res = $this->copy($backupFilePath, '', true);
|
||||
|
||||
if (!empty($deleteFileList)) {
|
||||
$res &= $this->getFileManager()->remove($deleteFileList, null, true);
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
$this->getFileManager()->removeInDir($backupPath, true);
|
||||
}
|
||||
|
||||
return (bool) $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function throwErrorAndRemovePackage(
|
||||
string $errorMessage = '',
|
||||
bool $deletePackage = true,
|
||||
bool $systemRebuild = true,
|
||||
?Throwable $exception = null
|
||||
): void {
|
||||
|
||||
$this->restoreFiles();
|
||||
|
||||
parent::throwErrorAndRemovePackage($errorMessage, $deletePackage, $systemRebuild, $exception);
|
||||
}
|
||||
}
|
||||
250
application/Espo/Core/Upgrades/Actions/Base/Uninstall.php
Normal file
250
application/Espo/Core/Upgrades/Actions/Base/Uninstall.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(mixed $data): mixed
|
||||
{
|
||||
$processId = $data['id'];
|
||||
|
||||
$this->getLog()->debug('Uninstallation process ['.$processId.']: start run.');
|
||||
|
||||
if (empty($processId)) {
|
||||
throw new Error('Uninstallation package ID was not specified.');
|
||||
}
|
||||
|
||||
$this->setProcessId($processId);
|
||||
|
||||
if (isset($data['parentProcessId'])) {
|
||||
$this->setParentProcessId($data['parentProcessId']);
|
||||
}
|
||||
|
||||
$this->initialize();
|
||||
$this->checkIsWritable();
|
||||
$this->enableMaintenanceMode();
|
||||
$this->beforeRunAction();
|
||||
|
||||
/* run before uninstall script */
|
||||
if (!isset($data['skipBeforeScript']) || !$data['skipBeforeScript']) {
|
||||
$this->runScript('beforeUninstall');
|
||||
}
|
||||
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
if (file_exists($backupPath)) {
|
||||
/* copy core files */
|
||||
if (!$this->copyFiles()) {
|
||||
$this->throwErrorAndRemovePackage('Cannot copy files.');
|
||||
}
|
||||
}
|
||||
|
||||
/* remove extension files, saved in fileList */
|
||||
if (!$this->deleteFiles('delete', true)) {
|
||||
$this->throwErrorAndRemovePackage('Permission denied to delete files.');
|
||||
}
|
||||
|
||||
$this->disableMaintenanceMode();
|
||||
|
||||
if (!isset($data['skipSystemRebuild']) || !$data['skipSystemRebuild']) {
|
||||
if (!$this->systemRebuild()) {
|
||||
$this->throwErrorAndRemovePackage(
|
||||
'Error occurred while EspoCRM rebuild. More detail in the log.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* run after uninstall script */
|
||||
if (!isset($data['skipAfterScript']) || !$data['skipAfterScript']) {
|
||||
$this->runScript('afterUninstall');
|
||||
}
|
||||
|
||||
$this->afterRunAction();
|
||||
/* delete backup files */
|
||||
$this->deletePackageFiles();
|
||||
$this->finalize();
|
||||
|
||||
$this->getLog()->debug('Uninstallation process ['.$processId.']: end run.');
|
||||
|
||||
$this->clearCache();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
protected function restoreFiles(): bool
|
||||
{
|
||||
/** @noinspection PhpRedundantOptionalArgumentInspection */
|
||||
$packagePath = $this->getPath('packagePath');
|
||||
|
||||
$manifestPath = Util::concatPath($packagePath, $this->manifestName);
|
||||
|
||||
if (!file_exists($manifestPath)) {
|
||||
$this->unzipArchive($packagePath);
|
||||
}
|
||||
|
||||
$fileDirs = $this->getFileDirs($packagePath);
|
||||
|
||||
$res = true;
|
||||
|
||||
foreach ($fileDirs as $filesPath) {
|
||||
if (file_exists($filesPath)) {
|
||||
$res = $this->copy($filesPath, '', true);
|
||||
}
|
||||
}
|
||||
|
||||
$manifestJson = $this->getFileManager()->getContents($manifestPath);
|
||||
$manifest = Json::decode($manifestJson, true);
|
||||
|
||||
if (!empty($manifest['delete'])) {
|
||||
$res &= $this->getFileManager()->remove($manifest['delete'], null, true);
|
||||
}
|
||||
|
||||
$res &= $this->getFileManager()->removeInDir($packagePath, true);
|
||||
|
||||
return (bool) $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ?string $type
|
||||
* @param string $dest
|
||||
* @throws Error
|
||||
*/
|
||||
protected function copyFiles($type = null, $dest = ''): bool
|
||||
{
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
|
||||
$source = Util::concatPath($backupPath, self::FILES);
|
||||
|
||||
return $this->copy($source, $dest, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backup path.
|
||||
*
|
||||
* @param bool $isPackage
|
||||
* @throws Error
|
||||
*/
|
||||
protected function getPackagePath($isPackage = false): string
|
||||
{
|
||||
if ($isPackage) {
|
||||
return $this->getPath('packagePath', $isPackage);
|
||||
}
|
||||
|
||||
return $this->getPath('backupPath');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
protected function deletePackageFiles(): bool
|
||||
{
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
|
||||
return $this->getFileManager()->removeInDir($backupPath, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function throwErrorAndRemovePackage(
|
||||
string $errorMessage = '',
|
||||
bool $deletePackage = true,
|
||||
bool $systemRebuild = true,
|
||||
?Throwable $exception = null
|
||||
): void {
|
||||
|
||||
$this->restoreFiles();
|
||||
|
||||
parent::throwErrorAndRemovePackage($errorMessage, false, $systemRebuild, $exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
* @throws Error
|
||||
*/
|
||||
protected function getCopyFileList(): array
|
||||
{
|
||||
if (!isset($this->data['fileList'])) {
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
$filesPath = Util::concatPath($backupPath, self::FILES);
|
||||
|
||||
$this->data['fileList'] = $this->getFileManager()->getFileList($filesPath, true, '', true, true);
|
||||
}
|
||||
|
||||
return $this->data['fileList'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
protected function getRestoreFileList(): array
|
||||
{
|
||||
if (!isset($this->data['restoreFileList'])) {
|
||||
$packagePath = $this->getPackagePath();
|
||||
$filesPath = Util::concatPath($packagePath, self::FILES);
|
||||
|
||||
if (!file_exists($filesPath)) {
|
||||
$this->unzipArchive($packagePath);
|
||||
}
|
||||
|
||||
$this->data['restoreFileList'] = $this->getFileManager()->getFileList($filesPath, true, '', true, true);
|
||||
}
|
||||
|
||||
return $this->data['restoreFileList'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @throws Error
|
||||
*/
|
||||
protected function getDeleteList($type = 'delete'): array
|
||||
{
|
||||
if ($type == 'delete') {
|
||||
$packageFileList = $this->getRestoreFileList();
|
||||
$backupFileList = $this->getCopyFileList();
|
||||
|
||||
return array_diff($packageFileList, $backupFileList);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
78
application/Espo/Core/Upgrades/Actions/Base/Upload.php
Normal file
78
application/Espo/Core/Upgrades/Actions/Base/Upload.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
class Upload extends Base
|
||||
{
|
||||
/**
|
||||
* Upload an upgrade/extension package.
|
||||
*
|
||||
* @param string $data
|
||||
* @return string ID of upgrade/extension process.
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(mixed $data): string
|
||||
{
|
||||
$processId = $this->createProcessId();
|
||||
|
||||
$this->getLog()->debug("Installation process [$processId]: start upload the package.");
|
||||
|
||||
$this->initialize();
|
||||
$this->beforeRunAction();
|
||||
|
||||
$packageArchivePath = $this->getPackagePath(true);
|
||||
|
||||
$contents = null;
|
||||
|
||||
if (!empty($data)) {
|
||||
[, $contents] = explode(',', $data);
|
||||
|
||||
$contents = base64_decode($contents);
|
||||
}
|
||||
|
||||
$res = $this->getFileManager()->putContents($packageArchivePath, $contents);
|
||||
|
||||
if ($res === false) {
|
||||
throw new Error('Could not upload the package.');
|
||||
}
|
||||
|
||||
$this->unzipArchive();
|
||||
$this->isAcceptable();
|
||||
$this->afterRunAction();
|
||||
$this->finalize();
|
||||
|
||||
$this->getLog()->debug("Installation process [$processId]: end upload the package.");
|
||||
|
||||
return $processId;
|
||||
}
|
||||
}
|
||||
68
application/Espo/Core/Upgrades/Actions/Extension/Delete.php
Normal file
68
application/Espo/Core/Upgrades/Actions/Extension/Delete.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Extension;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Entities\Extension;
|
||||
|
||||
class Delete extends \Espo\Core\Upgrades\Actions\Base\Delete
|
||||
{
|
||||
protected ?Extension $extensionEntity = null;
|
||||
|
||||
/**
|
||||
* Get an entity of this extension.
|
||||
*
|
||||
* @throws Error
|
||||
*/
|
||||
protected function getExtensionEntity(): Extension
|
||||
{
|
||||
if (!$this->extensionEntity) {
|
||||
$processId = $this->getProcessId();
|
||||
|
||||
$this->extensionEntity = $this->getEntityManager()->getEntityById(Extension::ENTITY_TYPE, $processId);
|
||||
|
||||
if (!$this->extensionEntity) {
|
||||
throw new Error('Extension entity not found.');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->extensionEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
protected function afterRunAction(): void
|
||||
{
|
||||
/** Delete extension entity */
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
$this->getEntityManager()->removeEntity($extensionEntity);
|
||||
}
|
||||
}
|
||||
245
application/Espo/Core/Upgrades/Actions/Extension/Install.php
Normal file
245
application/Espo/Core/Upgrades/Actions/Extension/Install.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Extension;
|
||||
|
||||
use Espo\Core\Upgrades\Base;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
use Espo\Entities\Extension;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Throwable;
|
||||
|
||||
class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
{
|
||||
protected ?Extension $extensionEntity = null;
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
protected function beforeRunAction(): void
|
||||
{
|
||||
$this->loadExtension();
|
||||
|
||||
if (!$this->isNew()) {
|
||||
$this->scriptParams['isUpgrade'] = true;
|
||||
|
||||
$this->compareVersion();
|
||||
$this->uninstallExtension();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
protected function afterRunAction(): void
|
||||
{
|
||||
if (!$this->isNew()) {
|
||||
$this->deleteExtension();
|
||||
}
|
||||
|
||||
$this->storeExtension();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy Existing files to a backup directory.
|
||||
*
|
||||
* @throws Error
|
||||
*/
|
||||
protected function backupExistingFiles(): bool
|
||||
{
|
||||
parent::backupExistingFiles();
|
||||
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
|
||||
/** copy scripts files */
|
||||
$packagePath = $this->getPackagePath();
|
||||
|
||||
$source = Util::concatPath($packagePath, self::SCRIPTS);
|
||||
$destination = Util::concatPath($backupPath, self::SCRIPTS);
|
||||
|
||||
return $this->copy($source, $destination, true);
|
||||
}
|
||||
|
||||
private function isNew(): bool
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
if ($extensionEntity) {
|
||||
$id = $extensionEntity->get(Attribute::ID);
|
||||
}
|
||||
|
||||
return !isset($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity of the extension.
|
||||
*/
|
||||
private function getExtensionEntity(): ?Extension
|
||||
{
|
||||
return $this->extensionEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the extension entity.
|
||||
*
|
||||
* @throws Error
|
||||
*/
|
||||
private function loadExtension(): void
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
|
||||
$this->extensionEntity = $this->getEntityManager()
|
||||
->getRDBRepositoryByClass(Extension::class)
|
||||
->where([
|
||||
'name' => $manifest['name'],
|
||||
'isInstalled' => true,
|
||||
])
|
||||
->findOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a record of an extension entity.
|
||||
*
|
||||
* @throws Error
|
||||
*/
|
||||
private function storeExtension(): void
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
|
||||
$extensionEntity = null;
|
||||
|
||||
if ($this->getProcessId()) {
|
||||
$extensionEntity = $entityManager->getEntityById(Extension::ENTITY_TYPE, $this->getProcessId());
|
||||
}
|
||||
|
||||
if (!$extensionEntity) {
|
||||
$extensionEntity = $entityManager->getNewEntity(Extension::ENTITY_TYPE);
|
||||
}
|
||||
|
||||
$manifest = $this->getManifest();
|
||||
$fileList = $this->getCopyFileList();
|
||||
|
||||
$data = [
|
||||
'id' => $this->getProcessId(),
|
||||
'name' => trim($manifest['name']),
|
||||
'isInstalled' => true,
|
||||
'version' => $manifest['version'],
|
||||
'fileList' => $fileList,
|
||||
'description' => $manifest['description'],
|
||||
];
|
||||
|
||||
if (!empty($manifest['checkVersionUrl'])) {
|
||||
$data['checkVersionUrl'] = $manifest['checkVersionUrl'];
|
||||
}
|
||||
|
||||
$extensionEntity->set($data);
|
||||
|
||||
try {
|
||||
$entityManager->saveEntity($extensionEntity);
|
||||
} catch (Throwable $e) {
|
||||
$msg = "Error while saving the extension entity. The error occurred in an existing hook. " .
|
||||
"{$e->getMessage()} at {$e->getFile()}:{$e->getLine()}";
|
||||
|
||||
$this->getLog()->error($msg);
|
||||
$this->throwErrorAndRemovePackage('Error saving extension entity. Check logs for details.', false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare version between installed and a new extensions.
|
||||
*
|
||||
* @throws Error
|
||||
*/
|
||||
private function compareVersion(): void
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
if (!$extensionEntity) {
|
||||
return;
|
||||
}
|
||||
|
||||
$comparedVersion = version_compare($manifest['version'], $extensionEntity->getVersion(), '>=');
|
||||
|
||||
if ($comparedVersion <= 0) {
|
||||
$this->throwErrorAndRemovePackage('You cannot install an older version of this extension.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If extension already installed, uninstall an old version.
|
||||
*
|
||||
* @throws Error
|
||||
*/
|
||||
private function uninstallExtension(): void
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
if (!$extensionEntity) {
|
||||
throw new Error("Can't uninstall not existing extension.");
|
||||
}
|
||||
|
||||
$this->executeAction(Base::UNINSTALL, [
|
||||
'id' => $extensionEntity->get(Attribute::ID),
|
||||
'skipSystemRebuild' => true,
|
||||
'skipAfterScript' => true,
|
||||
'parentProcessId' => $this->getProcessId(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete extension package.
|
||||
*
|
||||
* @throws Error
|
||||
*/
|
||||
private function deleteExtension(): void
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
if (!$extensionEntity) {
|
||||
throw new Error("Can't delete not existing extension.");
|
||||
}
|
||||
|
||||
$this->executeAction(Base::DELETE, [
|
||||
'id' => $extensionEntity->get(Attribute::ID),
|
||||
'parentProcessId' => $this->getProcessId(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string[]|string> $dependencyList
|
||||
* @throws Error
|
||||
*/
|
||||
protected function checkDependencies(array $dependencyList): bool
|
||||
{
|
||||
return $this->getHelper()->checkDependencies($dependencyList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Extension;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
use Espo\Entities\Extension;
|
||||
use Throwable;
|
||||
|
||||
class Uninstall extends \Espo\Core\Upgrades\Actions\Base\Uninstall
|
||||
{
|
||||
protected ?Extension $extensionEntity = null;
|
||||
|
||||
/**
|
||||
* Get entity of this extension.
|
||||
*
|
||||
* @return Extension
|
||||
* @throws Error
|
||||
*/
|
||||
protected function getExtensionEntity()
|
||||
{
|
||||
if (!isset($this->extensionEntity)) {
|
||||
$processId = $this->getProcessId();
|
||||
|
||||
$this->extensionEntity = $this->getEntityManager()->getEntityById(Extension::ENTITY_TYPE, $processId);
|
||||
|
||||
if (!$this->extensionEntity) {
|
||||
throw new Error('Extension entity not found.');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->extensionEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
protected function afterRunAction(): void
|
||||
{
|
||||
/** Set extension entity, isInstalled = false */
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
$extensionEntity->set('isInstalled', false);
|
||||
|
||||
try {
|
||||
$this->getEntityManager()->saveEntity($extensionEntity);
|
||||
} catch (Throwable $e) {
|
||||
$this->getLog()->error(
|
||||
'Error saving Extension entity. The error occurred by existing Hook, more details: ' .
|
||||
$e->getMessage() .' at '. $e->getFile() . ':' . $e->getLine()
|
||||
);
|
||||
|
||||
$this->throwErrorAndRemovePackage('Error saving Extension entity. Check logs for details.', false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
* @throws Error
|
||||
*/
|
||||
protected function getRestoreFileList(): array
|
||||
{
|
||||
if (!isset($this->data['restoreFileList'])) {
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
$this->data['restoreFileList'] = $extensionEntity->get('fileList');
|
||||
}
|
||||
|
||||
return $this->data['restoreFileList'] ?? [];
|
||||
}
|
||||
}
|
||||
46
application/Espo/Core/Upgrades/Actions/Extension/Upload.php
Normal file
46
application/Espo/Core/Upgrades/Actions/Extension/Upload.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Extension;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class Upload extends \Espo\Core\Upgrades\Actions\Base\Upload
|
||||
{
|
||||
/**
|
||||
* Check dependencies.
|
||||
*
|
||||
* @param array<string, string[]|string> $dependencyList
|
||||
* @throws Error
|
||||
*/
|
||||
protected function checkDependencies($dependencyList): bool
|
||||
{
|
||||
return $this->getHelper()->checkDependencies($dependencyList);
|
||||
}
|
||||
}
|
||||
96
application/Espo/Core/Upgrades/Actions/Helper.php
Normal file
96
application/Espo/Core/Upgrades/Actions/Helper.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Entities\Extension;
|
||||
use Espo\ORM\EntityManager;
|
||||
use RuntimeException;
|
||||
|
||||
class Helper
|
||||
{
|
||||
private ?Base $actionObject = null;
|
||||
|
||||
public function __construct(private EntityManager $entityManager)
|
||||
{}
|
||||
|
||||
public function setActionObject(Base $actionObject): void
|
||||
{
|
||||
$this->actionObject = $actionObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check dependencies.
|
||||
*
|
||||
* @param array<string, string[]|string> $dependencyList
|
||||
* @throws Error
|
||||
*/
|
||||
public function checkDependencies(mixed $dependencyList): bool
|
||||
{
|
||||
if (!$this->actionObject) {
|
||||
throw new RuntimeException("No action passed.");
|
||||
}
|
||||
|
||||
if (!is_array($dependencyList)) {
|
||||
$dependencyList = (array) $dependencyList;
|
||||
}
|
||||
|
||||
/** @var array<string, string[]|string> $dependencyList */
|
||||
|
||||
foreach ($dependencyList as $extensionName => $extensionVersion) {
|
||||
$entity = $this->entityManager
|
||||
->getRDBRepositoryByClass(Extension::class)
|
||||
->where([
|
||||
'name' => trim($extensionName),
|
||||
'isInstalled' => true,
|
||||
])
|
||||
->findOne();
|
||||
|
||||
$versionString = is_array($extensionVersion) ?
|
||||
implode(', ', $extensionVersion) :
|
||||
$extensionVersion;
|
||||
|
||||
$errorMessage = "Dependency error: Extension '$extensionName' with version '$versionString' is missing.";
|
||||
|
||||
if (
|
||||
!$entity ||
|
||||
!$this->actionObject->checkVersions(
|
||||
$extensionVersion,
|
||||
$entity->getVersion(),
|
||||
$errorMessage
|
||||
)
|
||||
) {
|
||||
throw new Error($errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
44
application/Espo/Core/Upgrades/Actions/Upgrade/Delete.php
Normal file
44
application/Espo/Core/Upgrades/Actions/Upgrade/Delete.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Upgrade;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class Delete extends \Espo\Core\Upgrades\Actions\Base\Delete
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(mixed $data): mixed
|
||||
{
|
||||
throw new Error('The operation is not permitted.');
|
||||
}
|
||||
}
|
||||
139
application/Espo/Core/Upgrades/Actions/Upgrade/Install.php
Normal file
139
application/Espo/Core/Upgrades/Actions/Upgrade/Install.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Upgrade;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Upgrades\Migration\Script;
|
||||
use Espo\Core\Upgrades\Migration\VersionUtil;
|
||||
use RuntimeException;
|
||||
|
||||
class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepBeforeUpgradeScript(array $data): void
|
||||
{
|
||||
$this->stepBeforeInstallScript($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function stepAfterUpgradeScript(array $data): void
|
||||
{
|
||||
$this->stepAfterInstallScript($data);
|
||||
$this->runMigrationAfterInstallScript();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
protected function finalize(): void
|
||||
{
|
||||
$configWriter = $this->createConfigWriter();
|
||||
$configWriter->set('version', $this->getTargetVersion());
|
||||
$configWriter->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete temporary package files.
|
||||
*
|
||||
* @throws Error
|
||||
*/
|
||||
protected function deletePackageFiles(): bool
|
||||
{
|
||||
$res = parent::deletePackageFiles();
|
||||
$res &= $this->deletePackageArchive();
|
||||
|
||||
return (bool) $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
private function getTargetVersion(): string
|
||||
{
|
||||
$version = $this->getManifest()['version'];
|
||||
|
||||
if (!$version) {
|
||||
throw new RuntimeException("No 'version' in manifest.");
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
private function runMigrationAfterInstallScript(): void
|
||||
{
|
||||
$targetVersion = $this->getTargetVersion();
|
||||
$version = $this->getConfig()->get('version');
|
||||
|
||||
if (!$version || !is_string($version)) {
|
||||
throw new RuntimeException("No or bad 'version' in config.");
|
||||
}
|
||||
|
||||
$script = $this->getMigrationAfterInstallScript($version, $targetVersion);
|
||||
|
||||
if (!$script) {
|
||||
return;
|
||||
}
|
||||
|
||||
$script->run();
|
||||
}
|
||||
|
||||
private function getMigrationAfterInstallScript(string $version, string $targetVersion): ?Script
|
||||
{
|
||||
$isPatch = VersionUtil::isPatch($version, $targetVersion);
|
||||
$a = VersionUtil::split($targetVersion);
|
||||
|
||||
$dir = $isPatch ?
|
||||
'V' . $a[0] . '_' . $a[1] . '_' . $a[2] :
|
||||
'V' . $a[0] . '_' . $a[1];
|
||||
|
||||
$className = "Espo\\Core\\Upgrades\\Migrations\\$dir\\AfterUpgrade";
|
||||
|
||||
if (!class_exists($className)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$script = $this->getInjectableFactory()->createWith($className, ['isUpgrade' => true]);
|
||||
|
||||
if (!$script instanceof Script) {
|
||||
throw new RuntimeException("$className does not implement Script interface.");
|
||||
}
|
||||
|
||||
return $script;
|
||||
}
|
||||
}
|
||||
44
application/Espo/Core/Upgrades/Actions/Upgrade/Uninstall.php
Normal file
44
application/Espo/Core/Upgrades/Actions/Upgrade/Uninstall.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Upgrade;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class Uninstall extends \Espo\Core\Upgrades\Actions\Base\Uninstall
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(mixed $data): mixed
|
||||
{
|
||||
throw new Error('The operation is not permitted.');
|
||||
}
|
||||
}
|
||||
34
application/Espo/Core/Upgrades/Actions/Upgrade/Upload.php
Normal file
34
application/Espo/Core/Upgrades/Actions/Upgrade/Upload.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Upgrade;
|
||||
|
||||
class Upload extends \Espo\Core\Upgrades\Actions\Base\Upload
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user