Passed
Push — master ( ad6eb8...bba3a1 )
by Julius
14:09 queued 18s
created

FileChunkCleanupJob::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * @copyright 2023 Anna Larch <[email protected]>
6
 *
7
 * @author Anna Larch <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
namespace OCA\Files\BackgroundJob;
26
27
use OC\Cache\File;
28
use OCP\AppFramework\Utility\ITimeFactory;
29
use OCP\BackgroundJob\Job;
30
use OCP\BackgroundJob\TimedJob;
31
use OCP\Files\IRootFolder;
32
use OCP\IUser;
33
use OCP\IUserManager;
34
use Psr\Log\LoggerInterface;
35
36
class FileChunkCleanupJob extends TimedJob {
37
	private IUserManager $userManager;
38
	private IRootFolder $rootFolder;
39
	private LoggerInterface $logger;
40
41
	public function __construct(IUserManager $userManager, IRootFolder $rootFolder, LoggerInterface $logger, ITimeFactory $timeFactory) {
42
		parent::__construct($timeFactory);
43
		$this->setInterval(3600*24);
44
		$this->setTimeSensitivity(Job::TIME_INSENSITIVE);
45
		$this->userManager = $userManager;
46
		$this->rootFolder = $rootFolder;
47
		$this->logger = $logger;
48
	}
49
50
	/**
51
	 * This job cleans up all backups except the latest 3 from the updaters backup directory
52
	 */
53
	public function run($argument): void {
54
		$this->userManager->callForSeenUsers(function (IUser $user): void {
55
			$this->logger->debug('Running chunk cleanup job for user '. $user->getUID());
56
			$fileCache = new File();
0 ignored issues
show
Deprecated Code introduced by
The class OC\Cache\File has been deprecated: 26.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

56
			$fileCache = /** @scrutinizer ignore-deprecated */ new File();
Loading history...
57
			$fileCache->setUpStorage($user->getUID());
58
			$fileCache->gc();
59
			$this->logger->debug('Finished running chunk cleanup job for user '. $user->getUID());
60
		});
61
	}
62
}
63