- Connector-System (app/Channels, config/channels.php) mit iCal-Connector, robustem Parser und Export-Feed je Portal (ohne eigene Belegungen, ohne Gästedaten) - Abgleich alle 5 Min. mit Protokoll, Echo-Erkennung, Konflikt-Mail bei möglicher Doppelbuchung - Überwachung: Störungs-Mail, Status-Endpunkt /health/sync für n8n - Portal-Aufgaben für Sofortbuchungsportale (FeWo-direkt): automatisch aus Buchungen/Sperren/anderen Portalen, Mail + Erinnerung, Abhaken im Admin - Optionaler signierter Automatisierungs-Webhook mit Rückmeldung - Herkunftsmessung: Abfrage im Formular + UTM-Parameter - Portal-Analyse: AGB-Prüfung Automatisierung, Umsetzungsbeschreibung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Observers;
|
|
|
|
use App\Actions\CreateChannelTasks;
|
|
use App\Enums\BookingStatus;
|
|
use App\Enums\ChannelTaskAction;
|
|
use App\Models\Booking;
|
|
use Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit;
|
|
|
|
/**
|
|
* Keeps manually maintained portals in step when a booking starts or stops occupying the calendar.
|
|
*/
|
|
class BookingObserver implements ShouldHandleEventsAfterCommit
|
|
{
|
|
public function __construct(private CreateChannelTasks $createChannelTasks) {}
|
|
|
|
public function created(Booking $booking): void
|
|
{
|
|
if ($this->occupies($booking->status)) {
|
|
$this->tasks($booking, ChannelTaskAction::Block);
|
|
}
|
|
}
|
|
|
|
public function updated(Booking $booking): void
|
|
{
|
|
if (! $booking->wasChanged('status')) {
|
|
return;
|
|
}
|
|
|
|
$before = $this->occupies($booking->getOriginal('status'));
|
|
$after = $this->occupies($booking->status);
|
|
|
|
if (! $before && $after) {
|
|
$this->tasks($booking, ChannelTaskAction::Block);
|
|
} elseif ($before && ! $after) {
|
|
$this->tasks($booking, ChannelTaskAction::Unblock);
|
|
}
|
|
}
|
|
|
|
private function occupies(BookingStatus|string|null $status): bool
|
|
{
|
|
$status = is_string($status) ? BookingStatus::tryFrom($status) : $status;
|
|
|
|
return in_array($status, BookingStatus::occupying(), true);
|
|
}
|
|
|
|
private function tasks(Booking $booking, ChannelTaskAction $action): void
|
|
{
|
|
$this->createChannelTasks->handle($booking->property, $booking->arrival, $booking->departure, $action, "Buchung {$booking->reference}");
|
|
}
|
|
}
|