verbesserung von benachrichtungen und warnungen an nutzer abgeschlossen. layout editor nun auf gutem stand.

This commit is contained in:
Codex Agent
2025-11-02 11:11:13 +01:00
parent 8e6c66f0db
commit 792b5dfe8b
32 changed files with 1292 additions and 149 deletions

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Jobs\Concerns;
use App\Models\Tenant;
use App\Services\Packages\TenantNotificationLogger;
use Illuminate\Support\Facades\Log;
trait LogsTenantNotifications
{
protected function notificationLogger(): TenantNotificationLogger
{
return app(TenantNotificationLogger::class);
}
protected function logNotification(Tenant $tenant, array $attributes): void
{
$this->notificationLogger()->log($tenant, $attributes);
}
protected function dispatchToRecipients(
Tenant $tenant,
iterable $recipients,
string $type,
callable $callback,
array $context = []
): void {
foreach ($recipients as $recipient) {
try {
$callback($recipient);
$this->logNotification($tenant, [
'type' => $type,
'channel' => 'mail',
'recipient' => $recipient,
'status' => 'sent',
'context' => $context,
'sent_at' => now(),
]);
} catch (\Throwable $e) {
Log::error('Tenant notification failed', [
'tenant_id' => $tenant->id,
'type' => $type,
'recipient' => $recipient,
'error' => $e->getMessage(),
]);
$this->logNotification($tenant, [
'type' => $type,
'channel' => 'mail',
'recipient' => $recipient,
'status' => 'failed',
'context' => $context,
'failed_at' => now(),
'failure_reason' => $e->getMessage(),
]);
}
}
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\EventPackage;
use App\Notifications\Packages\EventPackageGalleryExpiredNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendEventPackageGalleryExpired implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -40,6 +42,12 @@ class SendEventPackageGalleryExpired implements ShouldQueue
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenant, 'gallery_expired')) {
$this->logNotification($tenant, [
'type' => 'gallery_expired',
'status' => 'skipped',
'context' => $this->context($eventPackage),
]);
return;
}
@@ -54,11 +62,33 @@ class SendEventPackageGalleryExpired implements ShouldQueue
'event_package_id' => $eventPackage->id,
]);
$this->logNotification($tenant, [
'type' => 'gallery_expired',
'status' => 'skipped',
'context' => array_merge($this->context($eventPackage), ['reason' => 'no_recipient']),
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(new EventPackageGalleryExpiredNotification($eventPackage));
}
$context = $this->context($eventPackage);
$this->dispatchToRecipients(
$tenant,
$emails,
'gallery_expired',
function (string $email) use ($eventPackage) {
Notification::route('mail', $email)->notify(new EventPackageGalleryExpiredNotification($eventPackage));
},
$context
);
}
private function context(EventPackage $eventPackage): array
{
return [
'event_package_id' => $eventPackage->id,
'event_id' => $eventPackage->event_id,
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\EventPackage;
use App\Notifications\Packages\EventPackageGalleryExpiringNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendEventPackageGalleryWarning implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -43,6 +45,12 @@ class SendEventPackageGalleryWarning implements ShouldQueue
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenant, 'gallery_warnings')) {
$this->logNotification($tenant, [
'type' => 'gallery_warning',
'status' => 'skipped',
'context' => $this->context($eventPackage),
]);
return;
}
@@ -58,14 +66,37 @@ class SendEventPackageGalleryWarning implements ShouldQueue
'days_remaining' => $this->daysRemaining,
]);
$this->logNotification($tenant, [
'type' => 'gallery_warning',
'status' => 'skipped',
'context' => array_merge($this->context($eventPackage), ['reason' => 'no_recipient']),
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(new EventPackageGalleryExpiringNotification(
$eventPackage,
$this->daysRemaining,
));
}
$context = $this->context($eventPackage);
$this->dispatchToRecipients(
$tenant,
$emails,
'gallery_warning',
function (string $email) use ($eventPackage) {
Notification::route('mail', $email)->notify(new EventPackageGalleryExpiringNotification(
$eventPackage,
$this->daysRemaining,
));
},
$context
);
}
private function context(EventPackage $eventPackage): array
{
return [
'event_package_id' => $eventPackage->id,
'event_id' => $eventPackage->event_id,
'days_remaining' => $this->daysRemaining,
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\EventPackage;
use App\Notifications\Packages\EventPackageGuestLimitNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendEventPackageGuestLimitNotification implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -43,6 +45,12 @@ class SendEventPackageGuestLimitNotification implements ShouldQueue
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenant, 'guest_limits')) {
$this->logNotification($tenant, [
'type' => 'guest_limit',
'status' => 'skipped',
'context' => $this->context($eventPackage),
]);
return;
}
@@ -57,14 +65,37 @@ class SendEventPackageGuestLimitNotification implements ShouldQueue
'event_package_id' => $eventPackage->id,
]);
$this->logNotification($tenant, [
'type' => 'guest_limit',
'status' => 'skipped',
'context' => array_merge($this->context($eventPackage), ['reason' => 'no_recipient']),
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(new EventPackageGuestLimitNotification(
$eventPackage,
$this->limit,
));
}
$context = $this->context($eventPackage);
$this->dispatchToRecipients(
$tenant,
$emails,
'guest_limit',
function (string $email) use ($eventPackage) {
Notification::route('mail', $email)->notify(new EventPackageGuestLimitNotification(
$eventPackage,
$this->limit,
));
},
$context
);
}
private function context(EventPackage $eventPackage): array
{
return [
'event_package_id' => $eventPackage->id,
'event_id' => $eventPackage->event_id,
'limit' => $this->limit,
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\EventPackage;
use App\Notifications\Packages\EventPackageGuestThresholdNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendEventPackageGuestThresholdWarning implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -45,6 +47,12 @@ class SendEventPackageGuestThresholdWarning implements ShouldQueue
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenant, 'guest_thresholds')) {
$this->logNotification($tenant, [
'type' => 'guest_threshold',
'status' => 'skipped',
'context' => $this->context($eventPackage),
]);
return;
}
@@ -60,16 +68,41 @@ class SendEventPackageGuestThresholdWarning implements ShouldQueue
'threshold' => $this->threshold,
]);
$this->logNotification($tenant, [
'type' => 'guest_threshold',
'status' => 'skipped',
'context' => array_merge($this->context($eventPackage), ['reason' => 'no_recipient']),
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(new EventPackageGuestThresholdNotification(
$eventPackage,
$this->threshold,
$this->limit,
$this->used,
));
}
$context = $this->context($eventPackage);
$this->dispatchToRecipients(
$tenant,
$emails,
'guest_threshold',
function (string $email) use ($eventPackage) {
Notification::route('mail', $email)->notify(new EventPackageGuestThresholdNotification(
$eventPackage,
$this->threshold,
$this->limit,
$this->used,
));
},
$context
);
}
private function context(EventPackage $eventPackage): array
{
return [
'event_package_id' => $eventPackage->id,
'event_id' => $eventPackage->event_id,
'threshold' => $this->threshold,
'limit' => $this->limit,
'used' => $this->used,
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\EventPackage;
use App\Notifications\Packages\EventPackagePhotoLimitNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendEventPackagePhotoLimitNotification implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -43,6 +45,12 @@ class SendEventPackagePhotoLimitNotification implements ShouldQueue
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenant, 'photo_limits')) {
$this->logNotification($tenant, [
'type' => 'photo_limit',
'status' => 'skipped',
'context' => $this->context($eventPackage),
]);
return;
}
@@ -58,16 +66,39 @@ class SendEventPackagePhotoLimitNotification implements ShouldQueue
'limit' => $this->limit,
]);
$this->logNotification($tenant, [
'type' => 'photo_limit',
'status' => 'skipped',
'context' => array_merge($this->context($eventPackage), ['reason' => 'no_recipient']),
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(
new EventPackagePhotoLimitNotification(
$eventPackage,
$this->limit,
)
);
}
$context = $this->context($eventPackage);
$this->dispatchToRecipients(
$tenant,
$emails,
'photo_limit',
function (string $email) use ($eventPackage) {
Notification::route('mail', $email)->notify(
new EventPackagePhotoLimitNotification(
$eventPackage,
$this->limit,
)
);
},
$context
);
}
private function context(EventPackage $eventPackage): array
{
return [
'event_package_id' => $eventPackage->id,
'event_id' => $eventPackage->event_id,
'limit' => $this->limit,
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\EventPackage;
use App\Notifications\Packages\EventPackagePhotoThresholdNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendEventPackagePhotoThresholdWarning implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -45,6 +47,12 @@ class SendEventPackagePhotoThresholdWarning implements ShouldQueue
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenant, 'photo_thresholds')) {
$this->logNotification($tenant, [
'type' => 'photo_threshold',
'status' => 'skipped',
'context' => $this->context($eventPackage),
]);
return;
}
@@ -60,18 +68,43 @@ class SendEventPackagePhotoThresholdWarning implements ShouldQueue
'threshold' => $this->threshold,
]);
$this->logNotification($tenant, [
'type' => 'photo_threshold',
'status' => 'skipped',
'context' => array_merge($this->context($eventPackage), ['reason' => 'no_recipient']),
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(
new EventPackagePhotoThresholdNotification(
$eventPackage,
$this->threshold,
$this->limit,
$this->used,
)
);
}
$context = $this->context($eventPackage);
$this->dispatchToRecipients(
$tenant,
$emails,
'photo_threshold',
function (string $email) use ($eventPackage) {
Notification::route('mail', $email)->notify(
new EventPackagePhotoThresholdNotification(
$eventPackage,
$this->threshold,
$this->limit,
$this->used,
)
);
},
$context
);
}
private function context(EventPackage $eventPackage): array
{
return [
'event_package_id' => $eventPackage->id,
'event_id' => $eventPackage->event_id,
'threshold' => $this->threshold,
'limit' => $this->limit,
'used' => $this->used,
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\Tenant;
use App\Notifications\Packages\TenantCreditsLowNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendTenantCreditsLowNotification implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -39,6 +41,16 @@ class SendTenantCreditsLowNotification implements ShouldQueue
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenant, 'credits_low')) {
$this->logNotification($tenant, [
'type' => 'credits_low',
'status' => 'skipped',
'context' => [
'balance' => $this->balance,
'threshold' => $this->threshold,
'reason' => 'opt_out',
],
]);
return;
}
@@ -53,15 +65,36 @@ class SendTenantCreditsLowNotification implements ShouldQueue
'tenant_id' => $tenant->id,
]);
$this->logNotification($tenant, [
'type' => 'credits_low',
'status' => 'skipped',
'context' => [
'balance' => $this->balance,
'threshold' => $this->threshold,
'reason' => 'no_recipient',
],
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(new TenantCreditsLowNotification(
$tenant,
$this->balance,
$this->threshold,
));
}
$context = [
'balance' => $this->balance,
'threshold' => $this->threshold,
];
$this->dispatchToRecipients(
$tenant,
$emails,
'credits_low',
function (string $email) use ($tenant) {
Notification::route('mail', $email)->notify(new TenantCreditsLowNotification(
$tenant,
$this->balance,
$this->threshold,
));
},
$context
);
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\TenantPackage;
use App\Notifications\Packages\TenantPackageEventLimitNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendTenantPackageEventLimitNotification implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -36,14 +38,22 @@ class SendTenantPackageEventLimitNotification implements ShouldQueue
return;
}
$tenant = $tenantPackage->tenant;
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenantPackage->tenant, 'event_limits')) {
if (! $preferences->shouldNotify($tenant, 'event_limits')) {
$this->logNotification($tenant, [
'type' => 'event_limit',
'status' => 'skipped',
'context' => $this->context($tenantPackage),
]);
return;
}
$emails = collect([
$tenantPackage->tenant->contact_email,
$tenantPackage->tenant->user?->email,
$tenant->contact_email,
$tenant->user?->email,
])->filter(fn ($email) => is_string($email) && filter_var($email, FILTER_VALIDATE_EMAIL))
->unique();
@@ -52,14 +62,36 @@ class SendTenantPackageEventLimitNotification implements ShouldQueue
'tenant_package_id' => $tenantPackage->id,
]);
$this->logNotification($tenant, [
'type' => 'event_limit',
'status' => 'skipped',
'context' => array_merge($this->context($tenantPackage), ['reason' => 'no_recipient']),
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(new TenantPackageEventLimitNotification(
$tenantPackage,
$this->limit,
));
}
$context = $this->context($tenantPackage);
$this->dispatchToRecipients(
$tenant,
$emails,
'event_limit',
function (string $email) use ($tenantPackage) {
Notification::route('mail', $email)->notify(new TenantPackageEventLimitNotification(
$tenantPackage,
$this->limit,
));
},
$context
);
}
private function context(TenantPackage $tenantPackage): array
{
return [
'tenant_package_id' => $tenantPackage->id,
'limit' => $this->limit,
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\TenantPackage;
use App\Notifications\Packages\TenantPackageEventThresholdNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendTenantPackageEventThresholdWarning implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -38,14 +40,22 @@ class SendTenantPackageEventThresholdWarning implements ShouldQueue
return;
}
$tenant = $tenantPackage->tenant;
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenantPackage->tenant, 'event_thresholds')) {
if (! $preferences->shouldNotify($tenant, 'event_thresholds')) {
$this->logNotification($tenant, [
'type' => 'event_threshold',
'status' => 'skipped',
'context' => $this->context($tenantPackage),
]);
return;
}
$emails = collect([
$tenantPackage->tenant->contact_email,
$tenantPackage->tenant->user?->email,
$tenant->contact_email,
$tenant->user?->email,
])->filter(fn ($email) => is_string($email) && filter_var($email, FILTER_VALIDATE_EMAIL))
->unique();
@@ -55,16 +65,40 @@ class SendTenantPackageEventThresholdWarning implements ShouldQueue
'threshold' => $this->threshold,
]);
$this->logNotification($tenant, [
'type' => 'event_threshold',
'status' => 'skipped',
'context' => array_merge($this->context($tenantPackage), ['reason' => 'no_recipient']),
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(new TenantPackageEventThresholdNotification(
$tenantPackage,
$this->threshold,
$this->limit,
$this->used,
));
}
$context = $this->context($tenantPackage);
$this->dispatchToRecipients(
$tenant,
$emails,
'event_threshold',
function (string $email) use ($tenantPackage) {
Notification::route('mail', $email)->notify(new TenantPackageEventThresholdNotification(
$tenantPackage,
$this->threshold,
$this->limit,
$this->used,
));
},
$context
);
}
private function context(TenantPackage $tenantPackage): array
{
return [
'tenant_package_id' => $tenantPackage->id,
'threshold' => $this->threshold,
'limit' => $this->limit,
'used' => $this->used,
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\TenantPackage;
use App\Notifications\Packages\TenantPackageExpiredNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendTenantPackageExpiredNotification implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -33,14 +35,25 @@ class SendTenantPackageExpiredNotification implements ShouldQueue
return;
}
$tenant = $tenantPackage->tenant;
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenantPackage->tenant, 'package_expired')) {
if (! $preferences->shouldNotify($tenant, 'package_expired')) {
$this->logNotification($tenant, [
'type' => 'package_expired',
'status' => 'skipped',
'context' => [
'tenant_package_id' => $tenantPackage->id,
'reason' => 'opt_out',
],
]);
return;
}
$emails = collect([
$tenantPackage->tenant->contact_email,
$tenantPackage->tenant->user?->email,
$tenant->contact_email,
$tenant->user?->email,
])->filter(fn ($email) => is_string($email) && filter_var($email, FILTER_VALIDATE_EMAIL))
->unique();
@@ -49,11 +62,30 @@ class SendTenantPackageExpiredNotification implements ShouldQueue
'tenant_package_id' => $tenantPackage->id,
]);
$this->logNotification($tenant, [
'type' => 'package_expired',
'status' => 'skipped',
'context' => [
'tenant_package_id' => $tenantPackage->id,
'reason' => 'no_recipient',
],
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(new TenantPackageExpiredNotification($tenantPackage));
}
$context = [
'tenant_package_id' => $tenantPackage->id,
];
$this->dispatchToRecipients(
$tenant,
$emails,
'package_expired',
function (string $email) use ($tenantPackage) {
Notification::route('mail', $email)->notify(new TenantPackageExpiredNotification($tenantPackage));
},
$context
);
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Packages;
use App\Jobs\Concerns\LogsTenantNotifications;
use App\Models\TenantPackage;
use App\Notifications\Packages\TenantPackageExpiringNotification;
use Illuminate\Bus\Queueable;
@@ -16,6 +17,7 @@ class SendTenantPackageExpiringNotification implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use LogsTenantNotifications;
use Queueable;
use SerializesModels;
@@ -36,14 +38,26 @@ class SendTenantPackageExpiringNotification implements ShouldQueue
return;
}
$tenant = $tenantPackage->tenant;
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
if (! $preferences->shouldNotify($tenantPackage->tenant, 'package_expiring')) {
if (! $preferences->shouldNotify($tenant, 'package_expiring')) {
$this->logNotification($tenant, [
'type' => 'package_expiring',
'status' => 'skipped',
'context' => [
'tenant_package_id' => $tenantPackage->id,
'days_remaining' => $this->daysRemaining,
'reason' => 'opt_out',
],
]);
return;
}
$emails = collect([
$tenantPackage->tenant->contact_email,
$tenantPackage->tenant->user?->email,
$tenant->contact_email,
$tenant->user?->email,
])->filter(fn ($email) => is_string($email) && filter_var($email, FILTER_VALIDATE_EMAIL))
->unique();
@@ -53,14 +67,35 @@ class SendTenantPackageExpiringNotification implements ShouldQueue
'days_remaining' => $this->daysRemaining,
]);
$this->logNotification($tenant, [
'type' => 'package_expiring',
'status' => 'skipped',
'context' => [
'tenant_package_id' => $tenantPackage->id,
'days_remaining' => $this->daysRemaining,
'reason' => 'no_recipient',
],
]);
return;
}
foreach ($emails as $email) {
Notification::route('mail', $email)->notify(new TenantPackageExpiringNotification(
$tenantPackage,
$this->daysRemaining,
));
}
$context = [
'tenant_package_id' => $tenantPackage->id,
'days_remaining' => $this->daysRemaining,
];
$this->dispatchToRecipients(
$tenant,
$emails,
'package_expiring',
function (string $email) use ($tenantPackage) {
Notification::route('mail', $email)->notify(new TenantPackageExpiringNotification(
$tenantPackage,
$this->daysRemaining,
));
},
$context
);
}
}