Completed
Push — master ( b4df57...e6895c )
by Lukas
26s
created

GenerateBirthdays   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 3
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 3 1
A run() 0 10 1
1
<?php
2
/**
3
 * @author Thomas Müller <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2016, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
23
namespace OCA\DAV\Migration;
24
25
use OCA\DAV\CalDAV\BirthdayService;
26
use OCP\IUser;
27
use OCP\IUserManager;
28
use OCP\Migration\IOutput;
29
use OCP\Migration\IRepairStep;
30
31
class GenerateBirthdays implements IRepairStep {
32
33
	/** @var BirthdayService */
34
	private $birthdayService;
35
36
	/** @var IUserManager */
37
	private $userManager;
38
39
	/**
40
	 * GenerateBirthdays constructor.
41
	 *
42
	 * @param BirthdayService $birthdayService
43
	 * @param IUserManager $userManager
44
	 */
45
	public function __construct(BirthdayService $birthdayService, IUserManager $userManager) {
46
		$this->birthdayService = $birthdayService;
47
		$this->userManager = $userManager;
48
	}
49
50
	/**
51
	 * @inheritdoc
52
	 */
53
	public function getName() {
54
		return 'Regenerate birthday calendar for all users';
55
	}
56
57
	/**
58
	 * @inheritdoc
59
	 */
60
	public function run(IOutput $output) {
61
62
		$output->startProgress();
63
		$this->userManager->callForAllUsers(function($user) use ($output) {
64
			/** @var IUser $user */
65
			$output->advance(1, $user->getDisplayName());
66
			$this->birthdayService->syncUser($user->getUID());
67
		});
68
		$output->finishProgress();
69
	}
70
}
71