diff --git a/application/Espo/Core/Upgrades/Actions/Base.php b/application/Espo/Core/Upgrades/Actions/Base.php index f37fda6a4a..076035fc1f 100644 --- a/application/Espo/Core/Upgrades/Actions/Base.php +++ b/application/Espo/Core/Upgrades/Actions/Base.php @@ -34,6 +34,8 @@ abstract class Base private $entityManager; + private $helper; + protected $data; protected $params = null; @@ -131,7 +133,7 @@ abstract class Base return $this->config; } - protected function getEntityManager() + public function getEntityManager() { if (!isset($this->entityManager)) { $this->entityManager = $this->getContainer()->get('entityManager'); @@ -195,10 +197,15 @@ abstract class Base $res &= $this->checkVersions($manifest['acceptableVersions'], $this->getConfig()->get('version'), 'Your EspoCRM version doesn\'t match for this installation package.'); } + //check dependencies + if (!empty($manifest['dependencies'])) { + $res &= $this->checkDependencies($manifest['dependencies']); + } + return (bool) $res; } - protected function checkVersions($versionList, $currentVersion, $errorMessage = '') + public function checkVersions($versionList, $currentVersion, $errorMessage = '') { if (empty($versionList)) { return true; @@ -212,7 +219,7 @@ abstract class Base $semver = new SemVer\version($currentVersion); } catch (\Exception $e) { $GLOBALS['log']->error('Cannot recognize currentVersion ['.$currentVersion.'], error: '.$e->getMessage().'.'); - return; + return false; } foreach ($versionList as $version) { @@ -251,6 +258,11 @@ abstract class Base return true; } + protected function checkDependencies($dependencyList) + { + return true; + } + /** * Run scripts by type * @param string $type Ex. "before", "after" @@ -550,4 +562,15 @@ abstract class Base $backupPath = $this->getPath('backupPath'); return $this->copy('', array($backupPath, self::FILES), false, $fullFileList); } + + protected function getHelper() + { + if (!isset($this->helper)) { + $this->helper = new Helper(); + } + + $this->helper->setActionObject($this); + + return $this->helper; + } } \ No newline at end of file diff --git a/application/Espo/Core/Upgrades/Actions/Extension/Install.php b/application/Espo/Core/Upgrades/Actions/Extension/Install.php index efc397fafb..9e7dcd2ad7 100644 --- a/application/Espo/Core/Upgrades/Actions/Extension/Install.php +++ b/application/Espo/Core/Upgrades/Actions/Extension/Install.php @@ -138,7 +138,7 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install $data = array( 'id' => $this->getProcessId(), - 'name' => $manifest['name'], + 'name' => trim($manifest['name']), 'isInstalled' => true, 'version' => $manifest['version'], 'fileList' => $fileList, @@ -171,8 +171,8 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install * Throw an exception and remove package files. * Redeclared to prevent of deleting a package of installed extension. * - * @param string $errorMessage [description] - * @return [type] [description] + * @param string $errorMessage + * @return void */ protected function throwErrorAndRemovePackage($errorMessage = '') { @@ -211,7 +211,8 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install $this->executeAction(ExtensionManager::DELETE, array('id' => $extensionEntity->get('id'))); } - - - + protected function checkDependencies($dependencyList) + { + return $this->getHelper()->checkDependencies($dependencyList); + } } diff --git a/application/Espo/Core/Upgrades/Actions/Extension/Upload.php b/application/Espo/Core/Upgrades/Actions/Extension/Upload.php index 9eea1c4d0b..b1254b5215 100644 --- a/application/Espo/Core/Upgrades/Actions/Extension/Upload.php +++ b/application/Espo/Core/Upgrades/Actions/Extension/Upload.php @@ -24,5 +24,8 @@ namespace Espo\Core\Upgrades\Actions\Extension; class Upload extends \Espo\Core\Upgrades\Actions\Base\Upload { - + protected function checkDependencies($dependencyList) + { + return $this->getHelper()->checkDependencies($dependencyList); + } } \ No newline at end of file diff --git a/application/Espo/Core/Upgrades/Actions/Helper.php b/application/Espo/Core/Upgrades/Actions/Helper.php new file mode 100644 index 0000000000..0853f5b642 --- /dev/null +++ b/application/Espo/Core/Upgrades/Actions/Helper.php @@ -0,0 +1,77 @@ +setActionObject($actionObject); + } + } + + public function setActionObject(\Espo\Core\Upgrades\Actions\Base $actionObject) + { + $this->actionObject = $actionObject; + } + + protected function getActionObject() + { + return $this->actionObject; + } + + /** + * Check dependencies + * + * @param array | string $dependencyList + * + * @return bool + */ + public function checkDependencies($dependencyList) + { + if (!is_array($dependencyList)) { + $dependencyList = (array) $dependencyList; + } + + $actionObject = $this->getActionObject(); + + foreach ($dependencyList as $extensionName => $extensionVersion) { + $dependencyExtensionEntity = $actionObject->getEntityManager()->getRepository('Extension')->where(array( + 'name' => trim($extensionName), + 'isInstalled' => true, + ))->findOne(); + + $errorMessage = 'Dependency Error: The extension "'.$extensionName.'" with version "'.$extensionVersion.'" is missing.'; + if (!isset($dependencyExtensionEntity) || !$actionObject->checkVersions($extensionVersion, $dependencyExtensionEntity->get('version'), $errorMessage)) { + throw new Error($errorMessage); + } + } + + return true; + } +}