Completed
Pull Request — master (#6884)
by Georg
24:01 queued 11:17
created
apps/dav/appinfo/routes.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@
 block discarded – undo
22 22
  */
23 23
 
24 24
 return [
25
-	'routes' => [
26
-		['name' => 'birthday_calendar#enable', 'url' => '/enableBirthdayCalendar', 'verb' => 'POST'],
27
-		['name' => 'birthday_calendar#disable', 'url' => '/disableBirthdayCalendar', 'verb' => 'POST'],
28
-	]
25
+    'routes' => [
26
+        ['name' => 'birthday_calendar#enable', 'url' => '/enableBirthdayCalendar', 'verb' => 'POST'],
27
+        ['name' => 'birthday_calendar#disable', 'url' => '/disableBirthdayCalendar', 'verb' => 'POST'],
28
+    ]
29 29
 ];
Please login to merge, or discard this patch.
apps/dav/lib/Controller/BirthdayCalendarController.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -32,50 +32,50 @@
 block discarded – undo
32 32
 
33 33
 class BirthdayCalendarController extends Controller {
34 34
 
35
-	/**
36
-	 * @var IDBConnection
37
-	 */
38
-	protected $db;
35
+    /**
36
+     * @var IDBConnection
37
+     */
38
+    protected $db;
39 39
 
40
-	/**
41
-	 * @var IConfig
42
-	 */
43
-	protected $config;
40
+    /**
41
+     * @var IConfig
42
+     */
43
+    protected $config;
44 44
 
45
-	/**
46
-	 * BirthdayCalendar constructor.
47
-	 *
48
-	 * @param string $appName
49
-	 * @param IRequest $request
50
-	 * @param IDBConnection $db
51
-	 * @param IConfig $config
52
-	 */
53
-	public function __construct($appName, IRequest $request,
54
-								IDBConnection $db, IConfig $config){
55
-		parent::__construct($appName, $request);
56
-		$this->db = $db;
57
-		$this->config = $config;
58
-	}
45
+    /**
46
+     * BirthdayCalendar constructor.
47
+     *
48
+     * @param string $appName
49
+     * @param IRequest $request
50
+     * @param IDBConnection $db
51
+     * @param IConfig $config
52
+     */
53
+    public function __construct($appName, IRequest $request,
54
+                                IDBConnection $db, IConfig $config){
55
+        parent::__construct($appName, $request);
56
+        $this->db = $db;
57
+        $this->config = $config;
58
+    }
59 59
 
60
-	/**
61
-	 * @return Response
62
-	 */
63
-	public function enable() {
64
-		$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'yes');
60
+    /**
61
+     * @return Response
62
+     */
63
+    public function enable() {
64
+        $this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'yes');
65 65
 
66
-		// TODO schedule background job to regenerate
66
+        // TODO schedule background job to regenerate
67 67
 
68
-		return new JSONResponse([]);
69
-	}
68
+        return new JSONResponse([]);
69
+    }
70 70
 
71
-	/**
72
-	 * @return Response
73
-	 */
74
-	public function disable() {
75
-		$this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'no');
71
+    /**
72
+     * @return Response
73
+     */
74
+    public function disable() {
75
+        $this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'no');
76 76
 
77
-		// TODO delete all birthday calendars
77
+        // TODO delete all birthday calendars
78 78
 
79
-		return new JSONResponse([]);
80
-	}
79
+        return new JSONResponse([]);
80
+    }
81 81
 }
Please login to merge, or discard this patch.
apps/dav/lib/Settings/CalDAVSettings.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,41 +29,41 @@
 block discarded – undo
29 29
 
