diff --git a/lib/kolab_sync_data_calendar.php b/lib/kolab_sync_data_calendar.php --- a/lib/kolab_sync_data_calendar.php +++ b/lib/kolab_sync_data_calendar.php @@ -345,8 +345,23 @@ */ public function toKolab(Syncroton_Model_IEntry $data, $folderid, $entry = null, $timezone = null) { + $foldername = isset($entry['_mailbox']) ? $entry['_mailbox'] : $this->getFolderName($folderid); + if (empty($entry)) { + // If we don't have an existing event (not a modification) we nevertheless check for conflicts. + // This is necessary so we don't overwrite the server-side copy in case the client did not have it available + // when generating an Add command. + try { + $folder = $this->getFolderObject($foldername); + $entry = $folder->get_object($data->uID); + + if ($entry) { + $this->logger->debug('Found and existing event for UID: ' . $data->uID); + } + } catch (Exception $e) { + // uID is not available on exceptions, so we guard for that and silently ignore. + } + } $event = !empty($entry) ? $entry : array(); - $foldername = isset($event['_mailbox']) ? $event['_mailbox'] : $this->getFolderName($folderid); $config = $this->getFolderConfig($foldername); $is_exception = $data instanceof Syncroton_Model_EventException; $dummy_tz = str_repeat('A', 230) . '==';