summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-02-18 14:49:45 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-02-18 14:49:45 +0100
commitd8de7d1e73f303c71a3cf1dea43fb67f3606700d (patch)
treeb6d02e0acab86c5c4a03b47b1f4ff95c0ff0a550 /apps/dav/lib
parent981c73000cce96276d2e9db899162f31226b146f (diff)
downloadnextcloud-server-d8de7d1e73f303c71a3cf1dea43fb67f3606700d.tar.gz
nextcloud-server-d8de7d1e73f303c71a3cf1dea43fb67f3606700d.zip
Adding cli command to sync birthday calendar
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/caldav/birthdayservice.php42
1 files changed, 39 insertions, 3 deletions
diff --git a/apps/dav/lib/caldav/birthdayservice.php b/apps/dav/lib/caldav/birthdayservice.php
index 5a0dfb69925..3b0a2a10e1c 100644
--- a/apps/dav/lib/caldav/birthdayservice.php
+++ b/apps/dav/lib/caldav/birthdayservice.php
@@ -54,14 +54,18 @@ class BirthdayService {
$calendar = $this->ensureCalendarExists($principalUri, $calendarUri, []);
$objectUri = $book['uri'] . '-' . $cardUri. '.ics';
$calendarData = $this->buildBirthdayFromContact($cardData);
+ $existing = $this->calDavBackEnd->getCalendarObject($calendar['id'], $objectUri);
if (is_null($calendarData)) {
- $this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri);
+ if (!is_null($existing)) {
+ $this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri);
+ }
} else {
- $existing = $this->calDavBackEnd->getCalendarObject($calendar['id'], $objectUri);
if (is_null($existing)) {
$this->calDavBackEnd->createCalendarObject($calendar['id'], $objectUri, $calendarData->serialize());
} else {
- $this->calDavBackEnd->updateCalendarObject($calendar['id'], $objectUri, $calendarData->serialize());
+ if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) {
+ $this->calDavBackEnd->updateCalendarObject($calendar['id'], $objectUri, $calendarData->serialize());
+ }
}
}
}
@@ -148,4 +152,36 @@ class BirthdayService {
return $vCal;
}
+ /**
+ * @param string $user
+ */
+ public function syncUser($user) {
+ $books = $this->cardDavBackEnd->getAddressBooksForUser('principals/users/'.$user);
+ foreach($books as $book) {
+ $cards = $this->cardDavBackEnd->getCards($book['id']);
+ foreach($cards as $card) {
+ $this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
+ }
+ }
+ }
+
+ /**
+ * @param string $existingCalendarData
+ * @param VCalendar $newCalendarData
+ * @return bool
+ */
+ public function birthdayEvenChanged($existingCalendarData, $newCalendarData) {
+ try {
+ $existingBirthday = Reader::read($existingCalendarData);
+ } catch (Exception $ex) {
+ return true;
+ }
+ if ($newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() ||
+ $newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue()
+ ) {
+ return true;
+ }
+ return false;
+ }
+
}