30 30
 class CalDAVSettings implements ISettings {
31 31
 
32
-	/** @var IConfig */
33
-	private $config;
32
+    /** @var IConfig */
33
+    private $config;
34 34
 
35
-	/**
36
-	 * CalDAVSettings constructor.
37
-	 *
38
-	 * @param IConfig $config
39
-	 */
40
-	public function __construct(IConfig $config) {
41
-		$this->config = $config;
42
-	}
35
+    /**
36
+     * CalDAVSettings constructor.
37
+     *
38
+     * @param IConfig $config
39
+     */
40
+    public function __construct(IConfig $config) {
41
+        $this->config = $config;
42
+    }
43 43
 
44
-	/**
45
-	 * @return TemplateResponse
46
-	 */
47
-	public function getForm() {
48
-		$parameters = [
49
-			'send_invitations' => $this->config->getAppValue('dav', 'sendInvitations', 'yes'),
50
-			'generate_birthday_calendar' => $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'),
51
-		];
44
+    /**
45
+     * @return TemplateResponse
46
+     */
47
+    public function getForm() {
48
+        $parameters = [
49
+            'send_invitations' => $this->config->getAppValue('dav', 'sendInvitations', 'yes'),
50
+            'generate_birthday_calendar' => $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'),
51
+        ];
52 52
 
53
-		return new TemplateResponse('dav', 'settings-admin-caldav', $parameters);
54
-	}
53
+        return new TemplateResponse('dav', 'settings-admin-caldav', $parameters);
54
+    }
55 55
 
56
-	/**
57
-	 * @return string
58
-	 */
59
-	public function getSection() {
60
-		return 'additional';
61
-	}
56
+    /**
57
+     * @return string
58
+     */
59
+    public function getSection() {
60
+        return 'additional';
61
+    }
62 62
 
63
-	/**
64
-	 * @return int
65
-	 */
66
-	public function getPriority() {
67
-		return 20;
68
-	}
63
+    /**
64
+     * @return int
65
+     */
66
+    public function getPriority() {
67
+        return 20;
68
+    }
69 69
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Calendar.php 1 patch
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -39,302 +39,302 @@
 block discarded – undo
39 39
  */
40 40
 class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
41 41
 
42
-	/** @var IConfig */
43
-	private $config;
44
-
45
-	public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
46
-		parent::__construct($caldavBackend, $calendarInfo);
47
-
48
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
49
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
50
-		}
51
-		if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
52
-			$this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
53
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
54
-		}
55
-
56
-		$this->config = $config;
57
-	}
58
-
59
-	/**
60
-	 * Updates the list of shares.
61
-	 *
62
-	 * The first array is a list of people that are to be added to the
63
-	 * resource.
64
-	 *
65
-	 * Every element in the add array has the following properties:
66
-	 *   * href - A url. Usually a mailto: address
67
-	 *   * commonName - Usually a first and last name, or false
68
-	 *   * summary - A description of the share, can also be false
69
-	 *   * readOnly - A boolean value
70
-	 *
71
-	 * Every element in the remove array is just the address string.
72
-	 *
73
-	 * @param array $add
74
-	 * @param array $remove
75
-	 * @return void
76
-	 * @throws Forbidden
77
-	 */
78
-	public function updateShares(array $add, array $remove) {
79
-		if ($this->isShared()) {
80
-			throw new Forbidden();
81
-		}
82
-		$this->caldavBackend->updateShares($this, $add, $remove);
83
-	}
84
-
85
-	/**
86
-	 * Returns the list of people whom this resource is shared with.
87
-	 *
88
-	 * Every element in this array should have the following properties:
89
-	 *   * href - Often a mailto: address
90
-	 *   * commonName - Optional, for example a first + last name
91
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
92
-	 *   * readOnly - boolean
93
-	 *   * summary - Optional, a description for the share
94
-	 *
95
-	 * @return array
96
-	 */
97
-	public function getShares() {
98
-		if ($this->isShared()) {
99
-			return [];
100
-		}
101
-		return $this->caldavBackend->getShares($this->getResourceId());
102
-	}
103
-
104
-	/**
105
-	 * @return int
106
-	 */
107
-	public function getResourceId() {
108
-		return $this->calendarInfo['id'];
109
-	}
110
-
111
-	/**
112
-	 * @return string
113
-	 */
114
-	public function getPrincipalURI() {
115
-		return $this->calendarInfo['principaluri'];
116
-	}
117
-
118
-	public function getACL() {
119
-		$acl =  [
120
-			[
121
-				'privilege' => '{DAV:}read',
122
-				'principal' => $this->getOwner(),
123
-				'protected' => true,
124
-			]];
125
-		if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
126
-			$acl[] = [
127
-				'privilege' => '{DAV:}write',
128
-				'principal' => $this->getOwner(),
129
-				'protected' => true,
130
-			];
131
-		} else {
132
-			$acl[] = [
133
-				'privilege' => '{DAV:}write-properties',
134
-				'principal' => $this->getOwner(),
135
-				'protected' => true,
136
-			];
137
-		}
138
-
139
-		if ($this->getOwner() !== parent::getOwner()) {
140
-			$acl[] =  [
141
-					'privilege' => '{DAV:}read',
142
-					'principal' => parent::getOwner(),
143
-					'protected' => true,
144
-				];
145
-			if ($this->canWrite()) {
146
-				$acl[] = [
147
-					'privilege' => '{DAV:}write',
148
-					'principal' => parent::getOwner(),
149
-					'protected' => true,
150
-				];
151
-			} else {
152
-				$acl[] = [
153
-					'privilege' => '{DAV:}write-properties',
154
-					'principal' => parent::getOwner(),
155
-					'protected' => true,
156
-				];
157
-			}
158
-		}
159
-		if ($this->isPublic()) {
160
-			$acl[] = [
161
-				'privilege' => '{DAV:}read',
162
-				'principal' => 'principals/system/public',
163
-				'protected' => true,
164
-			];
165
-		}
166
-
167
-		$acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
168
-
169
-		if (!$this->isShared()) {
170
-			return $acl;
171
-		}
172
-
173
-		$allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
174
-		return array_filter($acl, function($rule) use ($allowedPrincipals) {
175
-			return in_array($rule['principal'], $allowedPrincipals);
176
-		});
177
-	}
178
-
179
-	public function getChildACL() {
180
-		return $this->getACL();
181
-	}
182
-
183
-	public function getOwner() {
184
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
185
-			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
186
-		}
187
-		return parent::getOwner();
188
-	}
189
-
190
-	public function delete() {
191
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
192
-			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
193
-			$principal = 'principal:' . parent::getOwner();
194
-			$shares = $this->caldavBackend->getShares($this->getResourceId());
195
-			$shares = array_filter($shares, function($share) use ($principal){
196
-				return $share['href'] === $principal;
197
-			});
198
-			if (empty($shares)) {
199
-				throw new Forbidden();
200
-			}
201
-
202
-			$this->caldavBackend->updateShares($this, [], [
203
-				'href' => $principal
204
-			]);
205
-			return;
206
-		}
207
-
208
-		// Remember when a user deleted their birthday calendar
209
-		// in order to not regenerate it on the next contacts change
210
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
211
-			$principalURI = $this->getPrincipalURI();
212
-			$userId = substr($principalURI, 17);
213
-
214
-			$this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
215
-		}
216
-
217
-		parent::delete();
218
-	}
219
-
220
-	public function propPatch(PropPatch $propPatch) {
221
-		// parent::propPatch will only update calendars table
222
-		// if calendar is shared, changes have to be made to the properties table
223
-		if (!$this->isShared()) {
224
-			parent::propPatch($propPatch);
225
-		}
226
-	}
227
-
228
-	public function getChild($name) {
229
-
230
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
231
-
232
-		if (!$obj) {
233
-			throw new NotFound('Calendar object not found');
234
-		}
235
-
236
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
237
-			throw new NotFound('Calendar object not found');
238
-		}
239
-
240
-		$obj['acl'] = $this->getChildACL();
241
-
242
-		return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
243
-
244
-	}
245
-
246
-	public function getChildren() {
247
-
248
-		$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
249
-		$children = [];
250
-		foreach ($objs as $obj) {
251
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
252
-				continue;
253
-			}
254
-			$obj['acl'] = $this->getChildACL();
255
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
256
-		}
257
-		return $children;
258
-
259
-	}
260
-
261
-	public function getMultipleChildren(array $paths) {
262
-
263
-		$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
264
-		$children = [];
265
-		foreach ($objs as $obj) {
266
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
267
-				continue;
268
-			}
269
-			$obj['acl'] = $this->getChildACL();
270
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
271
-		}
272
-		return $children;
273
-
274
-	}
275
-
276
-	public function childExists($name) {
277
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
278
-		if (!$obj) {
279
-			return false;
280
-		}
281
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
282
-			return false;
283
-		}
284
-
285
-		return true;
286
-	}
287
-
288
-	public function calendarQuery(array $filters) {
289
-
290
-		$uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
291
-		if ($this->isShared()) {
292
-			return array_filter($uris, function ($uri) {
293
-				return $this->childExists($uri);
294
-			});
295
-		}
296
-
297
-		return $uris;
298
-	}
299
-
300
-	/**
301
-	 * @param boolean $value
302
-	 * @return string|null
303
-	 */
304
-	public function setPublishStatus($value) {
305
-		$publicUri = $this->caldavBackend->setPublishStatus($value, $this);
306
-		$this->calendarInfo['publicuri'] = $publicUri;
307
-		return $publicUri;
308
-	}
309
-
310
-	/**
311
-	 * @return mixed $value
312
-	 */
313
-	public function getPublishStatus() {
314
-		return $this->caldavBackend->getPublishStatus($this);
315
-	}
316
-
317
-	private function canWrite() {
318
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
319
-			return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
320
-		}
321
-		return true;
322
-	}
323
-
324
-	private function isPublic() {
325
-		return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
326
-	}
327
-
328
-	protected function isShared() {
329
-		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
330
-			return false;
331
-		}
332
-
333
-		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
334
-	}
335
-
336
-	public function isSubscription() {
337
-		return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
338
-	}
42
+    /** @var IConfig */
43
+    private $config;
44
+
45
+    public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
46
+        parent::__construct($caldavBackend, $calendarInfo);
47
+
48
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
49
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
50
+        }
51
+        if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
52
+            $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
53
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
54
+        }
55
+
56
+        $this->config = $config;
57
+    }
58
+
59
+    /**
60
+     * Updates the list of shares.
61
+     *
62
+     * The first array is a list of people that are to be added to the
63
+     * resource.
64
+     *
65
+     * Every element in the add array has the following properties:
66
+     *   * href - A url. Usually a mailto: address
67
+     *   * commonName - Usually a first and last name, or false
68
+     *   * summary - A description of the share, can also be false
69
+     *   * readOnly - A boolean value
70
+     *
71
+     * Every element in the remove array is just the address string.
72
+     *
73
+     * @param array $add
74
+     * @param array $remove
75
+     * @return void
76
+     * @throws Forbidden
77
+     */
78
+    public function updateShares(array $add, array $remove) {
79
+        if ($this->isShared()) {
80
+            throw new Forbidden();
81
+        }
82
+        $this->caldavBackend->updateShares($this, $add, $remove);
83
+    }
84
+
85
+    /**
86
+     * Returns the list of people whom this resource is shared with.
87
+     *
88
+     * Every element in this array should have the following properties:
89
+     *   * href - Often a mailto: address
90
+     *   * commonName - Optional, for example a first + last name
91
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
92
+     *   * readOnly - boolean
93
+     *   * summary - Optional, a description for the share
94
+     *
95
+     * @return array
96
+     */
97
+    public function getShares() {
98
+        if ($this->isShared()) {
99
+            return [];
100
+        }
101
+        return $this->caldavBackend->getShares($this->getResourceId());
102
+    }
103
+
104
+    /**
105
+     * @return int
106
+     */
107
+    public function getResourceId() {
108
+        return $this->calendarInfo['id'];
109
+    }
110
+
111
+    /**
112
+     * @return string
113
+     */
114
+    public function getPrincipalURI() {
115
+        return $this->calendarInfo['principaluri'];
116
+    }
117
+
118
+    public function getACL() {
119
+        $acl =  [
120
+            [
121
+                'privilege' => '{DAV:}read',
122
+                'principal' => $this->getOwner(),
123
+                'protected' => true,
124
+            ]];
125
+        if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
126
+            $acl[] = [
127
+                'privilege' => '{DAV:}write',
128
+                'principal' => $this->getOwner(),
129
+                'protected' => true,
130
+            ];
131
+        } else {
132
+            $acl[] = [
133
+                'privilege' => '{DAV:}write-properties',
134
+                'principal' => $this->getOwner(),
135
+                'protected' => true,
136
+            ];
137
+        }
138
+
139
+        if ($this->getOwner() !== parent::getOwner()) {
140
+            $acl[] =  [
141
+                    'privilege' => '{DAV:}read',
142
+                    'principal' => parent::getOwner(),
143
+                    'protected' => true,
144
+                ];
145
+            if ($this->canWrite()) {
146
+                $acl[] = [
147
+                    'privilege' => '{DAV:}write',
148
+                    'principal' => parent::getOwner(),
149
+                    'protected' => true,
150
+                ];
151
+            } else {
152
+                $acl[] = [
153
+                    'privilege' => '{DAV:}write-properties',
154
+                    'principal' => parent::getOwner(),
155
+                    'protected' => true,
156
+                ];
157
+            }
158
+        }
159
+        if ($this->isPublic()) {
160
+            $acl[] = [
161
+                'privilege' => '{DAV:}read',
162
+                'principal' => 'principals/system/public',
163
+                'protected' => true,
164
+            ];
165
+        }
166
+
167
+        $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
168
+
169
+        if (!$this->isShared()) {
170
+            return $acl;
171
+        }
172
+
173
+        $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
174
+        return array_filter($acl, function($rule) use ($allowedPrincipals) {
175
+            return in_array($rule['principal'], $allowedPrincipals);
176
+        });
177
+    }
178
+
179
+    public function getChildACL() {
180
+        return $this->getACL();
181
+    }
182
+
183
+    public function getOwner() {
184
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
185
+            return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
186
+        }
187
+        return parent::getOwner();
188
+    }
189
+
190
+    public function delete() {
191
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
192
+            $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
193
+            $principal = 'principal:' . parent::getOwner();
194
+            $shares = $this->caldavBackend->getShares($this->getResourceId());
195
+            $shares = array_filter($shares, function($share) use ($principal){
196
+                return $share['href'] === $principal;
197
+            });
198
+            if (empty($shares)) {
199
+                throw new Forbidden();
200
+            }
201
+
202
+            $this->caldavBackend->updateShares($this, [], [
203
+                'href' => $principal
204
+            ]);
205
+            return;
206
+        }
207
+
208
+        // Remember when a user deleted their birthday calendar
209
+        // in order to not regenerate it on the next contacts change
210
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
211
+            $principalURI = $this->getPrincipalURI();
212
+            $userId = substr($principalURI, 17);
213
+
214
+            $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
215
+        }
216
+
217
+        parent::delete();
218
+    }
219
+
220
+    public function propPatch(PropPatch $propPatch) {
221
+        // parent::propPatch will only update calendars table
222
+        // if calendar is shared, changes have to be made to the properties table
223
+        if (!$this->isShared()) {
224
+            parent::propPatch($propPatch);
225
+        }
226
+    }
227
+
228
+    public function getChild($name) {
229
+
230
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
231
+
232
+        if (!$obj) {
233
+            throw new NotFound('Calendar object not found');
234
+        }
235
+
236
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
237
+            throw new NotFound('Calendar object not found');
238
+        }
239
+
240
+        $obj['acl'] = $this->getChildACL();
241
+
242
+        return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
243
+
244
+    }
245
+
246
+    public function getChildren() {
247
+
248
+        $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
249
+        $children = [];
250
+        foreach ($objs as $obj) {
251
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
252
+                continue;
253
+            }
254
+            $obj['acl'] = $this->getChildACL();
255
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
256
+        }
257
+        return $children;
258
+
259
+    }
260
+
261
+    public function getMultipleChildren(array $paths) {
262
+
263
+        $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
264
+        $children = [];
265
+        foreach ($objs as $obj) {
266
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
267
+                continue;
268
+            }
269
+            $obj['acl'] = $this->getChildACL();
270
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
271
+        }
272
+        return $children;
273
+
274
+    }
275
+
276
+    public function childExists($name) {
277
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
278
+        if (!$obj) {
279
+            return false;
280
+        }
281
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
282
+            return false;
283
+        }
284
+
285
+        return true;
286
+    }
287
+
288
+    public function calendarQuery(array $filters) {
289
+
290
+        $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
291
+        if ($this->isShared()) {
292
+            return array_filter($uris, function ($uri) {
293
+                return $this->childExists($uri);
294
+            });
295
+        }
296
+
297
+        return $uris;
298
+    }
299
+
300
+    /**
301
+     * @param boolean $value
302
+     * @return string|null
303
+     */
304
+    public function setPublishStatus($value) {
305
+        $publicUri = $this->caldavBackend->setPublishStatus($value, $this);
306
+        $this->calendarInfo['publicuri'] = $publicUri;
307
+        return $publicUri;
308
+    }
309
+
310
+    /**
311
+     * @return mixed $value
312
+     */
313
+    public function getPublishStatus() {
314
+        return $this->caldavBackend->getPublishStatus($this);
315
+    }
316
+
317
+    private function canWrite() {
318
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
319
+            return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
320
+        }
321
+        return true;
322
+    }
323
+
324
+    private function isPublic() {
325
+        return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
326
+    }
327
+
328
+    protected function isShared() {
329
+        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
330
+            return false;
331
+        }
332
+
333
+        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
334
+    }
335
+
336
+    public function isSubscription() {
337
+        return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
338
+    }
339 339
 
