Completed
Pull Request — master (#7707)
by Georg
55:12
created
apps/dav/lib/CalDAV/BirthdayService.php 2 patches
Indentation   +273 added lines, -273 removed lines patch added patch discarded remove patch
@@ -42,304 +42,304 @@
 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 $postfix
152
-	 * @param string $summarySymbol
153
-	 * @return null|VCalendar
154
-	 */
155
-	public function buildDateFromContact($cardData, $dateField, $postfix, $summarySymbol) {
156
-		if (empty($cardData)) {
157
-			return null;
158
-		}
159
-		try {
160
-			$doc = Reader::read($cardData);
161
-			// We're always converting to vCard 4.0 so we can rely on the
162
-			// VCardConverter handling the X-APPLE-OMIT-YEAR property for us.
163
-			if (!$doc instanceof VCard) {
164
-				return null;
165
-			}
166
-			$doc = $doc->convert(Document::VCARD40);
167
-		} catch (Exception $e) {
168
-			return null;
169
-		}
148
+    /**
149
+     * @param string $cardData
150
+     * @param string $dateField
151
+     * @param string $postfix
152
+     * @param string $summarySymbol
153
+     * @return null|VCalendar
154
+     */
155
+    public function buildDateFromContact($cardData, $dateField, $postfix, $summarySymbol) {
156
+        if (empty($cardData)) {
157
+            return null;
158
+        }
159
+        try {
160
+            $doc = Reader::read($cardData);
161
+            // We're always converting to vCard 4.0 so we can rely on the
162
+            // VCardConverter handling the X-APPLE-OMIT-YEAR property for us.
163
+            if (!$doc instanceof VCard) {
164
+                return null;
165
+            }
166
+            $doc = $doc->convert(Document::VCARD40);
167
+        } catch (Exception $e) {
168
+            return null;
169
+        }
170 170
 
171
-		if (!isset($doc->{$dateField})) {
172
-			return null;
173
-		}
174
-		if (!isset($doc->FN)) {
175
-			return null;
176
-		}
177
-		$birthday = $doc->{$dateField};
178
-		if (!(string)$birthday) {
179
-			return null;
180
-		}
181
-		// Skip if the BDAY property is not of the right type.
182
-		if (!$birthday instanceof DateAndOrTime) {
183
-			return null;
184
-		}
171
+        if (!isset($doc->{$dateField})) {
172
+            return null;
173
+        }
174
+        if (!isset($doc->FN)) {
175
+            return null;
176
+        }
177
+        $birthday = $doc->{$dateField};
178
+        if (!(string)$birthday) {
179
+            return null;
180
+        }
181
+        // Skip if the BDAY property is not of the right type.
182
+        if (!$birthday instanceof DateAndOrTime) {
183
+            return null;
184
+        }
185 185
 
186
-		// Skip if we can't parse the BDAY value.
187
-		try {
188
-			$dateParts = DateTimeParser::parseVCardDateTime($birthday->getValue());
189
-		} catch (InvalidDataException $e) {
190
-			return null;
191
-		}
186
+        // Skip if we can't parse the BDAY value.
187
+        try {
188
+            $dateParts = DateTimeParser::parseVCardDateTime($birthday->getValue());
189
+        } catch (InvalidDataException $e) {
190
+            return null;
191
+        }
192 192
 
193
-		$unknownYear = false;
194
-		if (!$dateParts['year']) {
195
-			$birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];
193
+        $unknownYear = false;
194
+        if (!$dateParts['year']) {
195
+            $birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];
196 196
 
197
-			$unknownYear = true;
198
-		}
197
+            $unknownYear = true;
198
+        }
199 199
 
200
-		try {
201
-			$date = new \DateTime($birthday);
202
-		} catch (Exception $e) {
203
-			return null;
204
-		}
205
-		if ($unknownYear) {
206
-			$summary = $doc->FN->getValue() . ' ' . $summarySymbol;
207
-		} else {
208
-			$year = (int)$date->format('Y');
209
-			$summary = $doc->FN->getValue() . " ($summarySymbol$year)";
210
-		}
211
-		$vCal = new VCalendar();
212
-		$vCal->VERSION = '2.0';
213
-		$vEvent = $vCal->createComponent('VEVENT');
214
-		$vEvent->add('DTSTART');
215
-		$vEvent->DTSTART->setDateTime(
216
-			$date
217
-		);
218
-		$vEvent->DTSTART['VALUE'] = 'DATE';
219
-		$vEvent->add('DTEND');
220
-		$date->add(new \DateInterval('P1D'));
221
-		$vEvent->DTEND->setDateTime(
222
-			$date
223
-		);
224
-		$vEvent->DTEND['VALUE'] = 'DATE';
225
-		$vEvent->{'UID'} = $doc->UID . $postfix;
226
-		$vEvent->{'RRULE'} = 'FREQ=YEARLY';
227
-		$vEvent->{'SUMMARY'} = $summary;
228
-		$vEvent->{'TRANSP'} = 'TRANSPARENT';
229
-		$alarm = $vCal->createComponent('VALARM');
230
-		$alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION']));
231
-		$alarm->add($vCal->createProperty('ACTION', 'DISPLAY'));
232
-		$alarm->add($vCal->createProperty('DESCRIPTION', $vEvent->{'SUMMARY'}));
233
-		$vEvent->add($alarm);
234
-		$vCal->add($vEvent);
235
-		return $vCal;
236
-	}
200
+        try {
201
+            $date = new \DateTime($birthday);
202
+        } catch (Exception $e) {
203
+            return null;
204
+        }
205
+        if ($unknownYear) {
206
+            $summary = $doc->FN->getValue() . ' ' . $summarySymbol;
207
+        } else {
208
+            $year = (int)$date->format('Y');
209
+            $summary = $doc->FN->getValue() . " ($summarySymbol$year)";
210
+        }
211
+        $vCal = new VCalendar();
212
+        $vCal->VERSION = '2.0';
213
+        $vEvent = $vCal->createComponent('VEVENT');
214
+        $vEvent->add('DTSTART');
215
+        $vEvent->DTSTART->setDateTime(
216
+            $date
217
+        );
218
+        $vEvent->DTSTART['VALUE'] = 'DATE';
219
+        $vEvent->add('DTEND');
220
+        $date->add(new \DateInterval('P1D'));
221
+        $vEvent->DTEND->setDateTime(
222
+            $date
223
+        );
224
+        $vEvent->DTEND['VALUE'] = 'DATE';
225
+        $vEvent->{'UID'} = $doc->UID . $postfix;
226
+        $vEvent->{'RRULE'} = 'FREQ=YEARLY';
227
+        $vEvent->{'SUMMARY'} = $summary;
228
+        $vEvent->{'TRANSP'} = 'TRANSPARENT';
229
+        $alarm = $vCal->createComponent('VALARM');
230
+        $alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION']));
231
+        $alarm->add($vCal->createProperty('ACTION', 'DISPLAY'));
232
+        $alarm->add($vCal->createProperty('DESCRIPTION', $vEvent->{'SUMMARY'}));
233
+        $vEvent->add($alarm);
234
+        $vCal->add($vEvent);
235
+        return $vCal;
236
+    }
237 237
 
