diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2021-03-26 07:59:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-26 07:59:16 +0100 |
commit | fbbcf26099749440858bcaba2f8f6de4cc4612bc (patch) | |
tree | 3d47e39274dfc7091b7ec56d6fce909e41020e99 /apps/dav/lib/CalDAV | |
parent | 09718c20aa10fb2e25bceaa3bbe364eeb5be145b (diff) | |
parent | 8ee995f214b3fb9c7c1ace9da26e8e9b640a7ddd (diff) | |
download | nextcloud-server-fbbcf26099749440858bcaba2f8f6de4cc4612bc.tar.gz nextcloud-server-fbbcf26099749440858bcaba2f8f6de4cc4612bc.zip |
Merge pull request #22201 from cweiske/20492-move-contacts-with-birthday
Delete old birthday calendar object when moving contact to another ad…
Diffstat (limited to 'apps/dav/lib/CalDAV')
-rw-r--r-- | apps/dav/lib/CalDAV/BirthdayService.php | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/apps/dav/lib/CalDAV/BirthdayService.php b/apps/dav/lib/CalDAV/BirthdayService.php index e9f4787a328..fc525934f15 100644 --- a/apps/dav/lib/CalDAV/BirthdayService.php +++ b/apps/dav/lib/CalDAV/BirthdayService.php @@ -381,12 +381,26 @@ class BirthdayService { $objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics'; $calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['postfix']); $existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri); - if (is_null($calendarData)) { - if (!is_null($existing)) { + if ($calendarData === null) { + if ($existing !== null) { $this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri); } } else { - if (is_null($existing)) { + if ($existing === null) { + // not found by URI, but maybe by UID + // happens when a contact with birthday is moved to a different address book + $calendarInfo = $this->calDavBackEnd->getCalendarById($calendarId); + $extraData = $this->calDavBackEnd->getDenormalizedData($calendarData->serialize()); + + if ($calendarInfo && array_key_exists('principaluri', $calendarInfo)) { + $existing2path = $this->calDavBackEnd->getCalendarObjectByUID($calendarInfo['principaluri'], $extraData['uid']); + if ($existing2path !== null && array_key_exists('uri', $calendarInfo)) { + // delete the old birthday entry first so that we do not get duplicate UIDs + $existing2objectUri = substr($existing2path, strlen($calendarInfo['uri']) + 1); + $this->calDavBackEnd->deleteCalendarObject($calendarId, $existing2objectUri); + } + } + $this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize()); } else { if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) { |