Das Widget prüft nur noch, dass der Einstieg existiert; die Auswahl im Editor bietet weiter nur veröffentlichte an. Der Worker kennt keine Anfrage und APP_URL ist unzuverlässig, daher gibt die Web-Anfrage die Adresse der Anfrage in der Verwaltung an die Aufgabe weiter. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Domain\Communication\CommunicationSettings;
|
|
use App\Domain\Communication\Inquiry;
|
|
use App\Mail\InquiryReceived;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Str;
|
|
use Throwable;
|
|
|
|
/**
|
|
* Interne Benachrichtigung über eine neue Anfrage. Die Anfrage ist zu diesem Zeitpunkt bereits gespeichert; ein Fehler
|
|
* hier wird an der Anfrage vermerkt (notification_error), geht nie verloren und lässt sich in der Verwaltung wiederholen.
|
|
*/
|
|
class SendInquiryNotification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public int $tries = 1;
|
|
|
|
/**
|
|
* @param ?string $adminUrl Adresse der Anfrage in der Verwaltung, während der Web-Anfrage berechnet: Im Worker
|
|
* gibt es keine Anfrage, und APP_URL gilt in diesem Projekt nicht als verlässlich.
|
|
*/
|
|
public function __construct(public int $inquiryId, public ?string $adminUrl = null) {}
|
|
|
|
public function handle(): void
|
|
{
|
|
$inquiry = Inquiry::query()->find($this->inquiryId);
|
|
|
|
if ($inquiry === null) {
|
|
return;
|
|
}
|
|
|
|
$recipients = CommunicationSettings::current()->recipientList();
|
|
|
|
if ($recipients === []) {
|
|
$inquiry->forceFill(['notification_error' => 'Es sind keine Empfänger für Benachrichtigungen hinterlegt (Kommunikation → Einstellungen).'])->save();
|
|
|
|
return;
|
|
}
|
|
|
|
try {
|
|
Mail::to($recipients)->send(new InquiryReceived($inquiry, $this->adminUrl));
|
|
} catch (Throwable $e) {
|
|
report($e);
|
|
$inquiry->forceFill(['notification_error' => 'Der E-Mail-Versand ist fehlgeschlagen: '.Str::limit($e->getMessage(), 400)])->save();
|
|
|
|
return;
|
|
}
|
|
|
|
$inquiry->forceFill(['notified_at' => now(), 'notification_error' => null])->save();
|
|
}
|
|
}
|