aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cdav.php4
-rw-r--r--include/import.php71
-rw-r--r--include/zot.php3
3 files changed, 76 insertions, 2 deletions
diff --git a/include/cdav.php b/include/cdav.php
index d72caa442..cdf7775db 100644
--- a/include/cdav.php
+++ b/include/cdav.php
@@ -175,12 +175,12 @@ function import_cdav_card($id, $ext, $table, $column, $objects, $profile, $backe
function get_cdav_id($principaluri, $uri, $table) {
- $r = q("SELECT id FROM $table WHERE principaluri = '%s' AND uri = '%s' LIMIT 1",
+ $r = q("SELECT * FROM $table WHERE principaluri = '%s' AND uri = '%s' LIMIT 1",
dbesc($principaluri),
dbesc($uri)
);
if(! $r)
return false;
- return $r[0]['id'];
+ return $r[0];
}
diff --git a/include/import.php b/include/import.php
index 0519052d8..bfe71963f 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1503,6 +1503,7 @@ function sync_files($channel, $files) {
}
}
+
/**
* @brief Synchronize addressbooks.
*
@@ -1571,6 +1572,76 @@ function sync_addressbook($channel, $data) {
/**
+ * @brief Synchronize calendars.
+ *
+ * @param array $channel
+ * @param array $data
+ */
+function sync_calendar($channel, $data) {
+
+ if(! \Zotlabs\Lib\Apps::system_app_installed($channel['channel_id'], 'Calendar'))
+ return;
+
+ logger("debug: " . print_r($data,true), LOGGER_DEBUG);
+
+ require_once('include/cdav.php');
+
+ $principalUri = 'principals/' . $channel['channel_address'];
+
+ if($data['action'] !== 'create') {
+ $x = get_cdav_id($principalUri, $data['uri'], 'calendarinstances');
+ if(! $x)
+ return;
+ $id = [ $x['id'], $x['calendarid'] ];
+ }
+
+ $pdo = \DBA::$dba->db;
+
+ $caldavBackend = new \Sabre\CalDAV\Backend\PDO($pdo);
+ $calendars = $caldavBackend->getCalendarsForUser($principalUri);
+
+ switch($data['action']) {
+
+ case 'create':
+ $id = $caldavBackend->createCalendar($principalUri, $data['uri'], $data['properties']);
+ set_pconfig($channel['channel_id'], 'cdav_calendar', $id[0], 1);
+ break;
+
+ case 'drop':
+ $caldavBackend->deleteCalendar($id);
+ break;
+
+ case 'edit':
+ $patch = new \Sabre\DAV\PropPatch($data['mutations']);
+ $caldavBackend->updateCalendar($id, $patch);
+ $patch->commit();
+ break;
+
+ case 'delete_card':
+ $caldavBackend->deleteCalendarObject($id, $data['carduri']);
+ break;
+
+ case 'update_card':
+ $caldavBackend->updateCalendarObject($id, $data['carduri'], $data['card']);
+ break;
+
+ case 'switch':
+ set_pconfig($channel['channel_id'], 'cdav_calendar', $id[0], $data['switch']);
+ break;
+
+ case 'import':
+ $objects = new \Sabre\VObject\Splitter\ICalendar($data['card']);
+ $profile = \Sabre\VObject\Node::PROFILE_CALDAV;
+ import_cdav_card($id, 'ics', 'calendarobjects', 'calendarid', $objects, $profile, $caldavBackend, $data['ids']);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+/**
* @brief Rename a key in an array.
*
* Replaces $old key with $new key in $arr.
diff --git a/include/zot.php b/include/zot.php
index c02dab162..5d5ac8424 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -3614,6 +3614,9 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
if(array_key_exists('addressbook',$arr) && $arr['addressbook'])
sync_addressbook($channel,$arr['addressbook']);
+ if(array_key_exists('calendar',$arr) && $arr['calendar'])
+ sync_calendar($channel,$arr['calendar']);
+
if(array_key_exists('chatroom',$arr) && $arr['chatroom'])
sync_chatrooms($channel,$arr['chatroom']);