From 673ec82aa3998f71a65bbeed918dfb0ad7569105 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Tue, 10 Mar 2020 20:39:53 +0100 Subject: [PATCH] Check for empty events before proceeding with the syncing (#531). --- src/application/controllers/Google.php | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/application/controllers/Google.php b/src/application/controllers/Google.php index 933f9883..c52fc3bc 100644 --- a/src/application/controllers/Google.php +++ b/src/application/controllers/Google.php @@ -221,23 +221,25 @@ class Google extends CI_Controller { foreach ($events->getItems() as $event) { $results = $this->appointments_model->get_batch(['id_google_calendar' => $event->getId()]); - if (count($results) == 0) - { - // Record doesn't exist in E!A, so add the event now. - $appointment = [ - 'start_datetime' => date('Y-m-d H:i:s', strtotime($event->start->getDateTime())), - 'end_datetime' => date('Y-m-d H:i:s', strtotime($event->end->getDateTime())), - 'is_unavailable' => TRUE, - 'location' => $event->getLocation(), - 'notes' => $event->getSummary() . ' ' . $event->getDescription(), - 'id_users_provider' => $provider_id, - 'id_google_calendar' => $event->getId(), - 'id_users_customer' => NULL, - 'id_services' => NULL, - ]; - $this->appointments_model->add($appointment); + if (!empty($results) || empty($event)) { + continue; } + + // Record doesn't exist in E!A, so add the event now. + $appointment = [ + 'start_datetime' => date('Y-m-d H:i:s', strtotime($event->start->getDateTime())), + 'end_datetime' => date('Y-m-d H:i:s', strtotime($event->end->getDateTime())), + 'is_unavailable' => TRUE, + 'location' => $event->getLocation(), + 'notes' => $event->getSummary() . ' ' . $event->getDescription(), + 'id_users_provider' => $provider_id, + 'id_google_calendar' => $event->getId(), + 'id_users_customer' => NULL, + 'id_services' => NULL, + ]; + + $this->appointments_model->add($appointment); } $this->output