340 340
 }
Please login to merge, or discard this patch.
apps/dav/lib/Command/SyncBirthdayCalendar.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -34,86 +34,86 @@
 block discarded – undo
34 34
 
35 35
 class SyncBirthdayCalendar extends Command {
36 36
 
37
-	/** @var BirthdayService */
38
-	private $birthdayService;
39
-
40
-	/** @var IConfig */
41
-	private $config;
42
-
43
-	/** @var IUserManager */
44
-	private $userManager;
45
-
46
-	/**
47
-	 * @param IUserManager $userManager
48
-	 * @param IConfig $config
49
-	 * @param BirthdayService $birthdayService
50
-	 */
51
-	function __construct(IUserManager $userManager, IConfig $config,
52
-						 BirthdayService $birthdayService) {
53
-		parent::__construct();
54
-		$this->birthdayService = $birthdayService;
55
-		$this->config = $config;
56
-		$this->userManager = $userManager;
57
-	}
58
-
59
-	protected function configure() {
60
-		$this
61
-			->setName('dav:sync-birthday-calendar')
62
-			->setDescription('Synchronizes the birthday calendar')
63
-			->addArgument('user',
64
-				InputArgument::OPTIONAL,
65
-				'User for whom the birthday calendar will be synchronized');
66
-	}
67
-
68
-	/**
69
-	 * @param InputInterface $input
70
-	 * @param OutputInterface $output
71
-	 */
72
-	protected function execute(InputInterface $input, OutputInterface $output) {
73
-		$this->verifyEnabled();
74
-
75
-		$user = $input->getArgument('user');
76
-		if (!is_null($user)) {
77
-			if (!$this->userManager->userExists($user)) {
78
-				throw new \InvalidArgumentException("User <$user> in unknown.");
79
-			}
80
-
81
-			// re-enable the birthday calendar in case it's called directly with a user name
82
-			$isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes');
83
-			if ($isEnabled !== 'yes') {
84
-				$this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes');
85
-				$output->writeln("Re-enabling birthday calendar for $user");
86
-			}
87
-
88
-			$output->writeln("Start birthday calendar sync for $user");
89
-			$this->birthdayService->syncUser($user);
90
-			return;
91
-		}
92
-		$output->writeln("Start birthday calendar sync for all users ...");
93
-		$p = new ProgressBar($output);
94
-		$p->start();
95
-		$this->userManager->callForAllUsers(function($user) use ($p)  {
96
-			$p->advance();
97
-
98
-			$userId = $user->getUID();
99
-			$isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
100
-			if ($isEnabled !== 'yes') {
101
-				return;
102
-			}
103
-
104
-			/** @var IUser $user */
105
-			$this->birthdayService->syncUser($user->getUID());
106
-		});
107
-
108
-		$p->finish();
109
-		$output->writeln('');
110
-	}
111
-
112
-	protected function verifyEnabled () {
113
-		$isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
114
-
115
-		if ($isEnabled !== 'yes') {
116
-			throw new \InvalidArgumentException('Birthday calendars are disabled');
117
-		}
118
-	}
37
+    /** @var BirthdayService */
38
+    private $birthdayService;
39
+
40
+    /** @var IConfig */
41
+    private $config;
42
+
43
+    /** @var IUserManager */
44
+    private $userManager;
45
+
46
+    /**
47
+     * @param IUserManager $userManager
48
+     * @param IConfig $config
49
+     * @param BirthdayService $birthdayService
50
+     */
51
+    function __construct(IUserManager $userManager, IConfig $config,
52
+                            BirthdayService $birthdayService) {
53
+        parent::__construct();
54
+        $this->birthdayService = $birthdayService;
55
+        $this->config = $config;
56
+        $this->userManager = $userManager;
57
+    }
58
+
59
+    protected function configure() {
60
+        $this
61
+            ->setName('dav:sync-birthday-calendar')
62
+            ->setDescription('Synchronizes the birthday calendar')
63
+            ->addArgument('user',
64
+                InputArgument::OPTIONAL,
65
+                'User for whom the birthday calendar will be synchronized');
66
+    }
67
+
68
+    /**
69
+     * @param InputInterface $input
70
+     * @param OutputInterface $output
71
+     */
72
+    protected function execute(InputInterface $input, OutputInterface $output) {
73
+        $this->verifyEnabled();
74
+
75
+        $user = $input->getArgument('user');
76
+        if (!is_null($user)) {
77
+            if (!$this->userManager->userExists($user)) {
78
+                throw new \InvalidArgumentException("User <$user> in unknown.");
79
+            }
80
+
81
+            // re-enable the birthday calendar in case it's called directly with a user name
82
+            $isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes');
83
+            if ($isEnabled !== 'yes') {
84
+                $this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes');
85
+                $output->writeln("Re-enabling birthday calendar for $user");
86
+            }
87
+
88
+            $output->writeln("Start birthday calendar sync for $user");
89
+            $this->birthdayService->syncUser($user);
90
+            return;
91
+        }
92
+        $output->writeln("Start birthday calendar sync for all users ...");
93
+        $p = new ProgressBar($output);
94
+        $p->start();
95
+        $this->userManager->callForAllUsers(function($user) use ($p)  {
96
+            $p->advance();
97
+
98
+            $userId = $user->getUID();
99
+            $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
100
+            if ($isEnabled !== 'yes') {
101
+                return;
102
+            }
103
+
104
+            /** @var IUser $user */
105
+            $this->birthdayService->syncUser($user->getUID());
106
+        });
107
+
108
+        $p->finish();
109
+        $output->writeln('');
110
+    }
111
+
112
+    protected function verifyEnabled () {
113
+        $isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
114
+
115
+        if ($isEnabled !== 'yes') {
116
+            throw new \InvalidArgumentException('Birthday calendars are disabled');
117
+        }
118
+    }
119 119
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/CalendarHome.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -35,109 +35,109 @@
 block discarded – undo
35 35
 
36 36
 class CalendarHome extends \Sabre\CalDAV\CalendarHome {
37 37
 
38
-	/** @var \OCP\IL10N */
39
-	private $l10n;
40
-
41
-	/** @var \OCP\IConfig */
42
-	private $config;
43
-
44
-	public function __construct(BackendInterface $caldavBackend, $principalInfo) {
45
-		parent::__construct($caldavBackend, $principalInfo);
46
-		$this->l10n = \OC::$server->getL10N('dav');
47
-		$this->config = \OC::$server->getConfig();
48
-	}
49
-
50
-	/**
51
-	 * @return BackendInterface
52
-	 */
53
-	public function getCalDAVBackend() {
54
-		return $this->caldavBackend;
55
-	}
56
-
57
-	/**
58
-	 * @inheritdoc
59
-	 */
60
-	function createExtendedCollection($name, MkCol $mkCol) {
61
-		$reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI];
62
-
63
-		if (in_array($name, $reservedNames)) {
64
-			throw new MethodNotAllowed('The resource you tried to create has a reserved name');
65
-		}
66
-
67
-		parent::createExtendedCollection($name, $mkCol);
68
-	}
69
-
70
-	/**
71
-	 * @inheritdoc
72
-	 */
73
-	function getChildren() {
74
-		$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
75
-		$objects = [];
76
-		foreach ($calendars as $calendar) {
77
-			$objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
78
-		}
79
-
80
-		if ($this->caldavBackend instanceof SchedulingSupport) {
81
-			$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
82
-			$objects[] = new Outbox($this->principalInfo['uri']);
83
-		}
84
-
85
-		// We're adding a notifications node, if it's supported by the backend.
86
-		if ($this->caldavBackend instanceof NotificationSupport) {
87
-			$objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
88
-		}
89
-
90
-		// If the backend supports subscriptions, we'll add those as well,
91
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
92
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
93
-				$objects[] = new Subscription($this->caldavBackend, $subscription);
94
-			}
95
-		}
96
-
97
-		return $objects;
98
-	}
99
-
100
-	/**
101
-	 * @inheritdoc
102
-	 */
103
-	function getChild($name) {
104
-		// Special nodes
105
-		if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
106
-			return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
107
-		}
108
-		if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
109
-			return new Outbox($this->principalInfo['uri']);
110
-		}
111
-		if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
112
-			return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
113
-		}
114
-
115
-		// Calendars
116
-		foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
117
-			if ($calendar['uri'] === $name) {
118
-				return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
119
-			}
120
-		}
121
-
122
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
123
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
124
-				if ($subscription['uri'] === $name) {
125
-					return new Subscription($this->caldavBackend, $subscription);
126
-				}
127
-			}
128
-
129
-		}
130
-
131
-		throw new NotFound('Node with name \'' . $name . '\' could not be found');
132
-	}
133
-
134
-	/**
135
-	 * @param array $filters
136
-	 * @param integer|null $limit
137
-	 * @param integer|null $offset
138
-	 */
139
-	function calendarSearch(array $filters, $limit=null, $offset=null) {
140
-		$principalUri = $this->principalInfo['uri'];
141
-		return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset);
142
-	}
38
+    /** @var \OCP\IL10N */
39
+    private $l10n;
40
+
41
+    /** @var \OCP\IConfig */
42
+    private $config;
43
+
44
+    public function __construct(BackendInterface $caldavBackend, $principalInfo) {
45
+        parent::__construct($caldavBackend, $principalInfo);
46
+        $this->l10n = \OC::$server->getL10N('dav');
47
+        $this->config = \OC::$server->getConfig();
48
+    }
49
+
50
+    /**
51
+     * @return BackendInterface
52
+     */
53
+    public function getCalDAVBackend() {
54
+        return $this->caldavBackend;
55
+    }
56
+
57
+    /**
58
+     * @inheritdoc
59
+     */
60
+    function createExtendedCollection($name, MkCol $mkCol) {
61
+        $reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI];
62
+
63
+        if (in_array($name, $reservedNames)) {
64
+            throw new MethodNotAllowed('The resource you tried to create has a reserved name');
65
+        }
66
+
67
+        parent::createExtendedCollection($name, $mkCol);
68
+    }
69
+
70
+    /**
71
+     * @inheritdoc
72
+     */
73
+    function getChildren() {
74
+        $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
75
+        $objects = [];
76
+        foreach ($calendars as $calendar) {
77
+            $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
78
+        }
79
+
80
+        if ($this->caldavBackend instanceof SchedulingSupport) {
81
+            $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
82
+            $objects[] = new Outbox($this->principalInfo['uri']);
83
+        }
84
+
85
+        // We're adding a notifications node, if it's supported by the backend.
86
+        if ($this->caldavBackend instanceof NotificationSupport) {
87
+            $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
88
+        }
89
+
90
+        // If the backend supports subscriptions, we'll add those as well,
91
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
92
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
93
+                $objects[] = new Subscription($this->caldavBackend, $subscription);
94
+            }
95
+        }
96
+
97
+        return $objects;
98
+    }
99
+
100
+    /**
101
+     * @inheritdoc
102
+     */
103
+    function getChild($name) {
104
+        // Special nodes
105
+        if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
106
+            return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
107
+        }
108
+        if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
109
+            return new Outbox($this->principalInfo['uri']);
110
+        }
111
+        if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
112
+            return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
113
+        }
114
+
115
+        // Calendars
116
+        foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
117
+            if ($calendar['uri'] === $name) {
118
+                return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
119
+            }
120
+        }
121
+
122
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
123
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
124
+                if ($subscription['uri'] === $name) {
125
+                    return new Subscription($this->caldavBackend, $subscription);
126
+                }
127
+            }
128
+
129
+        }
130
+
131
+        throw new NotFound('Node with name \'' . $name . '\' could not be found');
132
+    }
133
+
134
+    /**
135
+     * @param array $filters
136
+     * @param integer|null $limit
137
+     * @param integer|null $offset
138
+     */
139
+    function calendarSearch(array $filters, $limit=null, $offset=null) {
140
+        $principalUri = $this->principalInfo['uri'];
141
+        return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset);
142
+    }
143 143
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/PublicCalendarRoot.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -30,49 +30,49 @@
 block discarded – undo
