Skip to content
Snippets Groups Projects
Unverified Commit 785f6c63 authored by Roeland Jago Douma's avatar Roeland Jago Douma Committed by GitHub
Browse files

Merge pull request #26307 from nextcloud/backport/22201/stable21

[stable21] Delete old birthday calendar object when moving contact to another ad…
parents d65ce19f 74794bf1
No related branches found
No related tags found
No related merge requests found
...@@ -381,12 +381,26 @@ class BirthdayService { ...@@ -381,12 +381,26 @@ class BirthdayService {
$objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics'; $objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
$calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['postfix']); $calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['postfix']);
$existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri); $existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
if (is_null($calendarData)) { if ($calendarData === null) {
if (!is_null($existing)) { if ($existing !== null) {
$this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri); $this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri);
} }
} else { } 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()); $this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize());
} else { } else {
if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) { if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment