diff --git a/application/Espo/Jobs/Cleanup.php b/application/Espo/Jobs/Cleanup.php index f183a25e2e..1a96ff027d 100644 --- a/application/Espo/Jobs/Cleanup.php +++ b/application/Espo/Jobs/Cleanup.php @@ -49,6 +49,8 @@ class Cleanup extends \Espo\Core\Jobs\Base protected $cleanupRemindersPeriod = '15 days'; + protected $cleanupBackupPeriod = '2 month'; + public function run() { $this->cleanupJobs(); @@ -59,6 +61,7 @@ class Cleanup extends \Espo\Core\Jobs\Base $this->cleanupNotifications(); $this->cleanupActionHistory(); $this->cleanupAuthToken(); + $this->cleanupUpgradeBackups(); } protected function cleanupJobs() @@ -310,5 +313,25 @@ class Cleanup extends \Espo\Core\Jobs\Base $this->getEntityManager()->getRepository('Notification')->deleteFromDb($id); } } + + protected function cleanupUpgradeBackups() + { + $path = 'data/.backup/upgrades'; + $datetime = new \DateTime('-' . $this->cleanupBackupPeriod); + + if (file_exists($path)) { + $fileManager = $this->getContainer()->get('fileManager'); + $fileList = $fileManager->getFileList($path, false, '', false); + + foreach ($fileList as $dirName) { + $dirPath = $path . '/' . $dirName; + + $info = new \SplFileInfo($dirPath); + if ($datetime->getTimestamp() > $info->getMTime()) { + $fileManager->removeInDir($dirPath, true); + } + } + } + } }