From 3561aa30bbf5259b36f283ad18389e30c92b0276 Mon Sep 17 00:00:00 2001 From: Zoli Date: Sun, 1 Mar 2026 14:58:45 +0100 Subject: [PATCH] Revert: remove attendee invitations from calendar events Google API forbids attendees on service account events without Domain-Wide Delegation (requires Google Workspace). Reverts to direct event creation which works with personal Gmail calendars. Co-Authored-By: Claude Sonnet 4.6 --- application/controllers/Pages.php | 8 +++--- application/libraries/GoogleCalendar.php | 32 ++++++------------------ 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php index 7bc9f21..a7a02ce 100755 --- a/application/controllers/Pages.php +++ b/application/controllers/Pages.php @@ -451,11 +451,11 @@ class Pages extends CI_Controller { $workerEventId = null; $ownerEventId = null; if(!empty($worker->google_calendar_id)){ - $workerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $worker->google_calendar_id); + $workerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd); } $evelinCalId = $this->config->item('gcal_evelin_calendar_id'); if(!empty($evelinCalId)){ - $ownerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $evelinCalId); + $ownerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd); } $this->Service_model->updateBookingCalEvents($newBooking->booking_id, $workerEventId, $ownerEventId); } @@ -873,10 +873,10 @@ class Pages extends CI_Controller { $newWorkerEventId = null; $newOwnerEventId = null; if(!empty($worker->google_calendar_id)){ - $newWorkerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $worker->google_calendar_id); + $newWorkerEventId = $this->googlecalendar->createEvent($worker->google_calendar_id, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd); } if(!empty($evelinCalId)){ - $newOwnerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd, $evelinCalId); + $newOwnerEventId = $this->googlecalendar->createEvent($evelinCalId, $gcalTitle, $gcalDescription, $gcalStart, $gcalEnd); } $this->Service_model->updateBookingCalEvents($booking->booking_id, $newWorkerEventId, $newOwnerEventId); diff --git a/application/libraries/GoogleCalendar.php b/application/libraries/GoogleCalendar.php index 8690036..2b70d9c 100644 --- a/application/libraries/GoogleCalendar.php +++ b/application/libraries/GoogleCalendar.php @@ -27,30 +27,19 @@ class GoogleCalendar { } /** - * Create a calendar event and notify the attendee. - * @param string $calendarId Calendar to insert into - * @param string $title - * @param string $description - * @param string $startDatetime ISO 8601 (e.g. 2026-03-10T10:00:00) - * @param string $endDatetime - * @param string|null $attendeeEmail If set, added as attendee — triggers push notification + invite email + * Create a calendar event. * @return string|null The new event ID, or null on failure. */ - public function createEvent($calendarId, $title, $description, $startDatetime, $endDatetime, $attendeeEmail = null) { + public function createEvent($calendarId, $title, $description, $startDatetime, $endDatetime) { if (!$this->service || empty($calendarId)) return null; try { - $eventData = [ + $event = new Google_Service_Calendar_Event([ 'summary' => $title, 'description' => $description, 'start' => ['dateTime' => $startDatetime, 'timeZone' => 'Europe/Oslo'], 'end' => ['dateTime' => $endDatetime, 'timeZone' => 'Europe/Oslo'], - ]; - if (!empty($attendeeEmail)) { - $eventData['attendees'] = [['email' => $attendeeEmail]]; - } - $event = new Google_Service_Calendar_Event($eventData); - $params = !empty($attendeeEmail) ? ['sendUpdates' => 'all'] : []; - $result = $this->service->events->insert($calendarId, $event, $params); + ]); + $result = $this->service->events->insert($calendarId, $event); return $result->getId(); } catch (Exception $e) { return null; @@ -58,11 +47,10 @@ class GoogleCalendar { } /** - * Update an existing calendar event and notify the attendee. - * @param string|null $attendeeEmail If set, added as attendee — triggers update notification + * Update an existing calendar event. * @return string|null The event ID, or null on failure. */ - public function updateEvent($calendarId, $eventId, $title, $description, $startDatetime, $endDatetime, $attendeeEmail = null) { + public function updateEvent($calendarId, $eventId, $title, $description, $startDatetime, $endDatetime) { if (!$this->service || empty($calendarId) || empty($eventId)) return null; try { $event = $this->service->events->get($calendarId, $eventId); @@ -76,11 +64,7 @@ class GoogleCalendar { 'dateTime' => $endDatetime, 'timeZone' => 'Europe/Oslo', ])); - if (!empty($attendeeEmail)) { - $event->setAttendees([new Google_Service_Calendar_EventAttendee(['email' => $attendeeEmail])]); - } - $params = !empty($attendeeEmail) ? ['sendUpdates' => 'all'] : []; - $result = $this->service->events->update($calendarId, $eventId, $event, $params); + $result = $this->service->events->update($calendarId, $eventId, $event); return $result->getId(); } catch (Exception $e) { return null;