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>
42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Enums\InboxMessageKind;
|
|
use App\Models\Channel;
|
|
use App\Models\InboxMessage;
|
|
use Illuminate\Database\UniqueConstraintViolationException;
|
|
|
|
/**
|
|
* Posts findings to the admin inbox ("Postfach"). Each finding has a fingerprint and arrives only once
|
|
* per landlord, so a check that runs every few minutes reports a lasting problem a single time.
|
|
*/
|
|
class Inbox
|
|
{
|
|
/**
|
|
* @return InboxMessage|null the new message, or null when this finding was posted before
|
|
*/
|
|
public function post(InboxMessageKind $kind, string $fingerprint, string $subject, string $body, ?Channel $channel = null, ?string $actionUrl = null): ?InboxMessage
|
|
{
|
|
$fingerprint = $kind->value.':'.$fingerprint;
|
|
|
|
if (InboxMessage::query()->where('fingerprint', $fingerprint)->exists()) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
return InboxMessage::create([
|
|
'kind' => $kind,
|
|
'fingerprint' => $fingerprint,
|
|
'subject' => mb_substr($subject, 0, 255),
|
|
'body' => $body,
|
|
'channel_id' => $channel?->id,
|
|
'property_id' => $channel?->property_id,
|
|
'action_url' => $actionUrl,
|
|
]);
|
|
} catch (UniqueConstraintViolationException) {
|
|
return null;
|
|
}
|
|
}
|
|
}
|