feat: clean vr
This commit is contained in:
@@ -24,72 +24,27 @@ public function __construct(
|
|||||||
|
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
\Log::info("=== Starting SendPushToPackageJob ===");
|
if (!$firebaseFile = $this->getFirebaseJsonPath()) {
|
||||||
\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);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$factory = (new Factory)->withServiceAccount($firebaseFile);
|
$messaging = (new Factory)
|
||||||
$messaging = $factory->createMessaging();
|
->withServiceAccount($firebaseFile)
|
||||||
|
->createMessaging();
|
||||||
|
|
||||||
// Get all users that have this package AND have an FCM token
|
|
||||||
$users = $this->packageName->users()
|
$users = $this->packageName->users()
|
||||||
->whereNotNull('user_package_name.fcm_token')
|
->whereNotNull('user_package_name.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) {
|
||||||
\Log::info("Processing user ID: " . $user->id);
|
$fcmToken = $user->packageNames()
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,36 +55,17 @@ public function handle(): void
|
|||||||
])
|
])
|
||||||
->withData($this->data);
|
->withData($this->data);
|
||||||
|
|
||||||
\Log::info("Sending message to user " . $user->id . " with token: " . substr($fcmToken, 0, 20) . "...");
|
$messaging->send($message);
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
\Log::info("=== Completed SendPushToPackageJob ===");
|
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
\Log::error('Firebase error in SendPushToPackageJob: ' . $e->getMessage());
|
\Log::error('SendPushToPackageJob failed: ' . $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');
|
||||||
if (!$media) {
|
return $media?->getPath();
|
||||||
\Log::warning('No media found for collection firebase_json');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$path = $media->getPath();
|
|
||||||
\Log::info('Media path: ' . $path);
|
|
||||||
return $path;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user