diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-03-16 17:19:14 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-03-16 17:23:02 +0100 |
commit | fdb7c59e6c4ff1441d605fa4e2e3bdb02a9bf605 (patch) | |
tree | 858c523a726ce0132a104f155fad6ed8bd2a6f89 | |
parent | d188ed938cf6c08dab38f1cb11ea7f4014b19364 (diff) | |
download | nextcloud-server-fdb7c59e6c4ff1441d605fa4e2e3bdb02a9bf605.tar.gz nextcloud-server-fdb7c59e6c4ff1441d605fa4e2e3bdb02a9bf605.zip |
Create the contact birthday calendar right away as soon as the command is executed once - fixes #23203
-rw-r--r-- | apps/dav/lib/caldav/birthdayservice.php | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/apps/dav/lib/caldav/birthdayservice.php b/apps/dav/lib/caldav/birthdayservice.php index 7e1df189c4e..274341949b3 100644 --- a/apps/dav/lib/caldav/birthdayservice.php +++ b/apps/dav/lib/caldav/birthdayservice.php @@ -50,8 +50,7 @@ class BirthdayService { $book = $this->cardDavBackEnd->getAddressBookById($addressBookId); $principalUri = $book['principaluri']; - $calendarUri = self::BIRTHDAY_CALENDAR_URI; - $calendar = $this->ensureCalendarExists($principalUri, $calendarUri, []); + $calendar = $this->ensureCalendarExists($principalUri); $objectUri = $book['uri'] . '-' . $cardUri. '.ics'; $calendarData = $this->buildBirthdayFromContact($cardData); $existing = $this->calDavBackEnd->getCalendarObject($calendar['id'], $objectUri); @@ -77,32 +76,27 @@ class BirthdayService { public function onCardDeleted($addressBookId, $cardUri) { $book = $this->cardDavBackEnd->getAddressBookById($addressBookId); $principalUri = $book['principaluri']; - $calendarUri = self::BIRTHDAY_CALENDAR_URI; - $calendar = $this->ensureCalendarExists($principalUri, $calendarUri, []); + $calendar = $this->ensureCalendarExists($principalUri); $objectUri = $book['uri'] . '-' . $cardUri. '.ics'; $this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri); } /** * @param string $principal - * @param string $id - * @param array $properties * @return array|null * @throws \Sabre\DAV\Exception\BadRequest */ - public function ensureCalendarExists($principal, $id, $properties) { - $properties = array_merge([ - '{DAV:}displayname' => 'Contact birthdays', - '{http://apple.com/ns/ical/}calendar-color' => '#FFFFCA', - ], $properties); - - $book = $this->calDavBackEnd->getCalendarByUri($principal, $id); + public function ensureCalendarExists($principal) { + $book = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI); if (!is_null($book)) { return $book; } - $this->calDavBackEnd->createCalendar($principal, $id, $properties); + $this->calDavBackEnd->createCalendar($principal, self::BIRTHDAY_CALENDAR_URI, [ + '{DAV:}displayname' => 'Contact birthdays', + '{http://apple.com/ns/ical/}calendar-color' => '#FFFFCA', + ]); - return $this->calDavBackEnd->getCalendarByUri($principal, $id); + return $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI); } /** @@ -161,7 +155,9 @@ class BirthdayService { * @param string $user */ public function syncUser($user) { - $books = $this->cardDavBackEnd->getAddressBooksForUser('principals/users/'.$user); + $principal = 'principals/users/'.$user; + $this->ensureCalendarExists($principal); + $books = $this->cardDavBackEnd->getAddressBooksForUser($principal); foreach($books as $book) { $cards = $this->cardDavBackEnd->getCards($book['id']); foreach($cards as $card) { |