30 30
 
31 31
 class PublicCalendarRoot extends Collection {
32 32
 
33
-	/** @var CalDavBackend */
34
-	protected $caldavBackend;
33
+    /** @var CalDavBackend */
34
+    protected $caldavBackend;
35 35
 
36
-	/** @var \OCP\IL10N */
37
-	protected $l10n;
36
+    /** @var \OCP\IL10N */
37
+    protected $l10n;
38 38
 
39
-	/** @var \OCP\IConfig */
40
-	protected $config;
39
+    /** @var \OCP\IConfig */
40
+    protected $config;
41 41
 
42
-	/**
43
-	 * PublicCalendarRoot constructor.
44
-	 *
45
-	 * @param CalDavBackend $caldavBackend
46
-	 * @param IL10N $l10n
47
-	 * @param IConfig $config
48
-	 */
49
-	function __construct(CalDavBackend $caldavBackend, IL10N $l10n,
50
-						 IConfig $config) {
51
-		$this->caldavBackend = $caldavBackend;
52
-		$this->l10n = $l10n;
53
-		$this->config = $config;
42
+    /**
43
+     * PublicCalendarRoot constructor.
44
+     *
45
+     * @param CalDavBackend $caldavBackend
46
+     * @param IL10N $l10n
47
+     * @param IConfig $config
48
+     */
49
+    function __construct(CalDavBackend $caldavBackend, IL10N $l10n,
50
+                            IConfig $config) {
51
+        $this->caldavBackend = $caldavBackend;
52
+        $this->l10n = $l10n;
53
+        $this->config = $config;
54 54
 
55
-	}
55
+    }
56 56
 
57
-	/**
58
-	 * @inheritdoc
59
-	 */
60
-	function getName() {
61
-		return 'public-calendars';
62
-	}
57
+    /**
58
+     * @inheritdoc
59
+     */
60
+    function getName() {
61
+        return 'public-calendars';
62
+    }
63 63
 
64
-	/**
65
-	 * @inheritdoc
66
-	 */
67
-	function getChild($name) {
68
-		$calendar = $this->caldavBackend->getPublicCalendar($name);
69
-		return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
70
-	}
64
+    /**
65
+     * @inheritdoc
66
+     */
67
+    function getChild($name) {
68
+        $calendar = $this->caldavBackend->getPublicCalendar($name);
69
+        return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
70
+    }
71 71
 
72
-	/**
73
-	 * @inheritdoc
74
-	 */
75
-	function getChildren() {
76
-		return [];
77
-	}
72
+    /**
73
+     * @inheritdoc
74
+     */
75
+    function getChildren() {
76
+        return [];
77
+    }
78 78
 }
