Der Kalenderabgleich alle 5 Minuten hat jede fortbestehende Ueberschneidung erneut gemailt. ReportChannelConflicts legt jede Ueberschneidung einmal im neuen Postfach (InboxMessage, Fingerabdruck je Mandant) ab und mailt nur neue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Enums\InboxMessageKind;
|
|
use App\Filament\Pages\OccupancyCalendar;
|
|
use App\Mail\ChannelConflict;
|
|
use App\Models\Channel;
|
|
use App\Support\Inbox;
|
|
use App\Support\Settings;
|
|
use Carbon\CarbonInterface;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
/**
|
|
* Reports possible double bookings found while importing portal occupations (calendar sync or portal
|
|
* e-mail). Every conflict lands in the admin inbox once; only conflicts not reported before are e-mailed,
|
|
* so a lasting overlap does not trigger a mail on every sync.
|
|
*/
|
|
class ReportChannelConflicts
|
|
{
|
|
public function __construct(private Inbox $inbox) {}
|
|
|
|
/**
|
|
* @param array<string, CarbonInterface> $conflicts description => first night of the portal occupation
|
|
* @return list<string> the conflicts reported for the first time
|
|
*/
|
|
public function handle(Channel $channel, array $conflicts): array
|
|
{
|
|
$new = [];
|
|
foreach ($conflicts as $description => $startsOn) {
|
|
$message = $this->inbox->post(
|
|
InboxMessageKind::ChannelConflict,
|
|
$channel->id.':'.sha1($description),
|
|
'Mögliche Doppelbuchung über '.$channel->name,
|
|
$description,
|
|
$channel,
|
|
OccupancyCalendar::getUrl(['monat' => $startsOn->format('Y-m'), 'wohnung' => $channel->property_id]),
|
|
);
|
|
if ($message) {
|
|
$new[] = $description;
|
|
}
|
|
}
|
|
|
|
if ($new !== []) {
|
|
rescue(fn () => Mail::to(Settings::notificationRecipients())->send(new ChannelConflict($channel, $new)));
|
|
}
|
|
|
|
return $new;
|
|
}
|
|
}
|