🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 13:39
This commit is contained in:
37
queue/Jobs/SendNotificationJob.php
Normal file
37
queue/Jobs/SendNotificationJob.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user