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

This commit is contained in:
yuri
2017-06-23 15:47:24 +03:00
7 changed files with 105 additions and 27 deletions
+4 -8
View File
@@ -283,24 +283,20 @@ class CronManager
}
try {
$previousDate = $cronExpression->getPreviousRunDate()->format('Y-m-d H:i:s');
$nextDate = $cronExpression->getNextRunDate()->format('Y-m-d H:i:s');
} catch (\Exception $e) {
$GLOBALS['log']->error('CronManager (ScheduledJob ['.$scheduledJob['id'].']): Unsupported CRON expression ['.$scheduling.']');
continue;
}
if ($cronExpression->isDue()) {
$previousDate = date('Y-m-d H:i:s');
}
$existingJob = $this->getCronJob()->getJobByScheduledJob($scheduledJob['id'], $previousDate);
$existingJob = $this->getCronJob()->getJobByScheduledJob($scheduledJob['id'], $nextDate);
if ($existingJob) continue;
$className = $this->getScheduledJobUtil()->get($scheduledJob['job']);
if ($className) {
if (method_exists($className, 'prepare')) {
$implementation = new $className($this->container);
$implementation->prepare($scheduledJob, $previousDate);
$implementation->prepare($scheduledJob, $nextDate);
continue;
}
}
@@ -314,7 +310,7 @@ class CronManager
'name' => $scheduledJob['name'],
'status' => self::PENDING,
'scheduledJobId' => $scheduledJob['id'],
'executeTime' => $previousDate,
'executeTime' => $nextDate,
'method' => $scheduledJob['job']
));
$this->getEntityManager()->saveEntity($jobEntity);
@@ -42,6 +42,11 @@ class ExtensionManager extends Upgrades\Base
'after' => 'AfterInstall',
'beforeUninstall' => 'BeforeUninstall',
'afterUninstall' => 'AfterUninstall',
),
'customDirNames' => array(
'before' => 'beforeInstallFiles',
'after' => 'afterInstallFiles',
)
);
}
+5
View File
@@ -42,6 +42,11 @@ class UpgradeManager extends Upgrades\Base
'scriptNames' => array(
'before' => 'BeforeUpgrade',
'after' => 'AfterUpgrade',
),
'customDirNames' => array(
'before' => 'beforeUpgradeFiles',
'after' => 'afterUpgradeFiles',
)
);
}
+67 -11
View File
@@ -389,9 +389,7 @@ abstract class Base
{
if (!isset($this->data['fileList'])) {
$packagePath = $this->getPackagePath();
$filesPath = Util::concatPath($packagePath, self::FILES);
$this->data['fileList'] = $this->getFileManager()->getFileList($filesPath, true, '', true, true);
$this->data['fileList'] = $this->getFileList($packagePath);
}
return $this->data['fileList'];
@@ -401,14 +399,55 @@ abstract class Base
{
if (!isset($this->data['restoreFileList'])) {
$backupPath = $this->getPath('backupPath');
$backupFilePath = Util::concatPath($backupPath, self::FILES);
$this->data['restoreFileList'] = $this->getFileManager()->getFileList($backupFilePath, true, '', true, true);
$this->data['restoreFileList'] = $this->getFileList($backupPath);
}
return $this->data['restoreFileList'];
}
/**
* Get file directories (files, beforeInstallFiles, afterInstallFiles)
*
* @param sting $parentDirPath
*
* @return array
*/
protected function getFileDirs($parentDirPath = null)
{
$dirNames = $this->getParams('customDirNames');
$paths = array(self::FILES, $dirNames['before'], $dirNames['after']);
if (isset($parentDirPath)) {
foreach ($paths as &$path) {
$path = Util::concatPath($parentDirPath, $path);
}
}
return $paths;
}
/**
* Get file list from directories: files, beforeUpgradeFiles, afterUpgradeFiles
*
* @param string $dirPath
*
* @return array
*/
protected function getFileList($dirPath)
{
$fileList = array();
$paths = $this->getFileDirs($dirPath);
foreach ($paths as $filesPath) {
if (file_exists($filesPath)) {
$files = $this->getFileManager()->getFileList($filesPath, true, '', true, true);
$fileList = array_merge($fileList, $files);
}
}
return $fileList;
}
protected function copy($sourcePath, $destPath, $recursively = false, array $fileList = null, $copyOnlyFiles = false)
{
try {
@@ -423,15 +462,32 @@ abstract class Base
/**
* Copy files from upgrade/extension package
*
* @param string $processId
* @param string $type
*
* @return boolean
*/
protected function copyFiles()
protected function copyFiles($type = null)
{
$packagePath = $this->getPackagePath();
$filesPath = Util::concatPath($packagePath, self::FILES);
switch ($type) {
case 'before':
case 'after':
$dirNames = $this->getParams('customDirNames');
$dirPath = $dirNames[$type];
break;
return $this->copy($filesPath, '', true);
default:
$dirPath = self::FILES;
break;
}
$packagePath = $this->getPackagePath();
$filesPath = Util::concatPath($packagePath, $dirPath);
if (file_exists($filesPath)) {
return $this->copy($filesPath, '', true);
}
return true;
}
public function getManifest()
@@ -67,6 +67,11 @@ class Install extends \Espo\Core\Upgrades\Actions\Base
$this->backupExistingFiles();
//beforeInstallFiles
if (!$this->copyFiles('before')) {
$this->throwErrorAndRemovePackage('Cannot copy beforeInstall files.');
}
/* run before install script */
$this->runScript('before');
@@ -85,6 +90,11 @@ class Install extends \Espo\Core\Upgrades\Actions\Base
$this->throwErrorAndRemovePackage('Error occurred while EspoCRM rebuild.');
}
//afterInstallFiles
if (!$this->copyFiles('after')) {
$this->throwErrorAndRemovePackage('Cannot copy afterInstall files.');
}
/* run before install script */
$this->runScript('after');
@@ -112,7 +122,9 @@ class Install extends \Espo\Core\Upgrades\Actions\Base
$deleteFileList = array_diff($copyFileList, $backupFileList);
$res = $this->copy($backupFilePath, '', true);
$res &= $this->getFileManager()->remove($deleteFileList, null, true);
if (!empty($deleteFileList)) {
$res &= $this->getFileManager()->remove($deleteFileList, null, true);
}
if ($res) {
$this->getFileManager()->removeInDir($backupPath, true);
@@ -95,15 +95,20 @@ class Uninstall extends \Espo\Core\Upgrades\Actions\Base
protected function restoreFiles()
{
$packagePath = $this->getPath('packagePath');
$filesPath = Util::concatPath($packagePath, self::FILES);
if (!file_exists($filesPath)) {
$manifestPath = Util::concatPath($packagePath, $this->manifestName);
if (!file_exists($manifestPath)) {
$this->unzipArchive($packagePath);
}
$res = $this->copy($filesPath, '', true);
$fileDirs = $this->getFileDirs($packagePath);
foreach ($fileDirs as $filesPath) {
if (file_exists($filesPath)) {
$res = $this->copy($filesPath, '', true);
}
}
$manifestJson = $this->getFileManager()->getContents(array($packagePath, $this->manifestName));
$manifestJson = $this->getFileManager()->getContents($manifestPath);
$manifest = Json::decode($manifestJson, true);
if (!empty($manifest['delete'])) {
$res &= $this->getFileManager()->remove($manifest['delete'], null, true);
@@ -114,7 +119,7 @@ class Uninstall extends \Espo\Core\Upgrades\Actions\Base
return $res;
}
protected function copyFiles()
protected function copyFiles($type = null)
{
$backupPath = $this->getPath('backupPath');
$res = $this->copy(array($backupPath, self::FILES), '', true);
@@ -63,9 +63,8 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install
/** copy scripts files */
$packagePath = $this->getPackagePath();
$res &= $this->copy(array($packagePath, self::SCRIPTS), array($backupPath, self::SCRIPTS), true);
return $res;
return $this->copy(array($packagePath, self::SCRIPTS), array($backupPath, self::SCRIPTS), true);
}
protected function isNew()