diff --git a/config.inc.php.dist b/config.inc.php.dist index 08d9611..8c7f125 100644 --- a/config.inc.php.dist +++ b/config.inc.php.dist @@ -157,6 +157,12 @@ $config['kolab_invitation_calendars'] = false; // ) // ); +// Path used to create new calendars in a CalDav source. +// The following replacement variables are supported: +// %u - Source user name +// %i - Newly generated calendar UUID +// $config['calendar_caldav_new_calendar_path'] = '/calendars/%u/%i'; + // Driver to provide a resource directory ('ldap' is the only implementation yet). // Leave empty or commented to disable resources support. // $config['calendar_resources_driver'] = 'ldap'; diff --git a/drivers/caldav/SQL/mysql.initial.sql b/drivers/caldav/SQL/mysql.initial.sql index 92004b2..d460ef9 100644 --- a/drivers/caldav/SQL/mysql.initial.sql +++ b/drivers/caldav/SQL/mysql.initial.sql @@ -107,4 +107,5 @@ CREATE TABLE IF NOT EXISTS `caldav_attachments` ( CONSTRAINT `fk_caldav_attachments_event_id` FOREIGN KEY (`event_id`) REFERENCES `caldav_events`(`event_id`) ON DELETE CASCADE ON UPDATE CASCADE ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; -REPLACE INTO `system` (`name`, `value`) VALUES ('calendar-caldav-version', '2021082400'); \ No newline at end of file + +INSERT INTO `system` (`name`, `value`) VALUES ('calendar-caldav-version', '2021082400'); diff --git a/drivers/caldav/caldav_driver.php b/drivers/caldav/caldav_driver.php index 71a2162..9739e4c 100644 --- a/drivers/caldav/caldav_driver.php +++ b/drivers/caldav/caldav_driver.php @@ -273,10 +273,10 @@ public function create_calendar($cal) $server_url = self::_encode_url($source['caldav_url']); $server_path = rtrim(parse_url($server_url, PHP_URL_PATH), '/'); - $calId = $this->cal->generate_uid(); - $path = "/calendars/$source[caldav_user]/$calId"; + $path = $this->_get_new_calendar_path($source); self::debug_log("Creating new calendar \"$cal[name]\" with path $path at: " . $server_url); + $client = new caldav_client($server_url, $source['caldav_user'], $source['caldav_pass']); if($client->create_calendar($server_path . $path, $cal['name'], isset($cal['color']) ? $cal['color'] : 'cc0000')) { @@ -332,8 +332,6 @@ private function _add_calendars($calendars, $source) { */ public function create_source($source) { - $source['caldav_url'] = self::_encode_url($source['caldav_url']); - // Re-discover all existing calendars systematically try { $calendars = $this->_autodiscover_calendars($source); @@ -531,14 +529,12 @@ public function new_event($event) if (!$event['calendar'] || !$this->calendars[$event['calendar']]) return false; - if($event = $this->_save_preprocess($event)) { - $sync_client = $this->sync_clients[$event["calendar"]]; + $sync_client = $this->sync_clients[$event["calendar"]]; - // Only push event if caldav_tag is not set to avoid pushing it twice - if (isset($event["caldav_tag"]) || ($event = $sync_client->create_event($event)) !== null) { - if ($event_id = $this->_insert_event($event)) { - $this->_update_recurring($event); - } + // Only push event if caldav_tag is not set to avoid pushing it twice + if (isset($event["caldav_tag"]) || ($event = $sync_client->create_event($event)) !== null) { + if ($event_id = $this->_insert_event($event)) { + $this->_update_recurring($event); } } @@ -553,7 +549,7 @@ public function new_event($event) */ private function _insert_event(&$event) { - //$event = $this->_save_preprocess($event); + $event = $this->_save_preprocess($event); //TODO: proper 4 byte character (eg emoticons) handling //utf8 in mysql only supports 3 byte characters, so this throws an error if there are emoticons in the description. @@ -2230,6 +2226,12 @@ private function _perform_updates($updates) foreach($updates as $update) { + if(is_null($update['remote_event'])) + { + self::debug_log("No remote_event in update: ".print_r($update, true)); + continue; + + } if($update['remote_event']['allday']) { //caldav has exclusive end dates set to midnight of the next day. @@ -2349,4 +2351,12 @@ private function _encrypt_pass($pass) { $p = $e->encrypt($pass); return base64_encode($p); } + + private function _get_new_calendar_path($source) { + $template = $this->rc->config->get('calendar_caldav_new_calendar_path', '/calendars/%u/%i'); + return strtr($template, [ + '%u' => $source['caldav_user'], + '%i' => $this->cal->generate_uid(), + ]); + } } diff --git a/drivers/database/SQL/mysql.initial.sql b/drivers/database/SQL/mysql.initial.sql index 5f6dd60..e2248f2 100644 --- a/drivers/database/SQL/mysql.initial.sql +++ b/drivers/database/SQL/mysql.initial.sql @@ -82,4 +82,4 @@ CREATE TABLE IF NOT EXISTS `itipinvitations` ( REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; -REPLACE INTO system (name, value) VALUES ('calendar-database-version', '2015022700'); +INSERT INTO system (name, value) VALUES ('calendar-database-version', '2015022700'); diff --git a/drivers/kolab/SQL/mysql.initial.sql b/drivers/kolab/SQL/mysql.initial.sql index f672fb7..3fca238 100644 --- a/drivers/kolab/SQL/mysql.initial.sql +++ b/drivers/kolab/SQL/mysql.initial.sql @@ -29,4 +29,4 @@ CREATE TABLE IF NOT EXISTS `itipinvitations` ( REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; -REPLACE INTO system (name, value) VALUES ('calendar-kolab-version', '2014041700'); +INSERT INTO system (name, value) VALUES ('calendar-kolab-version', '2014041700');