Remove test code from the Caldav.php controller (#209)

This commit is contained in:
Alex Tselegidis 2024-05-12 18:07:31 +02:00
parent de63955341
commit 2aea423b38

View file

@ -166,7 +166,7 @@ class Caldav extends EA_Controller
$events_model = $CI->unavailabilities_model; $events_model = $CI->unavailabilities_model;
} }
// If current appointment not synced yet, add to Google Calendar. // If current appointment not synced yet, add to CalDAV Calendar.
if (!$local_event['id_caldav_calendar']) { if (!$local_event['id_caldav_calendar']) {
if (!$local_event['is_unavailability']) { if (!$local_event['is_unavailability']) {
@ -175,14 +175,14 @@ class Caldav extends EA_Controller
$caldav_event_id = $CI->caldav_sync->save_unavailability($local_event, $provider); $caldav_event_id = $CI->caldav_sync->save_unavailability($local_event, $provider);
} }
$local_event['id_google_calendar'] = $caldav_event_id; $local_event['id_caldav_calendar'] = $caldav_event_id;
$events_model->save($local_event); // Save the CalDAV Calendar ID. $events_model->save($local_event); // Save the CalDAV Calendar ID.
continue; continue;
} }
// Appointment is synced with Google Calendar. // Appointment is synced with CalDAV Calendar.
try { try {
$caldav_event = $CI->caldav_sync->get_event($provider, $local_event['id_caldav_calendar']); $caldav_event = $CI->caldav_sync->get_event($provider, $local_event['id_caldav_calendar']);
@ -191,7 +191,7 @@ class Caldav extends EA_Controller
throw new Exception('Event is cancelled, remove the record from Easy!Appointments.'); throw new Exception('Event is cancelled, remove the record from Easy!Appointments.');
} }
// If Google Calendar event is different from Easy!Appointments appointment then update Easy!Appointments record. // If CalDAV Calendar event is different from Easy!Appointments appointment then update Easy!Appointments record.
$local_event_start = strtotime($local_event['start_datetime']); $local_event_start = strtotime($local_event['start_datetime']);
$local_event_end = strtotime($local_event['end_datetime']); $local_event_end = strtotime($local_event['end_datetime']);
@ -214,7 +214,7 @@ class Caldav extends EA_Controller
$events_model->save($local_event); $events_model->save($local_event);
} }
} catch (Throwable) { } catch (Throwable) {
// Appointment not found on Google Calendar, delete from Easy!Appointments. // Appointment not found on CalDAV Calendar, delete from Easy!Appointments.
$events_model->delete($local_event['id']); $events_model->delete($local_event['id']);
$local_event['id_caldav_calendar'] = null; $local_event['id_caldav_calendar'] = null;
@ -266,7 +266,7 @@ class Caldav extends EA_Controller
'location' => $caldav_event['location'], 'location' => $caldav_event['location'],
'notes' => $caldav_event['summary'] . ' ' . $caldav_event['description'], 'notes' => $caldav_event['summary'] . ' ' . $caldav_event['description'],
'id_users_provider' => $provider_id, 'id_users_provider' => $provider_id,
'id_google_calendar' => $caldav_event['id'], 'id_caldav_calendar' => $caldav_event['id'],
]; ];
$CI->unavailabilities_model->save($local_event); $CI->unavailabilities_model->save($local_event);
@ -372,43 +372,4 @@ class Caldav extends EA_Controller
json_exception($e); json_exception($e);
} }
} }
/**
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function test(): void
{
$appointment = $this->appointments_model->find(5);
$service = $this->services_model->find($appointment['id_services']);
$provider = $this->providers_model->find($appointment['id_users_provider']);
$customer = $this->customers_model->find($appointment['id_users_customer']);
// Save example
// $caldav_event_id = $this->caldav_sync->save_appointment($appointment, $service, $provider, $customer);
// dd($caldav_event_id);
// Delete example
// $this->caldav_sync->delete_appointment($provider, $appointment['id_caldav_calendar']);
// Get event example
// $event = $this->caldav_sync->get_event($provider, $appointment['id_caldav_calendar']);
// dd($event);
// Get sync events example
// $events = $this->caldav_sync->get_sync_events($provider, '2024-05-06 00:00:00', '2024-05-13 00:00:00');
// dd($events);
// Save unavailability
// $unavailability = $this->unavailabilities_model->find(2);
// $unavailability_provider = $this->providers_model->find($unavailability['id_users_provider']);
//
// $this->caldav_sync->save_unavailability($unavailability, $unavailability_provider);
self::sync(2); // Sync jane
}
} }