Please login to merge, or discard this patch.
apps/dav/lib/RootCollection.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -37,90 +37,90 @@
 block discarded – undo
37 37
 
38 38
 class RootCollection extends SimpleCollection {
39 39
 
40
-	public function __construct() {
41
-		$config = \OC::$server->getConfig();
42
-		$l10n = \OC::$server->getL10N('dav');
43
-		$random = \OC::$server->getSecureRandom();
44
-		$userManager = \OC::$server->getUserManager();
45
-		$groupManager = \OC::$server->getGroupManager();
46
-		$db = \OC::$server->getDatabaseConnection();
47
-		$dispatcher = \OC::$server->getEventDispatcher();
48
-		$userPrincipalBackend = new Principal(
49
-			$userManager,
50
-			$groupManager
51
-		);
52
-		$groupPrincipalBackend = new GroupPrincipalBackend($groupManager);
53
-		// as soon as debug mode is enabled we allow listing of principals
54
-		$disableListing = !$config->getSystemValue('debug', false);
40
+    public function __construct() {
41
+        $config = \OC::$server->getConfig();
42
+        $l10n = \OC::$server->getL10N('dav');
43
+        $random = \OC::$server->getSecureRandom();
44
+        $userManager = \OC::$server->getUserManager();
45
+        $groupManager = \OC::$server->getGroupManager();
46
+        $db = \OC::$server->getDatabaseConnection();
47
+        $dispatcher = \OC::$server->getEventDispatcher();
48
+        $userPrincipalBackend = new Principal(
49
+            $userManager,
50
+            $groupManager
51
+        );
52
+        $groupPrincipalBackend = new GroupPrincipalBackend($groupManager);
53
+        // as soon as debug mode is enabled we allow listing of principals
54
+        $disableListing = !$config->getSystemValue('debug', false);
55 55
 
56
-		// setup the first level of the dav tree
57
-		$userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
58
-		$userPrincipals->disableListing = $disableListing;
59
-		$groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
60
-		$groupPrincipals->disableListing = $disableListing;
61
-		$systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
62
-		$systemPrincipals->disableListing = $disableListing;
63
-		$filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
64
-		$filesCollection->disableListing = $disableListing;
65
-		$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $dispatcher);
66
-		$calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
67
-		$calendarRoot->disableListing = $disableListing;
68
-		$publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config);
69
-		$publicCalendarRoot->disableListing = $disableListing;
56
+        // setup the first level of the dav tree
57
+        $userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
58
+        $userPrincipals->disableListing = $disableListing;
59
+        $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
60
+        $groupPrincipals->disableListing = $disableListing;
61
+        $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
62
+        $systemPrincipals->disableListing = $disableListing;
63
+        $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
64
+        $filesCollection->disableListing = $disableListing;
65
+        $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $dispatcher);
66
+        $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
67
+        $calendarRoot->disableListing = $disableListing;
68
+        $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config);
69
+        $publicCalendarRoot->disableListing = $disableListing;
70 70
 
71
-		$systemTagCollection = new SystemTag\SystemTagsByIdCollection(
72
-			\OC::$server->getSystemTagManager(),
73
-			\OC::$server->getUserSession(),
74
-			$groupManager
75
-		);
76
-		$systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
77
-			\OC::$server->getSystemTagManager(),
78
-			\OC::$server->getSystemTagObjectMapper(),
79
-			\OC::$server->getUserSession(),
80
-			$groupManager,
81
-			\OC::$server->getEventDispatcher()
82
-		);
83
-		$commentsCollection = new Comments\RootCollection(
84
-			\OC::$server->getCommentsManager(),
85
-			$userManager,
86
-			\OC::$server->getUserSession(),
87
-			\OC::$server->getEventDispatcher(),
88
-			\OC::$server->getLogger()
89
-		);
71
+        $systemTagCollection = new SystemTag\SystemTagsByIdCollection(
72
+            \OC::$server->getSystemTagManager(),
73
+            \OC::$server->getUserSession(),
74
+            $groupManager
75
+        );
76
+        $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
77
+            \OC::$server->getSystemTagManager(),
78
+            \OC::$server->getSystemTagObjectMapper(),
79
+            \OC::$server->getUserSession(),
80
+            $groupManager,
81
+            \OC::$server->getEventDispatcher()
82
+        );
83
+        $commentsCollection = new Comments\RootCollection(
84
+            \OC::$server->getCommentsManager(),
85
+            $userManager,
86
+            \OC::$server->getUserSession(),
87
+            \OC::$server->getEventDispatcher(),
88
+            \OC::$server->getLogger()
89
+        );
90 90
 
