1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright 2017, Georg Ehrke <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Christoph Wurst <[email protected]> |
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
|
|
|
namespace OCA\DAV\Controller; |
25
|
|
|
|
26
|
|
|
use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob; |
27
|
|
|
use OCA\DAV\CalDAV\CalDavBackend; |
28
|
|
|
use OCP\AppFramework\Controller; |
29
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
30
|
|
|
use OCP\AppFramework\Http\Response; |
31
|
|
|
use OCP\BackgroundJob\IJobList; |
32
|
|
|
use OCP\IConfig; |
33
|
|
|
use OCP\IDBConnection; |
34
|
|
|
use OCP\IRequest; |
35
|
|
|
use OCP\IUser; |
36
|
|
|
use OCP\IUserManager; |
37
|
|
|
|
38
|
|
|
class BirthdayCalendarController extends Controller { |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var IDBConnection |
42
|
|
|
*/ |
43
|
|
|
protected $db; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var IConfig |
47
|
|
|
*/ |
48
|
|
|
protected $config; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var IUserManager |
52
|
|
|
*/ |
53
|
|
|
protected $userManager; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var CalDavBackend |
57
|
|
|
*/ |
58
|
|
|
protected $caldavBackend; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var IJobList |
62
|
|
|
*/ |
63
|
|
|
protected $jobList; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* BirthdayCalendar constructor. |
67
|
|
|
* |
68
|
|
|
* @param string $appName |
69
|
|
|
* @param IRequest $request |
70
|
|
|
* @param IDBConnection $db |
71
|
|
|
* @param IConfig $config |
72
|
|
|
* @param IJobList $jobList |
73
|
|
|
* @param IUserManager $userManager |
74
|
|
|
* @param CalDavBackend $calDavBackend |
75
|
|
|
*/ |
76
|
|
|
public function __construct($appName, IRequest $request, |
77
|
|
|
IDBConnection $db, IConfig $config, |
78
|
|
|
IJobList $jobList, |
79
|
|
|
IUserManager $userManager, |
80
|
|
|
CalDavBackend $calDavBackend) { |
81
|
|
|
parent::__construct($appName, $request); |
82
|
|
|
$this->db = $db; |
83
|
|
|
$this->config = $config; |
84
|
|
|
$this->userManager = $userManager; |
85
|
|
|
$this->jobList = $jobList; |
86
|
|
|
$this->caldavBackend = $calDavBackend; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return Response |
91
|
|
|
* @AuthorizedAdminSetting(settings=OCA\DAV\Settings\CalDAVSettings) |
92
|
|
|
*/ |
93
|
|
|
public function enable() { |
94
|
|
|
$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'yes'); |
95
|
|
|
|
96
|
|
|
// add background job for each user |
97
|
|
|
$this->userManager->callForSeenUsers(function (IUser $user) { |
98
|
|
|
$this->jobList->add(GenerateBirthdayCalendarBackgroundJob::class, [ |
99
|
|
|
'userId' => $user->getUID(), |
100
|
|
|
]); |
101
|
|
|
}); |
102
|
|
|
|
103
|
|
|
return new JSONResponse([]); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return Response |
108
|
|
|
* @AuthorizedAdminSetting(settings=OCA\DAV\Settings\CalDAVSettings) |
109
|
|
|
*/ |
110
|
|
|
public function disable() { |
111
|
|
|
$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'no'); |
112
|
|
|
|
113
|
|
|
$this->jobList->remove(GenerateBirthdayCalendarBackgroundJob::class); |
114
|
|
|
$this->caldavBackend->deleteAllBirthdayCalendars(); |
115
|
|
|
|
116
|
|
|
return new JSONResponse([]); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|