Passed
Push — master ( 25fe32...0fb74a )
by Morris
13:02 queued 10s
created

RefreshWebcalJobRegistrar   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A run() 0 20 3
A getName() 0 2 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright 2018 Georg Ehrke <[email protected]>
5
 *
6
 * @author Georg Ehrke <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\DAV\Migration;
26
27
use OCA\DAV\BackgroundJob\RefreshWebcalJob;
28
use OCP\BackgroundJob\IJobList;
29
use OCP\IDBConnection;
30
use OCP\Migration\IOutput;
31
use OCP\Migration\IRepairStep;
32
33
class RefreshWebcalJobRegistrar implements IRepairStep {
34
35
	/** @var IDBConnection */
36
	private $connection;
37
38
	/** @var IJobList */
39
	private $jobList;
40
41
	/**
42
	 * FixBirthdayCalendarComponent constructor.
43
	 *
44
	 * @param IDBConnection $connection
45
	 * @param IJobList $jobList
46
	 */
47
	public function __construct(IDBConnection $connection, IJobList $jobList) {
48
		$this->connection = $connection;
49
		$this->jobList = $jobList;
50
	}
51
52
	/**
53
	 * @inheritdoc
54
	 */
55
	public function getName() {
56
		return 'Registering background jobs to update cache for webcal calendars';
57
	}
58
59
	/**
60
	 * @inheritdoc
61
	 */
62
	public function run(IOutput $output) {
63
		$query = $this->connection->getQueryBuilder();
64
		$query->select(['principaluri', 'uri'])
65
			->from('calendarsubscriptions');
66
		$stmt = $query->execute();
67
68
		$count = 0;
69
		while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
70
			$args = [
71
				'principaluri' => $row['principaluri'],
72
				'uri' => $row['uri'],
73
			];
74
75
			if (!$this->jobList->has(RefreshWebcalJob::class, $args)) {
76
				$this->jobList->add(RefreshWebcalJob::class, $args);
77
				$count++;
78
			}
79
		}
80
81
		$output->info("Added $count background jobs to update webcal calendars");
82
	}
83
}
84