This commit is contained in:
2025-12-12 20:08:04 +03:30
parent 3aab22fe2c
commit b19ffc08c6
+63 -8
View File
@@ -24,9 +24,38 @@ public function __construct(
public function handle(): void public function handle(): void
{ {
\Log::info("=== Starting SendPushToPackageJob ===");
\Log::info("Package ID: " . $this->packageName->id);
\Log::info("Package Name: " . $this->packageName->name);
\Log::info("Title: " . $this->title);
\Log::info("Description: " . $this->description);
// Check if package exists
if (!$this->packageName) {
\Log::error("PackageName not found!");
return;
}
$firebaseFile = $this->getFirebaseJsonPath(); $firebaseFile = $this->getFirebaseJsonPath();
\Log::info("Firebase file path: " . ($firebaseFile ?: 'NOT FOUND'));
if (!$firebaseFile) { if (!$firebaseFile) {
\Log::warning('Firebase JSON file not found for package: ' . $this->packageName->id); \Log::warning('Firebase JSON file not found for package: ' . $this->packageName->id);
\Log::warning('Package ID: ' . $this->packageName->id);
// Check if media exists
$media = $this->packageName->getFirstMedia('firebase_json');
if (!$media) {
\Log::warning('No media found with collection name: firebase_json');
} else {
\Log::warning('Media found: ' . $media->file_name);
}
return;
}
// Check if file exists
if (!file_exists($firebaseFile)) {
\Log::error("Firebase JSON file does not exist at path: " . $firebaseFile);
return; return;
} }
@@ -39,14 +68,28 @@ public function handle(): void
->whereNotNull('package_name_user.fcm_token') ->whereNotNull('package_name_user.fcm_token')
->get(); ->get();
\Log::info("Found " . $users->count() . " users with FCM tokens for package " . $this->packageName->id);
if ($users->isEmpty()) {
\Log::warning("No users with FCM tokens found for package: " . $this->packageName->id);
return;
}
foreach ($users as $user) { foreach ($users as $user) {
$fcmToken = $user->packageNames() \Log::info("Processing user ID: " . $user->id);
// Get the FCM token from pivot table
$pivot = $user->packageNames()
->where('package_names.id', $this->packageName->id) ->where('package_names.id', $this->packageName->id)
->first() ->first()
->pivot ->pivot;
->fcm_token;
$fcmToken = $pivot->fcm_token;
\Log::info("User " . $user->id . " FCM Token: " . ($fcmToken ?: 'NOT FOUND'));
if (!$fcmToken) { if (!$fcmToken) {
\Log::warning("Skipping user " . $user->id . " - no FCM token");
continue; continue;
} }
@@ -57,24 +100,36 @@ public function handle(): void
]) ])
->withData($this->data); ->withData($this->data);
\Log::info("Sending message to user " . $user->id . " with token: " . substr($fcmToken, 0, 20) . "...");
try { try {
$messaging->send($message); $result = $messaging->send($message);
\Log::info("Push notification sent to user {$user->id} for package {$this->packageName->id}"); \Log::info("SUCCESS: Push notification sent to user {$user->id}");
\Log::info("Message ID: " . ($result ?: 'No result returned'));
} catch (\Throwable $e) { } catch (\Throwable $e) {
\Log::error("Failed to send push to user {$user->id}: " . $e->getMessage()); \Log::error("FAILED to send push to user {$user->id}: " . $e->getMessage());
\Log::error("Error details: " . $e->getTraceAsString());
} }
} }
\Log::info("Sent push notifications to " . $users->count() . " users for package: " . $this->packageName->id); \Log::info("=== Completed SendPushToPackageJob ===");
} catch (\Throwable $e) { } catch (\Throwable $e) {
\Log::error('Firebase error in SendPushToPackageJob: ' . $e->getMessage()); \Log::error('Firebase error in SendPushToPackageJob: ' . $e->getMessage());
\Log::error('Stack trace: ' . $e->getTraceAsString());
} }
} }
private function getFirebaseJsonPath(): ?string private function getFirebaseJsonPath(): ?string
{ {
$media = $this->packageName->getFirstMedia('firebase_json'); $media = $this->packageName->getFirstMedia('firebase_json');
return $media?->getPath(); if (!$media) {
\Log::warning('No media found for collection firebase_json');
return null;
}
$path = $media->getPath();
\Log::info('Media path: ' . $path);
return $path;
} }
} }