Skip to content

Commit

Permalink
More fixes related to the caldav syncing (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed May 12, 2024
1 parent 2aea423 commit ab8257f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions application/libraries/Caldav_sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function save_appointment(array $appointment, array $service, array $prov

$caldav_calendar = $provider['settings']['caldav_calendar'];

$caldav_event_id = $this->CI->ics_file->generate_uid($appointment['id']) . '.ics';
$caldav_event_id =
$appointment['id_caldav_calendar'] ?: $this->CI->ics_file->generate_uid($appointment['id']);

$uri = $this->get_caldav_event_uri($caldav_calendar, $caldav_event_id);

Expand Down Expand Up @@ -107,7 +108,8 @@ public function save_unavailability(array $unavailability, array $provider): ?st

$caldav_calendar = $provider['settings']['caldav_calendar'];

$caldav_event_id = $this->CI->ics_file->generate_uid($unavailability['id']) . '.ics';
$caldav_event_id =
$unavailability['id_caldav_calendar'] ?: $this->CI->ics_file->generate_uid($unavailability['id']);

$uri = $this->get_caldav_event_uri($caldav_calendar, $caldav_event_id);

Expand Down Expand Up @@ -420,7 +422,7 @@ private function get_http_client_by_provider_id(int $provider_id): Client
*/
private function get_caldav_event_uri(string $caldav_calendar, ?string $caldav_event_id = null): string
{
return trim($caldav_calendar, '/') . ($caldav_event_id ? '/' . $caldav_event_id : '');
return trim($caldav_calendar, '/') . ($caldav_event_id ? '/' . $caldav_event_id . '.ics' : '');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions application/libraries/Ics_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function get_stream(array $appointment, array $service, array $provider,
->setEnd($appointment_end)
->setStatus('CONFIRMED')
->setSummary($service['name'])
->setUid($this->generate_uid($appointment['id']));
->setUid($appointment['id_caldav_calendar'] ?: $this->generate_uid($appointment['id']));

if (!empty($service['location'])) {
$location = new Location();
Expand Down Expand Up @@ -198,7 +198,7 @@ public function get_unavailability_stream(array $unavailability, array $provider
->setEnd($unavailability_end)
->setStatus('CONFIRMED')
->setSummary('Unavailability')
->setUid($this->generate_uid($unavailability['id']));
->setUid($unavailability['id_caldav_calendar'] ?: $this->generate_uid($unavailability['id']));

$event->setDescription(str_replace("\n", "\\n", (string) $unavailability['notes']));

Expand Down
1 change: 1 addition & 0 deletions application/libraries/Synchronization.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct()
$this->CI->load->model('appointments_model');

$this->CI->load->library('google_sync');
$this->CI->load->library('caldav_sync');
}

/**
Expand Down

0 comments on commit ab8257f

Please sign in to comment.