238
-	/**
239
-	 * @param string $user
240
-	 */
241
-	public function syncUser($user) {
242
-		$principal = 'principals/users/'.$user;
243
-		$this->ensureCalendarExists($principal);
244
-		$books = $this->cardDavBackEnd->getAddressBooksForUser($principal);
245
-		foreach($books as $book) {
246
-			$cards = $this->cardDavBackEnd->getCards($book['id']);
247
-			foreach($cards as $card) {
248
-				$this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
249
-			}
250
-		}
251
-	}
238
+    /**
239
+     * @param string $user
240
+     */
241
+    public function syncUser($user) {
242
+        $principal = 'principals/users/'.$user;
243
+        $this->ensureCalendarExists($principal);
244
+        $books = $this->cardDavBackEnd->getAddressBooksForUser($principal);
245
+        foreach($books as $book) {
246
+            $cards = $this->cardDavBackEnd->getCards($book['id']);
247
+            foreach($cards as $card) {
248
+                $this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
249
+            }
250
+        }
251
+    }
252 252
 
253
-	/**
254
-	 * @param string $existingCalendarData
255
-	 * @param VCalendar $newCalendarData
256
-	 * @return bool
257
-	 */
258
-	public function birthdayEvenChanged($existingCalendarData, $newCalendarData) {
259
-		try {
260
-			$existingBirthday = Reader::read($existingCalendarData);
261
-		} catch (Exception $ex) {
262
-			return true;
263
-		}
264
-		if ($newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() ||
265
-			$newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue()
266
-		) {
267
-			return true;
268
-		}
269
-		return false;
270
-	}
253
+    /**
254
+     * @param string $existingCalendarData
255
+     * @param VCalendar $newCalendarData
256
+     * @return bool
257
+     */
258
+    public function birthdayEvenChanged($existingCalendarData, $newCalendarData) {
259
+        try {
260
+            $existingBirthday = Reader::read($existingCalendarData);
261
+        } catch (Exception $ex) {
262
+            return true;
263
+        }
264
+        if ($newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() ||
265
+            $newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue()
266
+        ) {
267
+            return true;
268
+        }
269
+        return false;
270
+    }
271 271
 
