@@ -32,61 +32,61 @@ |
||
32 | 32 | use Psr\Log\LoggerInterface; |
33 | 33 | |
34 | 34 | class BackgroundCleanupUpdaterBackupsJob extends QueuedJob { |
35 | - protected IConfig $config; |
|
36 | - protected LoggerInterface $log; |
|
35 | + protected IConfig $config; |
|
36 | + protected LoggerInterface $log; |
|
37 | 37 | |
38 | - public function __construct(IConfig $config, LoggerInterface $log, ITimeFactory $time) { |
|
39 | - parent::__construct($time); |
|
40 | - $this->config = $config; |
|
41 | - $this->log = $log; |
|
42 | - } |
|
38 | + public function __construct(IConfig $config, LoggerInterface $log, ITimeFactory $time) { |
|
39 | + parent::__construct($time); |
|
40 | + $this->config = $config; |
|
41 | + $this->log = $log; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * This job cleans up all backups except the latest 3 from the updaters backup directory |
|
46 | - */ |
|
47 | - public function run($arguments) { |
|
48 | - $updateDir = $this->config->getSystemValue('updatedirectory', null) ?? $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
49 | - $instanceId = $this->config->getSystemValue('instanceid', null); |
|
44 | + /** |
|
45 | + * This job cleans up all backups except the latest 3 from the updaters backup directory |
|
46 | + */ |
|
47 | + public function run($arguments) { |
|
48 | + $updateDir = $this->config->getSystemValue('updatedirectory', null) ?? $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
49 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
|
50 | 50 | |
51 | - if (!is_string($instanceId) || empty($instanceId)) { |
|
52 | - return; |
|
53 | - } |
|
51 | + if (!is_string($instanceId) || empty($instanceId)) { |
|
52 | + return; |
|
53 | + } |
|
54 | 54 | |
55 | - $updaterFolderPath = $updateDir . '/updater-' . $instanceId; |
|
56 | - $backupFolderPath = $updaterFolderPath . '/backups'; |
|
57 | - if (file_exists($backupFolderPath)) { |
|
58 | - $this->log->info("$backupFolderPath exists - start to clean it up"); |
|
55 | + $updaterFolderPath = $updateDir . '/updater-' . $instanceId; |
|
56 | + $backupFolderPath = $updaterFolderPath . '/backups'; |
|
57 | + if (file_exists($backupFolderPath)) { |
|
58 | + $this->log->info("$backupFolderPath exists - start to clean it up"); |
|
59 | 59 | |
60 | - $dirList = []; |
|
61 | - $dirs = new \DirectoryIterator($backupFolderPath); |
|
62 | - foreach ($dirs as $dir) { |
|
63 | - // skip files and dot dirs |
|
64 | - if ($dir->isFile() || $dir->isDot()) { |
|
65 | - continue; |
|
66 | - } |
|
60 | + $dirList = []; |
|
61 | + $dirs = new \DirectoryIterator($backupFolderPath); |
|
62 | + foreach ($dirs as $dir) { |
|
63 | + // skip files and dot dirs |
|
64 | + if ($dir->isFile() || $dir->isDot()) { |
|
65 | + continue; |
|
66 | + } |
|
67 | 67 | |
68 | - $mtime = $dir->getMTime(); |
|
69 | - $realPath = $dir->getRealPath(); |
|
68 | + $mtime = $dir->getMTime(); |
|
69 | + $realPath = $dir->getRealPath(); |
|
70 | 70 | |
71 | - if ($realPath === false) { |
|
72 | - continue; |
|
73 | - } |
|
71 | + if ($realPath === false) { |
|
72 | + continue; |
|
73 | + } |
|
74 | 74 | |
75 | - $dirList[$mtime] = $realPath; |
|
76 | - } |
|
75 | + $dirList[$mtime] = $realPath; |
|
76 | + } |
|
77 | 77 | |
78 | - ksort($dirList); |
|
79 | - // drop the newest 3 directories |
|
80 | - $dirList = array_slice($dirList, 0, -3); |
|
81 | - $this->log->info("List of all directories that will be deleted: " . json_encode($dirList)); |
|
78 | + ksort($dirList); |
|
79 | + // drop the newest 3 directories |
|
80 | + $dirList = array_slice($dirList, 0, -3); |
|
81 | + $this->log->info("List of all directories that will be deleted: " . json_encode($dirList)); |
|
82 | 82 | |
83 | - foreach ($dirList as $dir) { |
|
84 | - $this->log->info("Removing $dir ..."); |
|
85 | - \OC_Helper::rmdirr($dir); |
|
86 | - } |
|
87 | - $this->log->info("Cleanup finished"); |
|
88 | - } else { |
|
89 | - $this->log->info("Could not find updater directory $backupFolderPath - cleanup step not needed"); |
|
90 | - } |
|
91 | - } |
|
83 | + foreach ($dirList as $dir) { |
|
84 | + $this->log->info("Removing $dir ..."); |
|
85 | + \OC_Helper::rmdirr($dir); |
|
86 | + } |
|
87 | + $this->log->info("Cleanup finished"); |
|
88 | + } else { |
|
89 | + $this->log->info("Could not find updater directory $backupFolderPath - cleanup step not needed"); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | } |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | * This job cleans up all backups except the latest 3 from the updaters backup directory |
46 | 46 | */ |
47 | 47 | public function run($arguments) { |
48 | - $updateDir = $this->config->getSystemValue('updatedirectory', null) ?? $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
48 | + $updateDir = $this->config->getSystemValue('updatedirectory', null) ?? $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); |
|
49 | 49 | $instanceId = $this->config->getSystemValue('instanceid', null); |
50 | 50 | |
51 | 51 | if (!is_string($instanceId) || empty($instanceId)) { |
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
55 | - $updaterFolderPath = $updateDir . '/updater-' . $instanceId; |
|
56 | - $backupFolderPath = $updaterFolderPath . '/backups'; |
|
55 | + $updaterFolderPath = $updateDir.'/updater-'.$instanceId; |
|
56 | + $backupFolderPath = $updaterFolderPath.'/backups'; |
|
57 | 57 | if (file_exists($backupFolderPath)) { |
58 | 58 | $this->log->info("$backupFolderPath exists - start to clean it up"); |
59 | 59 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | ksort($dirList); |
79 | 79 | // drop the newest 3 directories |
80 | 80 | $dirList = array_slice($dirList, 0, -3); |
81 | - $this->log->info("List of all directories that will be deleted: " . json_encode($dirList)); |
|
81 | + $this->log->info("List of all directories that will be deleted: ".json_encode($dirList)); |
|
82 | 82 | |
83 | 83 | foreach ($dirList as $dir) { |
84 | 84 | $this->log->info("Removing $dir ..."); |