91
-		$usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
92
-		$usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users');
93
-		$usersAddressBookRoot->disableListing = $disableListing;
91
+        $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
92
+        $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users');
93
+        $usersAddressBookRoot->disableListing = $disableListing;
94 94
 
95
-		$systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
96
-		$systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system');
97
-		$systemAddressBookRoot->disableListing = $disableListing;
95
+        $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher);
96
+        $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system');
97
+        $systemAddressBookRoot->disableListing = $disableListing;
98 98
 
99
-		$uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users');
100
-		$uploadCollection->disableListing = $disableListing;
99
+        $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users');
100
+        $uploadCollection->disableListing = $disableListing;
101 101
 
102
-		$avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
103
-		$avatarCollection->disableListing = $disableListing;
102
+        $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users');
103
+        $avatarCollection->disableListing = $disableListing;
104 104
 
105
-		$children = [
106
-				new SimpleCollection('principals', [
107
-						$userPrincipals,
108
-						$groupPrincipals,
109
-						$systemPrincipals]),
110
-				$filesCollection,
111
-				$calendarRoot,
112
-				$publicCalendarRoot,
113
-				new SimpleCollection('addressbooks', [
114
-						$usersAddressBookRoot,
115
-						$systemAddressBookRoot]),
116
-				$systemTagCollection,
117
-				$systemTagRelationsCollection,
118
-				$commentsCollection,
119
-				$uploadCollection,
120
-				$avatarCollection
121
-		];
105
+        $children = [
106
+                new SimpleCollection('principals', [
107
+                        $userPrincipals,
108
+                        $groupPrincipals,
109
+                        $systemPrincipals]),
110
+                $filesCollection,
111
+                $calendarRoot,
112
+                $publicCalendarRoot,
113
+                new SimpleCollection('addressbooks', [
114
+                        $usersAddressBookRoot,
115
+                        $systemAddressBookRoot]),
116
+                $systemTagCollection,
117
+                $systemTagRelationsCollection,
118
+                $commentsCollection,
119
+                $uploadCollection,
120
+                $avatarCollection
121
+        ];
122 122
 
123
-		parent::__construct('root', $children);
124
-	}
123
+        parent::__construct('root', $children);
124
+    }
125 125
 
126 126
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/BirthdayService.php 1 patch
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -42,303 +42,303 @@
 block discarded – undo
42 42
 
43 43
 class BirthdayService {
44 44
 
45
-	const BIRTHDAY_CALENDAR_URI = 'contact_birthdays';
45
+    const BIRTHDAY_CALENDAR_URI = 'contact_birthdays';
46 46
 
47
-	/** @var GroupPrincipalBackend */
48
-	private $principalBackend;
47
+    /** @var GroupPrincipalBackend */
48
+    private $principalBackend;
49 49
 
50
-	/** @var CalDavBackend  */
51
-	private $calDavBackEnd;
50
+    /** @var CalDavBackend  */
51
+    private $calDavBackEnd;
52 52
 
53
-	/** @var CardDavBackend  */
54
-	private $cardDavBackEnd;
53
+    /** @var CardDavBackend  */
54
+    private $cardDavBackEnd;
55 55
 
56
-	/** @var IConfig */
57
-	private $config;
56
+    /** @var IConfig */
57
+    private $config;
58 58
 
59
-	/**
60
-	 * BirthdayService constructor.
61
-	 *
62
-	 * @param CalDavBackend $calDavBackEnd
63
-	 * @param CardDavBackend $cardDavBackEnd
64
-	 * @param GroupPrincipalBackend $principalBackend
65
-	 * @param IConfig $config;
66
-	 */
67
-	public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, GroupPrincipalBackend $principalBackend, IConfig $config) {
68
-		$this->calDavBackEnd = $calDavBackEnd;
69
-		$this->cardDavBackEnd = $cardDavBackEnd;
70
-		$this->principalBackend = $principalBackend;
71
-		$this->config = $config;
72
-	}
59
+    /**
60
+     * BirthdayService constructor.
61
+     *
62
+     * @param CalDavBackend $calDavBackEnd
63
+     * @param CardDavBackend $cardDavBackEnd
64
+     * @param GroupPrincipalBackend $principalBackend
65
+     * @param IConfig $config;
66
+     */
67
+    public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, GroupPrincipalBackend $principalBackend, IConfig $config) {
68
+        $this->calDavBackEnd = $calDavBackEnd;
69
+        $this->cardDavBackEnd = $cardDavBackEnd;
70
+        $this->principalBackend = $principalBackend;
71
+        $this->config = $config;
72
+    }
73 73
 
74
-	/**
75
-	 * @param int $addressBookId
76
-	 * @param string $cardUri
77
-	 * @param string $cardData
78
-	 */
79
-	public function onCardChanged($addressBookId, $cardUri, $cardData) {
80
-		if (!$this->isGloballyEnabled()) {
81
-			return;
82
-		}
74
+    /**
75
+     * @param int $addressBookId
76
+     * @param string $cardUri
77
+     * @param string $cardData
78
+     */
79
+    public function onCardChanged($addressBookId, $cardUri, $cardData) {
80
+        if (!$this->isGloballyEnabled()) {
81
+            return;
82
+        }
83 83
 
84
-		$targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
85
-		$book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
86
-		$targetPrincipals[] = $book['principaluri'];
87
-		$datesToSync = [
88
-			['postfix' => '', 'field' => 'BDAY', 'symbol' => '*'],
89
-			['postfix' => '-death', 'field' => 'DEATHDATE', 'symbol' => "†"],
90
-			['postfix' => '-anniversary', 'field' => 'ANNIVERSARY', 'symbol' => "⚭"],
91
-		];
92
-		foreach ($targetPrincipals as $principalUri) {
93
-			if (!$this->isUserEnabled($principalUri)) {
94
-				continue;
95
-			}
84
+        $targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
85
+        $book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
86
+        $targetPrincipals[] = $book['principaluri'];
87
+        $datesToSync = [
88
+            ['postfix' => '', 'field' => 'BDAY', 'symbol' => '*'],
89
+            ['postfix' => '-death', 'field' => 'DEATHDATE', 'symbol' => "†"],
90
+            ['postfix' => '-anniversary', 'field' => 'ANNIVERSARY', 'symbol' => "⚭"],
91
+        ];
92
+        foreach ($targetPrincipals as $principalUri) {
93
+            if (!$this->isUserEnabled($principalUri)) {
94
+                continue;
95
+            }
96 96
 
97
-			$calendar = $this->ensureCalendarExists($principalUri);
98
-			foreach ($datesToSync as $type) {
99
-				$this->updateCalendar($cardUri, $cardData, $book, $calendar['id'], $type);
100
-			}
101
-		}
102
-	}
97
+            $calendar = $this->ensureCalendarExists($principalUri);
98
+            foreach ($datesToSync as $type) {
99
+                $this->updateCalendar($cardUri, $cardData, $book, $calendar['id'], $type);
100
+            }
101
+        }
102
+    }
103 103
 