272
-	/**
273
-	 * @param integer $addressBookId
274
-	 * @return mixed
275
-	 */
276
-	protected function getAllAffectedPrincipals($addressBookId) {
277
-		$targetPrincipals = [];
278
-		$shares = $this->cardDavBackEnd->getShares($addressBookId);
279
-		foreach ($shares as $share) {
280
-			if ($share['{http://owncloud.org/ns}group-share']) {
281
-				$users = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']);
282
-				foreach ($users as $user) {
283
-					$targetPrincipals[] = $user['uri'];
284
-				}
285
-			} else {
286
-				$targetPrincipals[] = $share['{http://owncloud.org/ns}principal'];
287
-			}
288
-		}
289
-		return array_values(array_unique($targetPrincipals, SORT_STRING));
290
-	}
272
+    /**
273
+     * @param integer $addressBookId
274
+     * @return mixed
275
+     */
276
+    protected function getAllAffectedPrincipals($addressBookId) {
277
+        $targetPrincipals = [];
278
+        $shares = $this->cardDavBackEnd->getShares($addressBookId);
279
+        foreach ($shares as $share) {
280
+            if ($share['{http://owncloud.org/ns}group-share']) {
281
+                $users = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']);
282
+                foreach ($users as $user) {
283
+                    $targetPrincipals[] = $user['uri'];
284
+                }
285
+            } else {
286
+                $targetPrincipals[] = $share['{http://owncloud.org/ns}principal'];
287
+            }
288
+        }
289
+        return array_values(array_unique($targetPrincipals, SORT_STRING));
290
+    }
291 291
 
292
-	/**
293
-	 * @param string $cardUri
294
-	 * @param string  $cardData
295
-	 * @param array $book
296
-	 * @param int $calendarId
297
-	 * @param string[] $type
298
-	 */
299
-	private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
300
-		$objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
301
-		$calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['postfix'], $type['symbol']);
302
-		$existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
303
-		if (is_null($calendarData)) {
304
-			if (!is_null($existing)) {
305
-				$this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri);
306
-			}
307
-		} else {
308
-			if (is_null($existing)) {
309
-				$this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize());
310
-			} else {
311
-				if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) {
312
-					$this->calDavBackEnd->updateCalendarObject($calendarId, $objectUri, $calendarData->serialize());
313
-				}
314
-			}
315
-		}
316
-	}
292
+    /**
293
+     * @param string $cardUri
294
+     * @param string  $cardData
295
+     * @param array $book
296
+     * @param int $calendarId
297
+     * @param string[] $type
298
+     */
299
+    private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
300
+        $objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
301
+        $calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['postfix'], $type['symbol']);
302
+        $existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
303
+        if (is_null($calendarData)) {
304
+            if (!is_null($existing)) {
305
+                $this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri);
306
+            }
307
+        } else {
308
+            if (is_null($existing)) {
309
+                $this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize());
310
+            } else {
311
+                if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) {
312
+                    $this->calDavBackEnd->updateCalendarObject($calendarId, $objectUri, $calendarData->serialize());
313
+                }
314
+            }
315
+        }
316
+    }
317 317
 
318
-	/**
319
-	 * checks if the admin opted-out of birthday calendars
320
-	 *
321
-	 * @return bool
322
-	 */
323
-	private function isGloballyEnabled() {
324
-		$isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
325
-		return $isGloballyEnabled === 'yes';
326
-	}
318
+    /**
319
+     * checks if the admin opted-out of birthday calendars
320
+     *
321
+     * @return bool
322
+     */
323
+    private function isGloballyEnabled() {
324
+        $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
325
+        return $isGloballyEnabled === 'yes';
326
+    }
327 327
 
