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

+30 -8
View File
@@ -5,41 +5,63 @@
use App\Actions\CreateChannelTasks;
use App\Enums\ChannelTaskAction;
use App\Models\BlockedPeriod;
use App\Models\Property;
use App\Tenancy\TenantContext;
use Carbon\CarbonImmutable;
use Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit;
use Illuminate\Support\Facades\DB;
/**
* Manual blocks and occupations imported from one portal must also reach the manually maintained
* portals – except the portal they came from.
*/
class BlockedPeriodObserver implements ShouldHandleEventsAfterCommit
class BlockedPeriodObserver
{
public function __construct(private CreateChannelTasks $createChannelTasks) {}
public function created(BlockedPeriod $block): void
{
$this->tasks($block, $block->starts_on, $block->ends_on, ChannelTaskAction::Block);
if (! $block->is_representation && $block->export_approved) {
$this->tasks($block, $block->starts_on, $block->ends_on, ChannelTaskAction::Block);
}
}
public function restored(BlockedPeriod $block): void
{
$this->created($block);
}
public function updated(BlockedPeriod $block): void
{
if (! $block->wasChanged(['starts_on', 'ends_on'])) {
if (! $block->wasChanged(['starts_on', 'ends_on', 'is_representation', 'export_approved'])) {
return;
}
$this->tasks($block, CarbonImmutable::parse($block->getOriginal('starts_on')), CarbonImmutable::parse($block->getOriginal('ends_on')), ChannelTaskAction::Unblock);
$this->tasks($block, $block->starts_on, $block->ends_on, ChannelTaskAction::Block);
$this->tasks($block, CarbonImmutable::parse($block->getRawOriginal('starts_on')), CarbonImmutable::parse($block->getRawOriginal('ends_on')), ChannelTaskAction::Unblock);
if (! $block->is_representation && $block->export_approved && ! $block->trashed()) {
$this->tasks($block, $block->starts_on, $block->ends_on, ChannelTaskAction::Block);
}
}
public function deleted(BlockedPeriod $block): void
{
$this->tasks($block, $block->starts_on, $block->ends_on, ChannelTaskAction::Unblock);
if (! $block->is_representation) {
$this->tasks($block, $block->starts_on, $block->ends_on, ChannelTaskAction::Unblock);
}
}
private function tasks(BlockedPeriod $block, CarbonImmutable $startsOn, CarbonImmutable $endsOn, ChannelTaskAction $action): void
{
$reason = $block->channel ? "Belegung über {$block->channel->name}" : 'Sperrzeit'.($block->reason ? ": {$block->reason}" : '');
$this->createChannelTasks->handle($block->property, $startsOn, $endsOn, $action, $reason, $block->channel_id);
$propertyId = $block->property_id;
$channelId = $block->channel_id;
$originId = $block->origin_channel_id;
$external = $channelId !== null || $originId !== null || $block->source !== 'manual';
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));
}
});
}
}