feat: clean vr
This commit is contained in:
@@ -24,72 +24,27 @@ public function __construct(
|
||||
|
||||
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();
|
||||
\Log::info("Firebase file path: " . ($firebaseFile ?: 'NOT FOUND'));
|
||||
|
||||
if (!$firebaseFile) {
|
||||
\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);
|
||||
if (!$firebaseFile = $this->getFirebaseJsonPath()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$factory = (new Factory)->withServiceAccount($firebaseFile);
|
||||
$messaging = $factory->createMessaging();
|
||||
$messaging = (new Factory)
|
||||
->withServiceAccount($firebaseFile)
|
||||
->createMessaging();
|
||||
|
||||
// Get all users that have this package AND have an FCM token
|
||||
$users = $this->packageName->users()
|
||||
->whereNotNull('user_package_name.fcm_token')
|
||||
->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) {
|
||||
\Log::info("Processing user ID: " . $user->id);
|
||||
|
||||
// Get the FCM token from pivot table
|
||||
$pivot = $user->packageNames()
|
||||
$fcmToken = $user->packageNames()
|
||||
->where('package_names.id', $this->packageName->id)
|
||||
->first()
|
||||
->pivot;
|
||||
|
||||
$fcmToken = $pivot->fcm_token;
|
||||
|
||||
\Log::info("User " . $user->id . " FCM Token: " . ($fcmToken ?: 'NOT FOUND'));
|
||||
->pivot
|
||||
->fcm_token;
|
||||
|
||||
if (!$fcmToken) {
|
||||
\Log::warning("Skipping user " . $user->id . " - no FCM token");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -100,36 +55,17 @@ public function handle(): void
|
||||
])
|
||||
->withData($this->data);
|
||||
|
||||
\Log::info("Sending message to user " . $user->id . " with token: " . substr($fcmToken, 0, 20) . "...");
|
||||
|
||||
try {
|
||||
$result = $messaging->send($message);
|
||||
\Log::info("SUCCESS: Push notification sent to user {$user->id}");
|
||||
\Log::info("Message ID: " . ($result ?: 'No result returned'));
|
||||
} catch (\Throwable $e) {
|
||||
\Log::error("FAILED to send push to user {$user->id}: " . $e->getMessage());
|
||||
\Log::error("Error details: " . $e->getTraceAsString());
|
||||
}
|
||||
$messaging->send($message);
|
||||
}
|
||||
|
||||
\Log::info("=== Completed SendPushToPackageJob ===");
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
\Log::error('Firebase error in SendPushToPackageJob: ' . $e->getMessage());
|
||||
\Log::error('Stack trace: ' . $e->getTraceAsString());
|
||||
\Log::error('SendPushToPackageJob failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function getFirebaseJsonPath(): ?string
|
||||
{
|
||||
$media = $this->packageName->getFirstMedia('firebase_json');
|
||||
if (!$media) {
|
||||
\Log::warning('No media found for collection firebase_json');
|
||||
return null;
|
||||
}
|
||||
|
||||
$path = $media->getPath();
|
||||
\Log::info('Media path: ' . $path);
|
||||
return $path;
|
||||
return $media?->getPath();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user