Skip to content

Fixes to make this plugin work with SOGo #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.inc.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion drivers/caldav/SQL/mysql.initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');

INSERT INTO `system` (`name`, `value`) VALUES ('calendar-caldav-version', '2021082400');
34 changes: 22 additions & 12 deletions drivers/caldav/caldav_driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
]);
}
}
2 changes: 1 addition & 1 deletion drivers/database/SQL/mysql.initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');
2 changes: 1 addition & 1 deletion drivers/kolab/SQL/mysql.initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');