toby/app/Infrastructure/Jobs/ClearVacationRequestDaysInGoogleCalendar.php
Adrian Hopek 8c1819aa01
#85 - google calendar improvements (#86)
* google calendar improvements

* fix

* change vacation request name

* #85 - google calendar improvements

* #85 - fix

* #85 - fix

* #85 - fix
2022-03-18 08:11:34 +01:00

37 lines
870 B
PHP

<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Spatie\GoogleCalendar\Event;
use Toby\Eloquent\Models\VacationRequest;
class ClearVacationRequestDaysInGoogleCalendar implements ShouldQueue
{
use Dispatchable;
use Queueable;
public function __construct(
protected VacationRequest $vacationRequest,
) {}
public function handle(): void
{
foreach ($this->vacationRequest->event_ids as $eventId) {
$calendarEvent = Event::find($eventId);
if ($calendarEvent->googleEvent->getStatus() !== "cancelled") {
$calendarEvent->delete();
}
}
$this->vacationRequest->update([
"event_ids" => null,
]);
}
}