|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright 2019 Georg Ehrke <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Georg Ehrke <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
namespace OCA\DAV\Migration; |
|
24
|
|
|
|
|
25
|
|
|
use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob; |
|
26
|
|
|
use OCP\BackgroundJob\IJobList; |
|
27
|
|
|
use OCP\IConfig; |
|
28
|
|
|
use OCP\IUser; |
|
29
|
|
|
use OCP\IUserManager; |
|
30
|
|
|
use OCP\Migration\IOutput; |
|
31
|
|
|
use OCP\Migration\IRepairStep; |
|
32
|
|
|
|
|
33
|
|
|
class RegenerateBirthdayCalendars implements IRepairStep { |
|
34
|
|
|
|
|
35
|
|
|
/** @var IUserManager */ |
|
36
|
|
|
private $userManager; |
|
37
|
|
|
|
|
38
|
|
|
/** @var IJobList */ |
|
39
|
|
|
private $jobList; |
|
40
|
|
|
|
|
41
|
|
|
/** @var IConfig */ |
|
42
|
|
|
private $config; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param IUserManager $userManager, |
|
46
|
|
|
* @param IJobList $jobList |
|
47
|
|
|
* @param IConfig $config |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct(IUserManager $userManager, |
|
50
|
|
|
IJobList $jobList, |
|
51
|
|
|
IConfig $config) { |
|
52
|
|
|
$this->userManager = $userManager; |
|
53
|
|
|
$this->jobList = $jobList; |
|
54
|
|
|
$this->config = $config; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getName() { |
|
61
|
|
|
return 'Regenerating birthday calendars to use new icons and fix old birthday events without year'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param IOutput $output |
|
66
|
|
|
*/ |
|
67
|
|
|
public function run(IOutput $output) { |
|
68
|
|
|
// only run once |
|
69
|
|
|
if ($this->config->getAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix') === 'yes') { |
|
70
|
|
|
$output->info('Repair step already executed'); |
|
71
|
|
|
return; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$output->info('Adding background jobs to regenerate birthday calendar'); |
|
75
|
|
|
$this->userManager->callForAllUsers(function(IUser $user) { |
|
76
|
|
|
$this->jobList->add(GenerateBirthdayCalendarBackgroundJob::class, [ |
|
77
|
|
|
'userId' => $user->getUID(), |
|
78
|
|
|
'purgeBeforeGenerating' => true |
|
79
|
|
|
]); |
|
80
|
|
|
}); |
|
81
|
|
|
|
|
82
|
|
|
// if all were done, no need to redo the repair during next upgrade |
|
83
|
|
|
$this->config->setAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes'); |
|
84
|
|
|
} |
|
85
|
|
|
} |