328
-	/**
329
-	 * checks if the user opted-out of birthday calendars
330
-	 *
331
-	 * @param $userPrincipal
332
-	 * @return bool
333
-	 */
334
-	private function isUserEnabled($userPrincipal) {
335
-		if (strpos($userPrincipal, 'principals/users/') === 0) {
336
-			$userId = substr($userPrincipal, 17);
337
-			$isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
338
-			return $isEnabled === 'yes';
339
-		}
328
+    /**
329
+     * checks if the user opted-out of birthday calendars
330
+     *
331
+     * @param $userPrincipal
332
+     * @return bool
333
+     */
334
+    private function isUserEnabled($userPrincipal) {
335
+        if (strpos($userPrincipal, 'principals/users/') === 0) {
336
+            $userId = substr($userPrincipal, 17);
337
+            $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
338
+            return $isEnabled === 'yes';
339
+        }
340 340
 
341
-		// not sure how we got here, just be on the safe side and return true
342
-		return true;
343
-	}
341
+        // not sure how we got here, just be on the safe side and return true
342
+        return true;
343
+    }
344 344
 
345 345
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
 			$calendar = $this->ensureCalendarExists($principalUri);
122 122
 			foreach (['', '-death', '-anniversary'] as $tag) {
123
-				$objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics';
123
+				$objectUri = $book['uri'].'-'.$cardUri.$tag.'.ics';
124 124
 				$this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri);
125 125
 			}
126 126
 		}
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 			return null;
176 176
 		}
177 177
 		$birthday = $doc->{$dateField};
178
-		if (!(string)$birthday) {
178
+		if (!(string) $birthday) {
179 179
 			return null;
180 180
 		}
181 181
 		// Skip if the BDAY property is not of the right type.
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
 		$unknownYear = false;
194 194
 		if (!$dateParts['year']) {
195
-			$birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];
195
+			$birthday = '1900-'.$dateParts['month'].'-'.$dateParts['date'];
196 196
 
197 197
 			$unknownYear = true;
198 198
 		}
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
 			return null;
204 204
 		}
205 205
 		if ($unknownYear) {
206
-			$summary = $doc->FN->getValue() . ' ' . $summarySymbol;
206
+			$summary = $doc->FN->getValue().' '.$summarySymbol;
207 207
 		} else {
208
-			$year = (int)$date->format('Y');
209
-			$summary = $doc->FN->getValue() . " ($summarySymbol$year)";
208
+			$year = (int) $date->format('Y');
209
+			$summary = $doc->FN->getValue()." ($summarySymbol$year)";
210 210
 		}
211 211
 		$vCal = new VCalendar();
212 212
 		$vCal->VERSION = '2.0';
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 			$date
223 223
 		);
224 224
 		$vEvent->DTEND['VALUE'] = 'DATE';
225
-		$vEvent->{'UID'} = $doc->UID . $postfix;
225
+		$vEvent->{'UID'} = $doc->UID.$postfix;
226 226
 		$vEvent->{'RRULE'} = 'FREQ=YEARLY';
227 227
 		$vEvent->{'SUMMARY'} = $summary;
228 228
 		$vEvent->{'TRANSP'} = 'TRANSPARENT';
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
 		$principal = 'principals/users/'.$user;
243 243
 		$this->ensureCalendarExists($principal);
244 244
 		$books = $this->cardDavBackEnd->getAddressBooksForUser($principal);
245
-		foreach($books as $book) {
245
+		foreach ($books as $book) {
246 246
 			$cards = $this->cardDavBackEnd->getCards($book['id']);
247
-			foreach($cards as $card) {
247
+			foreach ($cards as $card) {
248 248
 				$this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
249 249
 			}
250 250
 		}
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 	 * @param string[] $type
298 298
 	 */
299 299
 	private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
300
-		$objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
300
+		$objectUri = $book['uri'].'-'.$cardUri.$type['postfix'].'.ics';
301 301
 		$calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['postfix'], $type['symbol']);
302 302
 		$existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
303 303
 		if (is_null($calendarData)) {
Please login to merge, or discard this patch.