Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend

This commit is contained in:
yuri
2015-03-19 17:11:43 +02:00
4 changed files with 114 additions and 10 deletions
@@ -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;
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -0,0 +1,77 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: http://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
namespace Espo\Core\Upgrades\Actions;
use Espo\Core\Exceptions\Error;
class Helper
{
private $actionObject;
public function __construct($actionObject = null)
{
if (isset($actionObject)) {
$this->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;
}
}