104
-	/**
105
-	 * @param int $addressBookId
106
-	 * @param string $cardUri
107
-	 */
108
-	public function onCardDeleted($addressBookId, $cardUri) {
109
-		if (!$this->isGloballyEnabled()) {
110
-			return;
111
-		}
104
+    /**
105
+     * @param int $addressBookId
106
+     * @param string $cardUri
107
+     */
108
+    public function onCardDeleted($addressBookId, $cardUri) {
109
+        if (!$this->isGloballyEnabled()) {
110
+            return;
111
+        }
112 112
 
113
-		$targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
114
-		$book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
115
-		$targetPrincipals[] = $book['principaluri'];
116
-		foreach ($targetPrincipals as $principalUri) {
117
-			if (!$this->isUserEnabled($principalUri)) {
118
-				continue;
119
-			}
113
+        $targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
114
+        $book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
115
+        $targetPrincipals[] = $book['principaluri'];
116
+        foreach ($targetPrincipals as $principalUri) {
117
+            if (!$this->isUserEnabled($principalUri)) {
118
+                continue;
119
+            }
120 120
 
121
-			$calendar = $this->ensureCalendarExists($principalUri);
122
-			foreach (['', '-death', '-anniversary'] as $tag) {
123
-				$objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics';
124
-				$this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri);
125
-			}
126
-		}
127
-	}
121
+            $calendar = $this->ensureCalendarExists($principalUri);
122
+            foreach (['', '-death', '-anniversary'] as $tag) {
123
+                $objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics';
124
+                $this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri);
125
+            }
126
+        }
127
+    }
128 128
 
129
-	/**
130
-	 * @param string $principal
131
-	 * @return array|null
132
-	 * @throws \Sabre\DAV\Exception\BadRequest
133
-	 */
134
-	public function ensureCalendarExists($principal) {
135
-		$book = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
136
-		if (!is_null($book)) {
137
-			return $book;
138
-		}
139
-		$this->calDavBackEnd->createCalendar($principal, self::BIRTHDAY_CALENDAR_URI, [
140
-			'{DAV:}displayname' => 'Contact birthdays',
141
-			'{http://apple.com/ns/ical/}calendar-color' => '#FFFFCA',
142
-			'components'   => 'VEVENT',
143
-		]);
129
+    /**
130
+     * @param string $principal
131
+     * @return array|null
132
+     * @throws \Sabre\DAV\Exception\BadRequest
133
+     */
134
+    public function ensureCalendarExists($principal) {
135
+        $book = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
136
+        if (!is_null($book)) {
137
+            return $book;
138
+        }
139
+        $this->calDavBackEnd->createCalendar($principal, self::BIRTHDAY_CALENDAR_URI, [
140
+            '{DAV:}displayname' => 'Contact birthdays',
141
+            '{http://apple.com/ns/ical/}calendar-color' => '#FFFFCA',
142
+            'components'   => 'VEVENT',
143
+        ]);
144 144
 
145
-		return $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
146
-	}
145
+        return $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
146
+    }
147 147
 
148
-	/**
149
-	 * @param string $cardData
150
-	 * @param string $dateField
151
-	 * @param string $summarySymbol
152
-	 * @return null|VCalendar
153
-	 */
154
-	public function buildDateFromContact($cardData, $dateField, $summarySymbol) {
155
-		if (empty($cardData)) {
156
-			return null;
157
-		}
158
-		try {
159
-			$doc = Reader::read($cardData);
160
-			// We're always converting to vCard 4.0 so we can rely on the
161
-			// VCardConverter handling the X-APPLE-OMIT-YEAR property for us.
162
-			if (!$doc instanceof VCard) {
163
-				return null;
164
-			}
165
-			$doc = $doc->convert(Document::VCARD40);
166
-		} catch (Exception $e) {
167
-			return null;
168
-		}
148
+    /**
149
+     * @param string $cardData
150
+     * @param string $dateField
151
+     * @param string $summarySymbol
152
+     * @return null|VCalendar
153
+     */
154
+    public function buildDateFromContact($cardData, $dateField, $summarySymbol) {
155
+        if (empty($cardData)) {
156
+            return null;
157
+        }
158
+        try {
159
+            $doc = Reader::read($cardData);
160
+            // We're always converting to vCard 4.0 so we can rely on the
161
+            // VCardConverter handling the X-APPLE-OMIT-YEAR property for us.
162
+            if (!$doc instanceof VCard) {
163
+                return null;
164
+            }
165
+            $doc = $doc->convert(Document::VCARD40);
166
+        } catch (Exception $e) {
167
+            return null;
168
+        }
169 169
 
170
-		if (!isset($doc->{$dateField})) {
171
-			return null;
172
-		}
173
-		if (!isset($doc->FN)) {
174
-			return null;
175
-		}
176
-		$birthday = $doc->{$dateField};
177
-		if (!(string)$birthday) {
178
-			return null;
179
-		}
180
-		// Skip if the BDAY property is not of the right type.
181
-		if (!$birthday instanceof DateAndOrTime) {
182
-			return null;
183
-		}
170
+        if (!isset($doc->{$dateField})) {
171
+            return null;
172
+        }
173
+        if (!isset($doc->FN)) {
174
+            return null;
175
+        }
176
+        $birthday = $doc->{$dateField};
177
+        if (!(string)$birthday) {
178
+            return null;
179
+        }
180
+        // Skip if the BDAY property is not of the right type.
181
+        if (!$birthday instanceof DateAndOrTime) {
182
+            return null;
183
+        }
184 184
 
185
-		// Skip if we can't parse the BDAY value.
186
-		try {
187
-			$dateParts = DateTimeParser::parseVCardDateTime($birthday->getValue());
188
-		} catch (InvalidDataException $e) {
189
-			return null;
190
-		}
185
+        // Skip if we can't parse the BDAY value.
186
+        try {
187
+            $dateParts = DateTimeParser::parseVCardDateTime($birthday->getValue());
188
+        } catch (InvalidDataException $e) {
189
+            return null;
190
+        }
191 191
 
192
-		$unknownYear = false;
193
-		if (!$dateParts['year']) {
194
-			$birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];
192
+        $unknownYear = false;
193
+        if (!$dateParts['year']) {
194
+            $birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];
195 195
 
196
-			$unknownYear = true;
197
-		}
196
+            $unknownYear = true;
197
+        }
198 198
 
199
-		try {
200
-			$date = new \DateTime($birthday);
201
-		} catch (Exception $e) {
202
-			return null;
203
-		}
204
-		if ($unknownYear) {
205
-			$summary = $doc->FN->getValue() . ' ' . $summarySymbol;
206
-		} else {
207
-			$year = (int)$date->format('Y');
208
-			$summary = $doc->FN->getValue() . " ($summarySymbol$year)";
209
-		}
210
-		$vCal = new VCalendar();
211
-		$vCal->VERSION = '2.0';
212
-		$vEvent = $vCal->createComponent('VEVENT');
213
-		$vEvent->add('DTSTART');
214
-		$vEvent->DTSTART->setDateTime(
215
-			$date
216
-		);
217
-		$vEvent->DTSTART['VALUE'] = 'DATE';
218
-		$vEvent->add('DTEND');
219
-		$date->add(new \DateInterval('P1D'));
220
-		$vEvent->DTEND->setDateTime(
221
-			$date
222
-		);
223
-		$vEvent->DTEND['VALUE'] = 'DATE';
224
-		$vEvent->{'UID'} = $doc->UID;
225
-		$vEvent->{'RRULE'} = 'FREQ=YEARLY';
226
-		$vEvent->{'SUMMARY'} = $summary;
227
-		$vEvent->{'TRANSP'} = 'TRANSPARENT';
228
-		$alarm = $vCal->createComponent('VALARM');
229
-		$alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION']));
230
-		$alarm->add($vCal->createProperty('ACTION', 'DISPLAY'));
231
-		$alarm->add($vCal->createProperty('DESCRIPTION', $vEvent->{'SUMMARY'}));
232
-		$vEvent->add($alarm);
233
-		$vCal->add($vEvent);
234
-		return $vCal;
235
-	}
199
+        try {
200
+            $date = new \DateTime($birthday);
201
+        } catch (Exception $e) {
202
+            return null;
203
+        }
204
+        if ($unknownYear) {
205
+            $summary = $doc->FN->getValue() . ' ' . $summarySymbol;
206
+        } else {
207
+            $year = (int)$date->format('Y');
208
+            $summary = $doc->FN->getValue() . " ($summarySymbol$year)";
209
+        }
210
+        $vCal = new VCalendar();
211
+        $vCal->VERSION = '2.0';
212
+        $vEvent = $vCal->createComponent('VEVENT');
213
+        $vEvent->add('DTSTART');
214
+        $vEvent->DTSTART->setDateTime(
215
+            $date
216
+        );
217
+        $vEvent->DTSTART['VALUE'] = 'DATE';
218
+        $vEvent->add('DTEND');
219
+        $date->add(new \DateInterval('P1D'));
220
+        $vEvent->DTEND->setDateTime(
221
+            $date
222
+        );
223
+        $vEvent->DTEND['VALUE'] = 'DATE';
224
+        $vEvent->{'UID'} = $doc->UID;
225
+        $vEvent->{'RRULE'} = 'FREQ=YEARLY';
226
+        $vEvent->{'SUMMARY'} = $summary;
227
+        $vEvent->{'TRANSP'} = 'TRANSPARENT';
228
+        $alarm = $vCal->createComponent('VALARM');
229
+        $alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION']));
230
+        $alarm->add($vCal->createProperty('ACTION', 'DISPLAY'));
231
+        $alarm->add($vCal->createProperty('DESCRIPTION', $vEvent->{'SUMMARY'}));
232
+        $vEvent->add($alarm);
233
+        $vCal->add($vEvent);
234
+        return $vCal;
235
+    }
236 236
 
