38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Queue\Jobs;
|
|
|
|
use App\Core\Database;
|
|
use Throwable;
|
|
|
|
final class SendNotificationJob
|
|
{
|
|
public function handle(array $payload): void
|
|
{
|
|
$userId = $payload['user_id'];
|
|
$title = $payload['title'];
|
|
$message = $payload['message'];
|
|
$type = $payload['type'] ?? 'info';
|
|
|
|
try {
|
|
$db = Database::getInstance();
|
|
$stmt = $db->prepare("INSERT INTO notifications (id, user_id, title, message, type, is_read, created_at) VALUES (?, ?, ?, ?, ?, 0, NOW())");
|
|
$stmt->execute([
|
|
\Ramsey\Uuid\Uuid::uuid4()->toString(),
|
|
$userId,
|
|
$title,
|
|
$message,
|
|
$type
|
|
]);
|
|
|
|
// Here we could also trigger WebSockets or push notifications if implemented
|
|
|
|
} catch (Throwable $e) {
|
|
echo "[!] Notification failed for user {$userId}: " . $e->getMessage() . "\n";
|
|
throw $e;
|
|
}
|
|
}
|
|
}
|