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 <noreply@anthropic.com>
This commit is contained in:
@@ -451,11 +451,11 @@ class Pages extends CI_Controller {
|
|||||||
$workerEventId = null;
|
$workerEventId = null;
|
||||||
$ownerEventId = null;
|
$ownerEventId = null;
|
||||||
if(!empty($worker->google_calendar_id)){
|
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');
|
$evelinCalId = $this->config->item('gcal_evelin_calendar_id');
|
||||||
if(!empty($evelinCalId)){
|
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);
|
$this->Service_model->updateBookingCalEvents($newBooking->booking_id, $workerEventId, $ownerEventId);
|
||||||
}
|
}
|
||||||
@@ -873,10 +873,10 @@ class Pages extends CI_Controller {
|
|||||||
$newWorkerEventId = null;
|
$newWorkerEventId = null;
|
||||||
$newOwnerEventId = null;
|
$newOwnerEventId = null;
|
||||||
if(!empty($worker->google_calendar_id)){
|
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)){
|
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);
|
$this->Service_model->updateBookingCalEvents($booking->booking_id, $newWorkerEventId, $newOwnerEventId);
|
||||||
|
|
||||||
|
|||||||
@@ -27,30 +27,19 @@ class GoogleCalendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a calendar event and notify the attendee.
|
* Create a calendar event.
|
||||||
* @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
|
|
||||||
* @return string|null The new event ID, or null on failure.
|
* @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;
|
if (!$this->service || empty($calendarId)) return null;
|
||||||
try {
|
try {
|
||||||
$eventData = [
|
$event = new Google_Service_Calendar_Event([
|
||||||
'summary' => $title,
|
'summary' => $title,
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'start' => ['dateTime' => $startDatetime, 'timeZone' => 'Europe/Oslo'],
|
'start' => ['dateTime' => $startDatetime, 'timeZone' => 'Europe/Oslo'],
|
||||||
'end' => ['dateTime' => $endDatetime, 'timeZone' => 'Europe/Oslo'],
|
'end' => ['dateTime' => $endDatetime, 'timeZone' => 'Europe/Oslo'],
|
||||||
];
|
]);
|
||||||
if (!empty($attendeeEmail)) {
|
$result = $this->service->events->insert($calendarId, $event);
|
||||||
$eventData['attendees'] = [['email' => $attendeeEmail]];
|
|
||||||
}
|
|
||||||
$event = new Google_Service_Calendar_Event($eventData);
|
|
||||||
$params = !empty($attendeeEmail) ? ['sendUpdates' => 'all'] : [];
|
|
||||||
$result = $this->service->events->insert($calendarId, $event, $params);
|
|
||||||
return $result->getId();
|
return $result->getId();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return null;
|
return null;
|
||||||
@@ -58,11 +47,10 @@ class GoogleCalendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an existing calendar event and notify the attendee.
|
* Update an existing calendar event.
|
||||||
* @param string|null $attendeeEmail If set, added as attendee — triggers update notification
|
|
||||||
* @return string|null The event ID, or null on failure.
|
* @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;
|
if (!$this->service || empty($calendarId) || empty($eventId)) return null;
|
||||||
try {
|
try {
|
||||||
$event = $this->service->events->get($calendarId, $eventId);
|
$event = $this->service->events->get($calendarId, $eventId);
|
||||||
@@ -76,11 +64,7 @@ class GoogleCalendar {
|
|||||||
'dateTime' => $endDatetime,
|
'dateTime' => $endDatetime,
|
||||||
'timeZone' => 'Europe/Oslo',
|
'timeZone' => 'Europe/Oslo',
|
||||||
]));
|
]));
|
||||||
if (!empty($attendeeEmail)) {
|
$result = $this->service->events->update($calendarId, $eventId, $event);
|
||||||
$event->setAttendees([new Google_Service_Calendar_EventAttendee(['email' => $attendeeEmail])]);
|
|
||||||
}
|
|
||||||
$params = !empty($attendeeEmail) ? ['sendUpdates' => 'all'] : [];
|
|
||||||
$result = $this->service->events->update($calendarId, $eventId, $event, $params);
|
|
||||||
return $result->getId();
|
return $result->getId();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user