Cleanup: remove old backup files after upgrade
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user