Skip to content

Commit

Permalink
Merge pull request #26305 from nextcloud/backport/22201/stable20
Browse files Browse the repository at this point in the history
[stable20] Delete old birthday calendar object when moving contact to another ad…
  • Loading branch information
skjnldsv authored Mar 26, 2021
2 parents 2262115 + 92ac67c commit 20cb2b4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions apps/dav/lib/CalDAV/BirthdayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,26 @@ private function updateCalendar(string $cardUri,
$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)) {
Expand Down

0 comments on commit 20cb2b4

Please sign in to comment.