Passed
Push — master ( 613b2a...08e11d )
by Christoph
14:08 queued 13s
created

PruneOutdatedSyncTokensJob   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 26
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A run() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright 2022 Thomas Citharel <[email protected]>
7
 *
8
 * @author Thomas Citharel <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
namespace OCA\DAV\BackgroundJob;
27
28
use OCP\AppFramework\Utility\ITimeFactory;
29
use OCP\BackgroundJob\TimedJob;
30
use OCA\DAV\AppInfo\Application;
31
use OCA\DAV\CalDAV\CalDavBackend;
32
use OCA\DAV\CardDAV\CardDavBackend;
33
use OCP\IConfig;
34
use Psr\Log\LoggerInterface;
35
36
class PruneOutdatedSyncTokensJob extends TimedJob {
37
38
	private IConfig $config;
39
	private LoggerInterface $logger;
40
	private CardDavBackend $cardDavBackend;
41
	private CalDavBackend $calDavBackend;
42
43
	public function __construct(ITimeFactory $timeFactory, CalDavBackend $calDavBackend, CardDavBackend $cardDavBackend, IConfig $config, LoggerInterface $logger) {
44
		parent::__construct($timeFactory);
45
		$this->calDavBackend = $calDavBackend;
46
		$this->cardDavBackend = $cardDavBackend;
47
		$this->config = $config;
48
		$this->logger = $logger;
49
		$this->setInterval(60 * 60 * 24); // One day
50
		$this->setTimeSensitivity(self::TIME_INSENSITIVE);
51
	}
52
53
	public function run($argument) {
54
		$limit = max(1, (int) $this->config->getAppValue(Application::APP_ID, 'totalNumberOfSyncTokensToKeep', '10000'));
55
56
		$prunedCalendarSyncTokens = $this->calDavBackend->pruneOutdatedSyncTokens($limit);
57
		$prunedAddressBookSyncTokens = $this->cardDavBackend->pruneOutdatedSyncTokens($limit);
58
59
		$this->logger->info('Pruned {calendarSyncTokensNumber} calendar sync tokens and {addressBooksSyncTokensNumber} address book sync tokens', [
60
			'calendarSyncTokensNumber' => $prunedCalendarSyncTokens,
61
			'addressBooksSyncTokensNumber' => $prunedAddressBookSyncTokens
62
		]);
63
	}
64
}
65