Generische iCal-Kanäle mit Bestandsklärung und sicheren Exporten bereitstellen
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m33s

This commit is contained in:
Lars committed 2026-10-27 17:14:45 +01:00
1 parent 6fe5bbc6e3
commit 783068501c
42 files changed
+2646 -248

No files matched your search

+25 -15
View File
@@ -6,12 +6,15 @@
use App\Enums\BookingStatus;
use App\Enums\ChannelTaskAction;
use App\Models\Booking;
use Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit;
use App\Models\Property;
use App\Tenancy\TenantContext;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\DB;
/**
* Keeps manually maintained portals in step when a booking starts or stops occupying the calendar.
*/
class BookingObserver implements ShouldHandleEventsAfterCommit
class BookingObserver
{
public function __construct(private CreateChannelTasks $createChannelTasks) {}
@@ -24,17 +27,18 @@ public function created(Booking $booking): void
public function updated(Booking $booking): void
{
if (! $booking->wasChanged('status')) {
if (! $booking->wasChanged(['status', 'arrival', 'departure'])) {
return;
}
$before = $this->occupies($booking->getOriginal('status'));
$before = $this->occupies($booking->getRawOriginal('status'));
$after = $this->occupies($booking->status);
if (! $before && $after) {
if ($before && (! $after || $booking->wasChanged(['arrival', 'departure']))) {
$this->tasks($booking, ChannelTaskAction::Unblock, CarbonImmutable::parse($booking->getRawOriginal('arrival')), CarbonImmutable::parse($booking->getRawOriginal('departure')));
}
if ($after && (! $before || $booking->wasChanged(['arrival', 'departure']))) {
$this->tasks($booking, ChannelTaskAction::Block);
} elseif ($before && ! $after) {
$this->tasks($booking, ChannelTaskAction::Unblock);
}
}
@@ -45,14 +49,20 @@ private function occupies(BookingStatus|string|null $status): bool
return in_array($status, BookingStatus::occupying(), true);
}
private function tasks(Booking $booking, ChannelTaskAction $action): void
private function tasks(Booking $booking, ChannelTaskAction $action, ?CarbonImmutable $startsOn = null, ?CarbonImmutable $endsOn = null): void
{
$property = $booking->property()->withoutGlobalScope('tenant')->first();
if ($property === null) {
return;
}
$this->createChannelTasks->handle($property, $booking->arrival, $booking->departure, $action, "Buchung {$booking->reference}");
$propertyId = $booking->property_id;
$channelId = $booking->import_channel_id;
$originId = $booking->origin_channel_id;
$external = ! $booking->isDirect();
$startsOn ??= $booking->arrival;
$endsOn ??= $booking->departure;
$reason = "Buchung {$booking->reference}";
DB::afterCommit(function () use ($propertyId, $channelId, $originId, $external, $startsOn, $endsOn, $action, $reason): void {
$property = Property::withoutGlobalScope('tenant')->find($propertyId);
if ($property !== null) {
app(TenantContext::class)->run($property->tenant, fn () => $this->createChannelTasks->handle($property, $startsOn, $endsOn, $action, $reason, $channelId, $originId, $external));
}
});
}
}