diff --git a/application/Espo/Core/Upgrades/Actions/Base.php b/application/Espo/Core/Upgrades/Actions/Base.php index 97bc322a21..0e9f5ea9e9 100644 --- a/application/Espo/Core/Upgrades/Actions/Base.php +++ b/application/Espo/Core/Upgrades/Actions/Base.php @@ -311,6 +311,17 @@ abstract class Base return $this->getPath('packagePath', $isPackage); } + protected function getDeleteList($type = 'delete') + { + $manifest = $this->getManifest(); + + if (isset($manifest[$type])) { + return $manifest[$type]; + } + + return array(); + } + /** * Get a list of files defined in manifest.json * @@ -318,13 +329,26 @@ abstract class Base */ protected function getDeleteFileList() { - $manifest = $this->getManifest(); + if (!isset($this->data['deleteFileList'])) { + $deleteFileList = array(); - if (!empty($manifest['delete'])) { - return $manifest['delete']; + $deleteList = array_merge($this->getDeleteList('delete'), $this->getDeleteList('deleteBeforeCopy')); + foreach ($deleteList as $key => $itemPath) { + if (is_dir($itemPath)) { + $fileList = $this->getFileManager()->getFileList($itemPath, true, '', true, true); + $fileList = $this->concatStringWithArray($itemPath, $fileList); + $deleteFileList = array_merge($deleteFileList, $fileList); + + continue; + } + + $deleteFileList[] = $itemPath; + } + + $this->data['deleteFileList'] = $deleteFileList; } - return array(); + return $this->data['deleteFileList']; } /** @@ -334,17 +358,28 @@ abstract class Base */ protected function deleteFiles($withEmptyDirs = false) { - $deleteFileList = $this->getDeleteFileList(); + $deleteList = $this->getDeleteList('delete'); - //remove directories, leave only files - foreach ($deleteFileList as $key => $filePath) { - if (!is_file($filePath)) { - unset($deleteFileList[$key]); - } + if (!empty($deleteList)) { + return $this->getFileManager()->remove($deleteList, null, $withEmptyDirs); } - if (!empty($deleteFileList)) { - return $this->getFileManager()->remove($deleteFileList, null, $withEmptyDirs); + 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; @@ -571,4 +606,16 @@ abstract class Base return $this->helper; } + + protected function concatStringWithArray($string, array $array) + { + foreach ($array as &$value) { + if (substr($string, -1) != '/') { + $string .= '/'; + } + $value = $string . $value; + } + + return $array; + } } \ No newline at end of file diff --git a/application/Espo/Core/Upgrades/Actions/Base/Install.php b/application/Espo/Core/Upgrades/Actions/Base/Install.php index 99d1a145a3..54e2f75675 100644 --- a/application/Espo/Core/Upgrades/Actions/Base/Install.php +++ b/application/Espo/Core/Upgrades/Actions/Base/Install.php @@ -70,6 +70,9 @@ class Install extends \Espo\Core\Upgrades\Actions\Base /* run before install script */ $this->runScript('before'); + /* remove files defined in a manifest "deleteBeforeCopy" */ + $this->deleteBeforeCopy(true); + /* copy files from directory "Files" to EspoCRM files */ if (!$this->copyFiles()) { $this->throwErrorAndRemovePackage('Cannot copy files.'); diff --git a/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php b/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php index 7580ff3fcc..0518d27ab3 100644 --- a/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php +++ b/application/Espo/Core/Upgrades/Actions/Base/Uninstall.php @@ -179,13 +179,15 @@ class Uninstall extends \Espo\Core\Upgrades\Actions\Base return $this->data['restoreFileList']; } - protected function getDeleteFileList() + protected function getDeleteList($type = 'delete') { - $packageFileList = $this->getRestoreFileList(); - $backupFileList = $this->getCopyFileList(); + if ($type == 'delete') { + $packageFileList = $this->getRestoreFileList(); + $backupFileList = $this->getCopyFileList(); - $deleteFileList = array_diff($packageFileList, $backupFileList); + return array_diff($packageFileList, $backupFileList); + } - return $deleteFileList; + return array(); } } diff --git a/application/Espo/Core/Upgrades/Actions/Upgrade/Delete.php b/application/Espo/Core/Upgrades/Actions/Upgrade/Delete.php new file mode 100644 index 0000000000..8165a6755c --- /dev/null +++ b/application/Espo/Core/Upgrades/Actions/Upgrade/Delete.php @@ -0,0 +1,40 @@ +