Cleanup: remove old backup files after upgrade

This commit is contained in:
Taras Machyshyn
2017-10-30 12:40:11 +02:00
parent 54a35674bc
commit 92e61db752
+23
View File
@@ -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);
}
}
}
}
}