Implement package limit notification system
This commit is contained in:
71
app/Jobs/Packages/SendEventPackageGalleryWarning.php
Normal file
71
app/Jobs/Packages/SendEventPackageGalleryWarning.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Packages;
|
||||
|
||||
use App\Models\EventPackage;
|
||||
use App\Notifications\Packages\EventPackageGalleryExpiringNotification;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
class SendEventPackageGalleryWarning implements ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithQueue;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public int $eventPackageId,
|
||||
public int $daysRemaining,
|
||||
) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$eventPackage = EventPackage::with(['event', 'package', 'event.tenant'])->find($this->eventPackageId);
|
||||
|
||||
if (! $eventPackage) {
|
||||
Log::warning('Gallery warning job skipped; event package missing', [
|
||||
'event_package_id' => $this->eventPackageId,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$tenant = $eventPackage->event?->tenant;
|
||||
if (! $tenant) {
|
||||
return;
|
||||
}
|
||||
|
||||
$preferences = app(\App\Services\Packages\TenantNotificationPreferences::class);
|
||||
if (! $preferences->shouldNotify($tenant, 'gallery_warnings')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$emails = collect([
|
||||
$tenant->contact_email,
|
||||
$tenant->user?->email,
|
||||
])->filter(fn ($email) => is_string($email) && filter_var($email, FILTER_VALIDATE_EMAIL))
|
||||
->unique();
|
||||
|
||||
if ($emails->isEmpty()) {
|
||||
Log::info('Gallery warning skipped due to missing recipients', [
|
||||
'event_package_id' => $eventPackage->id,
|
||||
'days_remaining' => $this->daysRemaining,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($emails as $email) {
|
||||
Notification::route('mail', $email)->notify(new EventPackageGalleryExpiringNotification(
|
||||
$eventPackage,
|
||||
$this->daysRemaining,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user