diff options
author | Max Kostikov <max@kostikov.co> | 2020-02-24 10:02:09 +0100 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-02-24 10:02:09 +0100 |
commit | 989fbe70cd566da4c5757527aa77022036af6274 (patch) | |
tree | 3f2f031445c4f5cf1e97d548a9df335a12a98c5b /include/import.php | |
parent | 7bb94f999350dfdc2c2cdf5b5d094ef52953edd6 (diff) | |
download | volse-hubzilla-989fbe70cd566da4c5757527aa77022036af6274.tar.gz volse-hubzilla-989fbe70cd566da4c5757527aa77022036af6274.tar.bz2 volse-hubzilla-989fbe70cd566da4c5757527aa77022036af6274.zip |
Implement DAV calendars sync with clones
Diffstat (limited to 'include/import.php')
-rw-r--r-- | include/import.php | 71 |
1 files changed, 71 insertions, 0 deletions
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. |