summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2020-08-11 22:13:55 +0200
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2021-03-26 07:25:44 +0000
commit74794bf100df691f2e42174901f94ab933183e6f (patch)
tree84b94d0e1043f53a831770eb276991d8a4af391d /apps/dav/lib
parent9a4cbba7f6ef355605988c6b812a1282b35cfe79 (diff)
downloadnextcloud-server-74794bf100df691f2e42174901f94ab933183e6f.tar.gz
nextcloud-server-74794bf100df691f2e42174901f94ab933183e6f.zip
Delete old birthday calendar object when moving contact to another address book
When an contact is moved to another address book, the contact is copied to the second address book. During copying, the birthday event is created - but it gets the same UID as the contact's birthday event in the first address book. To prevent the "Calendar object with uid already exists" error that followed, we need to delete the old entry before the new one is created. Resolves: https://github.com/nextcloud/server/issues/20492 Signed-off-by: Christian Weiske <cweiske@cweiske.de>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/CalDAV/BirthdayService.php20
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)) {