aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-02-24 10:02:09 +0100
committerMario <mario@mariovavti.com>2020-02-24 10:02:09 +0100
commitb36eb9a91cba1a6f3a53961f895665a0ae110b95 (patch)
tree3f2f031445c4f5cf1e97d548a9df335a12a98c5b /include
parent7bb94f999350dfdc2c2cdf5b5d094ef52953edd6 (diff)
parent989fbe70cd566da4c5757527aa77022036af6274 (diff)
downloadvolse-hubzilla-b36eb9a91cba1a6f3a53961f895665a0ae110b95.tar.gz
volse-hubzilla-b36eb9a91cba1a6f3a53961f895665a0ae110b95.tar.bz2
volse-hubzilla-b36eb9a91cba1a6f3a53961f895665a0ae110b95.zip
Merge branch 'dev' into 'dev'
Implement DAV calendars sync with clones See merge request hubzilla/core!1834
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']);