diff --git a/application/Espo/Core/ExtensionManager.php b/application/Espo/Core/ExtensionManager.php index 2183e0105c..10dbd0e989 100644 --- a/application/Espo/Core/ExtensionManager.php +++ b/application/Espo/Core/ExtensionManager.php @@ -47,6 +47,7 @@ class ExtensionManager extends Upgrades\Base 'customDirNames' => array( 'before' => 'beforeInstallFiles', 'after' => 'afterInstallFiles', + 'deleteAndCopy' => 'vendorFiles', ) ); } diff --git a/application/Espo/Core/UpgradeManager.php b/application/Espo/Core/UpgradeManager.php index 1c024ed3af..758e92d8f9 100644 --- a/application/Espo/Core/UpgradeManager.php +++ b/application/Espo/Core/UpgradeManager.php @@ -47,6 +47,7 @@ class UpgradeManager extends Upgrades\Base 'customDirNames' => array( 'before' => 'beforeUpgradeFiles', 'after' => 'afterUpgradeFiles', + 'deleteAndCopy' => 'vendorFiles', ) ); } \ No newline at end of file diff --git a/application/Espo/Core/Upgrades/Actions/Base.php b/application/Espo/Core/Upgrades/Actions/Base.php index 8b3333eb27..63a681a145 100644 --- a/application/Espo/Core/Upgrades/Actions/Base.php +++ b/application/Espo/Core/Upgrades/Actions/Base.php @@ -28,6 +28,7 @@ ************************************************************************/ namespace Espo\Core\Upgrades\Actions; + use Espo\Core\Utils\Util; use Espo\Core\Utils\System; use Espo\Core\Utils\Json; @@ -83,7 +84,6 @@ abstract class Base */ protected $defaultPackageType = 'extension'; - public function __construct(\Espo\Core\Container $container, \Espo\Core\Upgrades\ActionManager $actionManager) { $this->container = $container; @@ -315,8 +315,32 @@ abstract class Base { $manifest = $this->getManifest(); - if (isset($manifest[$type])) { - return $manifest[$type]; + switch ($type) { + case 'delete': + case 'deleteBeforeCopy': + if (isset($manifest[$type])) { + return $manifest[$type]; + } + break; + + case 'deleteAndCopy': /*Get directory/file list on a 2nd level. E.g. venor/zendframework*/ + $packagePath = $this->getPackagePath(); + $dirNames = $this->getParams('customDirNames'); + $filesPath = Util::concatPath($packagePath, $dirNames['deleteAndCopy']); + + if (file_exists($filesPath)) { + $list = []; + $dirList = $this->getFileManager()->getFileList($filesPath, false, '', null, true); + foreach ($dirList as $dirName) { + $dirPath = Util::concatPath($filesPath, $dirName); + $subDirList = $this->getFileManager()->getFileList($dirPath, false, '', null, true); + foreach ($subDirList as $subDirItem) { + $list[] = Util::concatPath($dirName, $subDirItem); + } + } + return $list; + } + break; } return array(); @@ -332,7 +356,7 @@ abstract class Base if (!isset($this->data['deleteFileList'])) { $deleteFileList = array(); - $deleteList = array_merge($this->getDeleteList('delete'), $this->getDeleteList('deleteBeforeCopy')); + $deleteList = array_merge($this->getDeleteList('delete'), $this->getDeleteList('deleteBeforeCopy'), $this->getDeleteList('deleteAndCopy')); foreach ($deleteList as $key => $itemPath) { if (is_dir($itemPath)) { $fileList = $this->getFileManager()->getFileList($itemPath, true, '', true, true); @@ -356,9 +380,9 @@ abstract class Base * * @return boolen */ - protected function deleteFiles($withEmptyDirs = false) + protected function deleteFiles($type = 'delete', $withEmptyDirs = false) { - $deleteList = $this->getDeleteList('delete'); + $deleteList = $this->getDeleteList($type); if (!empty($deleteList)) { return $this->getFileManager()->remove($deleteList, null, $withEmptyDirs); @@ -367,24 +391,6 @@ abstract class Base return true; } - /** - * Deleted file/forder list before coppy the upgrade files - * - * @param boolean $withEmptyDirs - * - * @return boolean - */ - protected function deleteBeforeCopy($withEmptyDirs = false) - { - $deleteList = $this->getDeleteList('deleteBeforeCopy'); - - if (!empty($deleteList)) { - $this->getFileManager()->remove($deleteList, null, $withEmptyDirs); - } - - return true; - } - protected function getCopyFileList() { if (!isset($this->data['fileList'])) { @@ -406,7 +412,7 @@ abstract class Base } /** - * Get file directories (files, beforeInstallFiles, afterInstallFiles) + * Get file directories (files, beforeInstallFiles, afterInstallFiles, deleteAndCopy) * * @param sting $parentDirPath * @@ -415,7 +421,7 @@ abstract class Base protected function getFileDirs($parentDirPath = null) { $dirNames = $this->getParams('customDirNames'); - $paths = array(self::FILES, $dirNames['before'], $dirNames['after']); + $paths = array(self::FILES, $dirNames['before'], $dirNames['after'], $dirNames['deleteAndCopy']); if (isset($parentDirPath)) { foreach ($paths as &$path) { @@ -466,11 +472,12 @@ abstract class Base * * @return boolean */ - protected function copyFiles($type = null) + protected function copyFiles($type = null, $dest = '') { switch ($type) { case 'before': case 'after': + case 'deleteAndCopy': $dirNames = $this->getParams('customDirNames'); $dirPath = $dirNames[$type]; break; @@ -484,7 +491,7 @@ abstract class Base $filesPath = Util::concatPath($packagePath, $dirPath); if (file_exists($filesPath)) { - return $this->copy($filesPath, '', true); + return $this->copy($filesPath, $dest, true); } return true; @@ -515,6 +522,11 @@ abstract class Base return $this->data['manifest']; } + protected function setManifest() + { + + } + /** * Check if the manifest is correct * diff --git a/application/Espo/Core/Upgrades/Actions/Base/Install.php b/application/Espo/Core/Upgrades/Actions/Base/Install.php index 31baf204d7..276915f18b 100644 --- a/application/Espo/Core/Upgrades/Actions/Base/Install.php +++ b/application/Espo/Core/Upgrades/Actions/Base/Install.php @@ -76,7 +76,7 @@ class Install extends \Espo\Core\Upgrades\Actions\Base $this->runScript('before'); /* remove files defined in a manifest "deleteBeforeCopy" */ - $this->deleteBeforeCopy(true); + $this->deleteFiles('deleteBeforeCopy', true); /* copy files from directory "Files" to EspoCRM files */ if (!$this->copyFiles()) { @@ -84,7 +84,10 @@ class Install extends \Espo\Core\Upgrades\Actions\Base } /* remove files defined in a manifest */ - $this->deleteFiles(true); + $this->deleteFiles('delete', true); + + $this->deleteFiles('deleteAndCopy'); + $this->copyFiles('deleteAndCopy'); if (!$this->systemRebuild()) { $this->throwErrorAndRemovePackage('Error occurred while EspoCRM rebuild.'); diff --git a/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php b/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php index f24628d88c..f1d49a2125 100644 --- a/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php +++ b/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php @@ -66,7 +66,7 @@ class Uninstall extends \Espo\Core\Upgrades\Actions\Base } /* remove extension files, saved in fileList */ - if (!$this->deleteFiles(true)) { + if (!$this->deleteFiles('delete', true)) { $this->throwErrorAndRemovePackage('Permission denied to delete files.'); } } @@ -119,10 +119,10 @@ class Uninstall extends \Espo\Core\Upgrades\Actions\Base return $res; } - protected function copyFiles($type = null) + protected function copyFiles($type = null, $dest = '') { $backupPath = $this->getPath('backupPath'); - $res = $this->copy(array($backupPath, self::FILES), '', true); + $res = $this->copy(array($backupPath, self::FILES), $dest, true); return $res; }