237
-	/**
238
-	 * @param string $user
239
-	 */
240
-	public function syncUser($user) {
241
-		$principal = 'principals/users/'.$user;
242
-		$this->ensureCalendarExists($principal);
243
-		$books = $this->cardDavBackEnd->getAddressBooksForUser($principal);
244
-		foreach($books as $book) {
245
-			$cards = $this->cardDavBackEnd->getCards($book['id']);
246
-			foreach($cards as $card) {
247
-				$this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
248
-			}
249
-		}
250
-	}
237
+    /**
238
+     * @param string $user
239
+     */
240
+    public function syncUser($user) {
241
+        $principal = 'principals/users/'.$user;
242
+        $this->ensureCalendarExists($principal);
243
+        $books = $this->cardDavBackEnd->getAddressBooksForUser($principal);
244
+        foreach($books as $book) {
245
+            $cards = $this->cardDavBackEnd->getCards($book['id']);
246
+            foreach($cards as $card) {
247
+                $this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
248
+            }
249
+        }
250
+    }
251 251
 
252
-	/**
253
-	 * @param string $existingCalendarData
254
-	 * @param VCalendar $newCalendarData
255
-	 * @return bool
256
-	 */
257
-	public function birthdayEvenChanged($existingCalendarData, $newCalendarData) {
258
-		try {
259
-			$existingBirthday = Reader::read($existingCalendarData);
260
-		} catch (Exception $ex) {
261
-			return true;
262
-		}
263
-		if ($newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() ||
264
-			$newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue()
265
-		) {
266
-			return true;
267
-		}
268
-		return false;
269
-	}
252
+    /**
253
+     * @param string $existingCalendarData
254
+     * @param VCalendar $newCalendarData
255
+     * @return bool
256
+     */
257
+    public function birthdayEvenChanged($existingCalendarData, $newCalendarData) {
258
+        try {
259
+            $existingBirthday = Reader::read($existingCalendarData);
260
+        } catch (Exception $ex) {
261
+            return true;
262
+        }
263
+        if ($newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() ||
264
+            $newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue()
265
+        ) {
266
+            return true;
267
+        }
268
+        return false;
269
+    }
270 270
 
271
-	/**
272
-	 * @param integer $addressBookId
273
-	 * @return mixed
274
-	 */
275
-	protected function getAllAffectedPrincipals($addressBookId) {
276
-		$targetPrincipals = [];
277
-		$shares = $this->cardDavBackEnd->getShares($addressBookId);
278
-		foreach ($shares as $share) {
279
-			if ($share['{http://owncloud.org/ns}group-share']) {
280
-				$users = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']);
281
-				foreach ($users as $user) {
282
-					$targetPrincipals[] = $user['uri'];
283
-				}
284
-			} else {
285
-				$targetPrincipals[] = $share['{http://owncloud.org/ns}principal'];
286
-			}
287
-		}
288
-		return array_values(array_unique($targetPrincipals, SORT_STRING));
289
-	}
271
+    /**
272
+     * @param integer $addressBookId
273
+     * @return mixed
274
+     */
275
+    protected function getAllAffectedPrincipals($addressBookId) {
276
+        $targetPrincipals = [];
277
+        $shares = $this->cardDavBackEnd->getShares($addressBookId);
278
+        foreach ($shares as $share) {
279
+            if ($share['{http://owncloud.org/ns}group-share']) {
280
+                $users = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']);
281
+                foreach ($users as $user) {
282
+                    $targetPrincipals[] = $user['uri'];
283
+                }
284
+            } else {
285
+                $targetPrincipals[] = $share['{http://owncloud.org/ns}principal'];
286
+            }
287
+        }
288
+        return array_values(array_unique($targetPrincipals, SORT_STRING));
289
+    }
290 290
 
291
-	/**
292
-	 * @param string $cardUri
293
-	 * @param string  $cardData
294
-	 * @param array $book
295
-	 * @param int $calendarId
296
-	 * @param string[] $type
297
-	 */
298
-	private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
299
-		$objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
300
-		$calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['symbol']);
301
-		$existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
302
-		if (is_null($calendarData)) {
303
-			if (!is_null($existing)) {
304
-				$this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri);
305
-			}
306
-		} else {
307
-			if (is_null($existing)) {
308
-				$this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize());
309
-			} else {
310
-				if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) {
311
-					$this->calDavBackEnd->updateCalendarObject($calendarId, $objectUri, $calendarData->serialize());
312
-				}
313
-			}
314
-		}
315
-	}
291
+    /**
292
+     * @param string $cardUri
293
+     * @param string  $cardData
294
+     * @param array $book
295
+     * @param int $calendarId
296
+     * @param string[] $type
297
+     */
298
+    private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
299
+        $objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
300
+        $calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['symbol']);
301
+        $existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
302
+        if (is_null($calendarData)) {
303
+            if (!is_null($existing)) {
304
+                $this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri);
305
+            }
306
+        } else {
307
+            if (is_null($existing)) {
308
+                $this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize());
309
+            } else {
310
+                if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) {
311
+                    $this->calDavBackEnd->updateCalendarObject($calendarId, $objectUri, $calendarData->serialize());
312
+                }
313
+            }
314
+        }
315
+    }
316 316
 
317
-	/**
318
-	 * checks if the admin opted-out of birthday calendars
319
-	 *
320
-	 * @return bool
321
-	 */
322
-	private function isGloballyEnabled() {
323
-		$isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
324
-		return $isGloballyEnabled === 'yes';
325
-	}
317
+    /**
318
+     * checks if the admin opted-out of birthday calendars
319
+     *
320
+     * @return bool
321
+     */
322
+    private function isGloballyEnabled() {
323
+        $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
324
+        return $isGloballyEnabled === 'yes';
325
+    }
326 326
 
327
-	/**
328
-	 * checks if the user opted-out of birthday calendars
329
-	 *
330
-	 * @param $userPrincipal
331
-	 * @return bool
332
-	 */
333
-	private function isUserEnabled($userPrincipal) {
334
-		if (strpos($userPrincipal, 'principals/users/') === 0) {
335
-			$userId = substr($userPrincipal, 17);
336
-			$isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
337
-			return $isEnabled === 'yes';
338
-		}
327
+    /**
328
+     * checks if the user opted-out of birthday calendars
329
+     *
330
+     * @param $userPrincipal
331
+     * @return bool
332
+     */
333
+    private function isUserEnabled($userPrincipal) {
334
+        if (strpos($userPrincipal, 'principals/users/') === 0) {
335
+            $userId = substr($userPrincipal, 17);
336
+            $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
337
+            return $isEnabled === 'yes';
338
+        }
339 339
 
340
-		// not sure how we got here, just be on the safe side and return true
341
-		return true;
342
-	}
340
+        // not sure how we got here, just be on the safe side and return true
341
+        return true;
342
+    }
343 343
 
344 344
 }
Please login to merge, or discard this patch.