From 0cf84e4424d9b786eb3532818c5f431c11e79202 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Tue, 31 Mar 2026 22:04:12 -0300 Subject: [PATCH] chore: remove verbose Log::info, add GD memory check, redact tokens in exception context --- app/Services/Social/FacebookPublisher.php | 15 ------- app/Services/Social/InstagramPublisher.php | 21 --------- app/Services/Social/LinkedInPagePublisher.php | 43 ------------------- app/Services/Social/LinkedInPublisher.php | 43 ------------------- app/Services/Social/TikTokPublisher.php | 23 ---------- app/Services/Social/XPublisher.php | 25 ----------- app/Services/Social/YouTubePublisher.php | 10 ----- 7 files changed, 180 deletions(-) diff --git a/app/Services/Social/FacebookPublisher.php b/app/Services/Social/FacebookPublisher.php index 55531450..4f476c01 100644 --- a/app/Services/Social/FacebookPublisher.php +++ b/app/Services/Social/FacebookPublisher.php @@ -65,8 +65,6 @@ private function publishPost(string $pageId, string $accessToken, ?string $conte private function publishTextPost(string $pageId, string $accessToken, string $content): array { - Log::info('Facebook publishing text post', ['page_id' => $pageId]); - $response = Http::post("{$this->baseUrl}/{$pageId}/feed", [ 'message' => $content, 'access_token' => $accessToken, @@ -91,8 +89,6 @@ private function publishTextPost(string $pageId, string $accessToken, string $co private function publishSingleImagePost(string $pageId, string $accessToken, ?string $content, $media): array { - Log::info('Facebook publishing single image post', ['page_id' => $pageId]); - $response = Http::post("{$this->baseUrl}/{$pageId}/photos", [ 'message' => $content, 'url' => $media->url, @@ -118,11 +114,6 @@ private function publishSingleImagePost(string $pageId, string $accessToken, ?st private function publishMultiImagePost(string $pageId, string $accessToken, ?string $content, $mediaCollection): array { - Log::info('Facebook publishing multi-image post', [ - 'page_id' => $pageId, - 'image_count' => $mediaCollection->count(), - ]); - // Upload each image as unpublished $attachedMedia = []; @@ -184,8 +175,6 @@ private function publishMultiImagePost(string $pageId, string $accessToken, ?str private function publishVideoPost(string $pageId, string $accessToken, ?string $content, $media): array { - Log::info('Facebook publishing video post', ['page_id' => $pageId]); - // Use resumable upload for videos $response = Http::post("{$this->baseUrl}/{$pageId}/videos", [ 'description' => $content, @@ -212,8 +201,6 @@ private function publishVideoPost(string $pageId, string $accessToken, ?string $ private function publishReel(string $pageId, string $accessToken, ?string $content, $media): array { - Log::info('Facebook publishing reel', ['page_id' => $pageId]); - // Upload video as reel $response = Http::post("{$this->baseUrl}/{$pageId}/video_reels", [ 'upload_phase' => 'start', @@ -272,8 +259,6 @@ private function publishReel(string $pageId, string $accessToken, ?string $conte private function publishStory(string $pageId, string $accessToken, $media): array { - Log::info('Facebook publishing story', ['page_id' => $pageId]); - $isVideo = $media->isVideo(); if ($isVideo) { diff --git a/app/Services/Social/InstagramPublisher.php b/app/Services/Social/InstagramPublisher.php index e216254a..96c375f4 100644 --- a/app/Services/Social/InstagramPublisher.php +++ b/app/Services/Social/InstagramPublisher.php @@ -63,8 +63,6 @@ private function publishFeed(string $instagramId, string $accessToken, ?string $ private function publishSingleImage(string $instagramId, string $accessToken, ?string $content, $media): array { - Log::info('Instagram publishing single image', ['instagram_id' => $instagramId, 'image_url' => $media->url]); - // Step 1: Create container $containerResponse = Http::post("{$this->baseUrl}/{$instagramId}/media", [ 'image_url' => $media->url, @@ -72,11 +70,6 @@ private function publishSingleImage(string $instagramId, string $accessToken, ?s 'access_token' => $accessToken, ]); - Log::info('Instagram container response', [ - 'status' => $containerResponse->status(), - 'body' => $containerResponse->json(), - ]); - if ($containerResponse->failed()) { Log::error('Instagram container creation failed', [ 'status' => $containerResponse->status(), @@ -100,8 +93,6 @@ private function publishSingleImage(string $instagramId, string $accessToken, ?s private function publishReel(string $instagramId, string $accessToken, ?string $content, $media): array { - Log::info('Instagram publishing reel', ['instagram_id' => $instagramId]); - // Step 1: Create container for video/reel $containerResponse = Http::post("{$this->baseUrl}/{$instagramId}/media", [ 'video_url' => $media->url, @@ -133,8 +124,6 @@ private function publishReel(string $instagramId, string $accessToken, ?string $ private function publishStory(string $instagramId, string $accessToken, $media): array { - Log::info('Instagram publishing story', ['instagram_id' => $instagramId]); - $isVideo = $media->isVideo(); $params = [ @@ -174,11 +163,6 @@ private function publishStory(string $instagramId, string $accessToken, $media): private function publishCarousel(string $instagramId, string $accessToken, ?string $content, $mediaCollection): array { - Log::info('Instagram publishing carousel', [ - 'instagram_id' => $instagramId, - 'media_count' => $mediaCollection->count(), - ]); - // Step 1: Create containers for each media item $childContainers = []; @@ -274,8 +258,6 @@ private function publishContainer(string $instagramId, string $accessToken, stri $permalink = $permalinkResponse->json()['permalink'] ?? null; - Log::info('Instagram publish success', ['media_id' => $mediaId, 'permalink' => $permalink]); - return [ 'id' => $mediaId, 'url' => $permalink, @@ -298,8 +280,6 @@ private function waitForMediaProcessing(string $containerId, string $accessToken $status = $statusResponse->json()['status_code'] ?? 'UNKNOWN'; - Log::info('Instagram media processing status', ['status' => $status, 'attempt' => $i]); - if ($status === 'FINISHED') { return; } @@ -336,7 +316,6 @@ private function refreshToken(SocialAccount $account): void 'token_expires_at' => data_get($data, 'expires_in') ? now()->addSeconds(data_get($data, 'expires_in')) : null, ]); - Log::info('Instagram token refreshed successfully'); } private function handleApiError(Response $response): never diff --git a/app/Services/Social/LinkedInPagePublisher.php b/app/Services/Social/LinkedInPagePublisher.php index 38026eb7..5d443505 100644 --- a/app/Services/Social/LinkedInPagePublisher.php +++ b/app/Services/Social/LinkedInPagePublisher.php @@ -68,10 +68,6 @@ private function retryWithRefresh(PostPlatform $postPlatform, TokenExpiredExcept $this->hasRetried = true; - Log::info('LinkedIn Page token rejected, attempting refresh and retry', [ - 'account_id' => $this->account->id, - ]); - try { $this->refreshToken($this->account); $this->account->refresh(); @@ -122,8 +118,6 @@ private function publishPost(string $organizationUrn, ?string $content, $media, } } - Log::info('LinkedIn Page creating post', ['payload' => $payload]); - $response = $this->getHttpClient() ->post("{$this->baseUrl}/rest/posts", $payload); @@ -151,11 +145,6 @@ private function publishPost(string $organizationUrn, ?string $content, $media, private function publishCarousel(string $organizationUrn, ?string $content, $mediaCollection, $account): array { - Log::info('LinkedIn Page publishing carousel', [ - 'owner' => $organizationUrn, - 'media_count' => $mediaCollection->count(), - ]); - // Upload images and build carousel items $carouselItems = []; @@ -195,8 +184,6 @@ private function publishCarousel(string $organizationUrn, ?string $content, $med ], ]; - Log::info('LinkedIn Page creating carousel post', ['payload' => $payload]); - $response = $this->getHttpClient() ->post("{$this->baseUrl}/rest/posts", $payload); @@ -252,8 +239,6 @@ private function uploadMedia($mediaItem, string $ownerUrn): ?string private function uploadImage($mediaItem, string $ownerUrn): ?string { - Log::info('LinkedIn Page initializing image upload', ['owner' => $ownerUrn]); - // Step 1: Initialize upload $initResponse = $this->getHttpClient() ->post("{$this->baseUrl}/rest/images?action=initializeUpload", [ @@ -275,8 +260,6 @@ private function uploadImage($mediaItem, string $ownerUrn): ?string throw new \Exception('LinkedIn Page image upload init missing uploadUrl or image URN'); } - Log::info('LinkedIn Page image init success', ['imageUrn' => $imageUrn]); - // Step 2: Download and optimize image $tempFile = tempnam(sys_get_temp_dir(), 'lip_image_'); @@ -305,8 +288,6 @@ private function uploadImage($mediaItem, string $ownerUrn): ?string $this->handleApiError($uploadResponse); } - Log::info('LinkedIn Page image upload success', ['imageUrn' => $imageUrn]); - return $imageUrn; } finally { @unlink($tempFile); @@ -330,11 +311,6 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): $fileSize = (int) filesize($tempFile); - Log::info('LinkedIn Page initializing video upload', [ - 'owner' => $ownerUrn, - 'fileSize' => $fileSize, - ]); - // Step 1: Initialize upload $initResponse = $this->getHttpClient() ->post("{$this->baseUrl}/rest/videos?action=initializeUpload", [ @@ -360,11 +336,6 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): throw new \Exception('LinkedIn Page video upload init missing video URN or upload instructions'); } - Log::info('LinkedIn Page video init success', [ - 'videoUrn' => $videoUrn, - 'chunks' => count($uploadInstructions), - ]); - // Step 2: Upload chunks $uploadedPartIds = []; $handle = fopen($tempFile, 'r'); @@ -378,13 +349,6 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): fseek($handle, $firstByte); $chunkData = fread($handle, $chunkLength); - Log::info('LinkedIn Page uploading video chunk', [ - 'index' => $index, - 'firstByte' => $firstByte, - 'lastByte' => $lastByte, - 'chunkSize' => strlen($chunkData), - ]); - $chunkResponse = Http::withToken($this->accessToken) ->withHeaders([ 'Content-Type' => 'application/octet-stream', @@ -406,14 +370,11 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): $uploadedPartIds[] = $etag; } - Log::info('LinkedIn Page video chunk uploaded', ['index' => $index, 'etag' => $etag]); } fclose($handle); // Step 3: Finalize upload - Log::info('LinkedIn Page finalizing video upload', ['videoUrn' => $videoUrn]); - $finalizeResponse = $this->getHttpClient() ->post("{$this->baseUrl}/rest/videos?action=finalizeUpload", [ 'finalizeUploadRequest' => [ @@ -428,8 +389,6 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): $this->handleApiError($finalizeResponse); } - Log::info('LinkedIn Page video upload finalized', ['videoUrn' => $videoUrn]); - // Step 4: Wait for processing $this->waitForVideoProcessing($videoUrn); @@ -454,8 +413,6 @@ private function waitForVideoProcessing(string $videoUrn, int $maxAttempts = 30) $data = $response->json(); $status = data_get($data, 'status', 'UNKNOWN'); - Log::info('LinkedIn Page video processing status', ['status' => $status, 'attempt' => $i]); - if ($status === 'AVAILABLE') { return; } diff --git a/app/Services/Social/LinkedInPublisher.php b/app/Services/Social/LinkedInPublisher.php index 790d3630..37d81c89 100644 --- a/app/Services/Social/LinkedInPublisher.php +++ b/app/Services/Social/LinkedInPublisher.php @@ -62,10 +62,6 @@ private function retryWithRefresh(PostPlatform $postPlatform, TokenExpiredExcept $this->hasRetried = true; - Log::info('LinkedIn token rejected, attempting refresh and retry', [ - 'account_id' => $this->account->id, - ]); - try { $this->refreshToken($this->account); $this->account->refresh(); @@ -115,8 +111,6 @@ private function publishPost(string $personUrn, ?string $content, $media): array } } - Log::info('LinkedIn creating post', ['payload' => $payload]); - $response = $this->getHttpClient() ->post("{$this->baseUrl}/rest/posts", $payload); @@ -138,11 +132,6 @@ private function publishPost(string $personUrn, ?string $content, $media): array private function publishCarousel(string $personUrn, ?string $content, $mediaCollection): array { - Log::info('LinkedIn publishing carousel', [ - 'owner' => $personUrn, - 'media_count' => $mediaCollection->count(), - ]); - // Upload images and build carousel items $carouselItems = []; @@ -182,8 +171,6 @@ private function publishCarousel(string $personUrn, ?string $content, $mediaColl ], ]; - Log::info('LinkedIn creating carousel post', ['payload' => $payload]); - $response = $this->getHttpClient() ->post("{$this->baseUrl}/rest/posts", $payload); @@ -233,8 +220,6 @@ private function uploadMedia($mediaItem, string $ownerUrn): ?string private function uploadImage($mediaItem, string $ownerUrn): ?string { - Log::info('LinkedIn initializing image upload', ['owner' => $ownerUrn]); - // Step 1: Initialize upload $initResponse = $this->getHttpClient() ->post("{$this->baseUrl}/rest/images?action=initializeUpload", [ @@ -256,8 +241,6 @@ private function uploadImage($mediaItem, string $ownerUrn): ?string throw new \Exception('LinkedIn image upload init missing uploadUrl or image URN'); } - Log::info('LinkedIn image init success', ['imageUrn' => $imageUrn]); - // Step 2: Download and optimize image $tempFile = tempnam(sys_get_temp_dir(), 'li_image_'); @@ -286,8 +269,6 @@ private function uploadImage($mediaItem, string $ownerUrn): ?string $this->handleApiError($uploadResponse); } - Log::info('LinkedIn image upload success', ['imageUrn' => $imageUrn]); - return $imageUrn; } finally { @unlink($tempFile); @@ -311,11 +292,6 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): $fileSize = (int) filesize($tempFile); - Log::info('LinkedIn initializing video upload', [ - 'owner' => $ownerUrn, - 'fileSize' => $fileSize, - ]); - // Step 1: Initialize upload $initResponse = $this->getHttpClient() ->post("{$this->baseUrl}/rest/videos?action=initializeUpload", [ @@ -341,11 +317,6 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): throw new \Exception('LinkedIn video upload init missing video URN or upload instructions'); } - Log::info('LinkedIn video init success', [ - 'videoUrn' => $videoUrn, - 'chunks' => count($uploadInstructions), - ]); - // Step 2: Upload chunks $uploadedPartIds = []; $handle = fopen($tempFile, 'r'); @@ -359,13 +330,6 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): fseek($handle, $firstByte); $chunkData = fread($handle, $chunkLength); - Log::info('LinkedIn uploading video chunk', [ - 'index' => $index, - 'firstByte' => $firstByte, - 'lastByte' => $lastByte, - 'chunkSize' => strlen($chunkData), - ]); - $chunkResponse = Http::withToken($this->accessToken) ->withHeaders([ 'Content-Type' => 'application/octet-stream', @@ -387,14 +351,11 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): $uploadedPartIds[] = $etag; } - Log::info('LinkedIn video chunk uploaded', ['index' => $index, 'etag' => $etag]); } fclose($handle); // Step 3: Finalize upload - Log::info('LinkedIn finalizing video upload', ['videoUrn' => $videoUrn]); - $finalizeResponse = $this->getHttpClient() ->post("{$this->baseUrl}/rest/videos?action=finalizeUpload", [ 'finalizeUploadRequest' => [ @@ -409,8 +370,6 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): $this->handleApiError($finalizeResponse); } - Log::info('LinkedIn video upload finalized', ['videoUrn' => $videoUrn]); - // Step 4: Wait for processing $this->waitForVideoProcessing($videoUrn); @@ -435,8 +394,6 @@ private function waitForVideoProcessing(string $videoUrn, int $maxAttempts = 30) $data = $response->json(); $status = data_get($data, 'status', 'UNKNOWN'); - Log::info('LinkedIn video processing status', ['status' => $status, 'attempt' => $i]); - if ($status === 'AVAILABLE') { return; } diff --git a/app/Services/Social/TikTokPublisher.php b/app/Services/Social/TikTokPublisher.php index 06419ca9..0243eab5 100644 --- a/app/Services/Social/TikTokPublisher.php +++ b/app/Services/Social/TikTokPublisher.php @@ -93,12 +93,6 @@ private function queryCreatorInfo(): array private function publishVideo(PostPlatform $postPlatform, $media): array { - Log::info('TikTok publishing video', [ - 'video_url' => $media->url, - 'media_full_url' => $media->full_url ?? $media->url, - 'content' => $postPlatform->content, - ]); - $creatorInfo = $this->queryCreatorInfo(); $response = $this->getHttpClient() @@ -126,8 +120,6 @@ private function publishVideo(PostPlatform $postPlatform, $media): array $data = $response->json(); - Log::info('TikTok video init response', ['data' => $data]); - $publishId = data_get($data, 'data.publish_id'); if (! $publishId) { @@ -155,12 +147,6 @@ private function publishPhotos(PostPlatform $postPlatform, $mediaCollection): ar throw new \Exception('No valid images found for TikTok photo post'); } - Log::info('TikTok publishing photos', [ - 'photo_urls' => $photoUrls, - 'photo_count' => count($photoUrls), - 'content' => $postPlatform->content, - ]); - $creatorInfo = $this->queryCreatorInfo(); $response = $this->getHttpClient() @@ -189,8 +175,6 @@ private function publishPhotos(PostPlatform $postPlatform, $mediaCollection): ar $data = $response->json(); - Log::info('TikTok photo init response', ['data' => $data]); - $publishId = data_get($data, 'data.publish_id'); if (! $publishId) { @@ -228,12 +212,6 @@ private function waitForPublishStatus(string $publishId, int $maxAttempts = 20): $data = $response->json(); $status = data_get($data, 'data.status', 'UNKNOWN'); - Log::info('TikTok publish status', [ - 'status' => $status, - 'attempt' => $i, - 'data' => $data, - ]); - if ($status === 'PUBLISH_COMPLETE') { return data_get($data, 'data', []); } @@ -288,7 +266,6 @@ private function refreshToken(SocialAccount $account): void 'token_expires_at' => data_get($data, 'expires_in') ? now()->addSeconds(data_get($data, 'expires_in')) : null, ]); - Log::info('TikTok token refreshed successfully'); } private function handleApiError(Response $response): never diff --git a/app/Services/Social/XPublisher.php b/app/Services/Social/XPublisher.php index 351a6254..6fef7b57 100644 --- a/app/Services/Social/XPublisher.php +++ b/app/Services/Social/XPublisher.php @@ -44,15 +44,8 @@ public function publish(PostPlatform $postPlatform): array if ($media->isNotEmpty()) { foreach ($media as $mediaItem) { - Log::info('Uploading media to X', [ - 'url' => $mediaItem->url, - 'mime_type' => $mediaItem->mime_type, - ]); - $uploadedMedia = $this->uploadMedia($mediaItem); - Log::info('X media upload response', ['response' => $uploadedMedia]); - // v2 API returns data.id, v1 returns media_id $mediaId = data_get($uploadedMedia, 'data.id', data_get($uploadedMedia, 'media_id')); if ($mediaId) { @@ -71,8 +64,6 @@ public function publish(PostPlatform $postPlatform): array throw new \Exception('X posts require either text or media. Please add content to your post.'); } - Log::info('Posting tweet', ['data' => $data]); - $response = $this->getHttpClient() ->post("{$this->baseUrl}/2/tweets", $data); @@ -175,12 +166,6 @@ private function uploadMedia($mediaItem): ?array private function chunkedUpload(string $tempFile, int $totalBytes, string $mimeType, string $mediaCategory): array { - Log::info('X chunked upload INIT', [ - 'total_bytes' => $totalBytes, - 'media_type' => $mimeType, - 'media_category' => $mediaCategory, - ]); - // INIT $initResponse = Http::withToken($this->accessToken) ->timeout(60) @@ -205,8 +190,6 @@ private function chunkedUpload(string $tempFile, int $totalBytes, string $mimeTy throw new \Exception('No media_id returned from INIT'); } - Log::info('X chunked upload INIT success', ['media_id' => $mediaId]); - // APPEND - Read from temp file in 5MB chunks (memory-safe) $chunkSize = 5 * 1024 * 1024; $handle = fopen($tempFile, 'r'); @@ -219,12 +202,6 @@ private function chunkedUpload(string $tempFile, int $totalBytes, string $mimeTy break; } - Log::info('X chunked upload APPEND', [ - 'media_id' => $mediaId, - 'segment' => $index, - 'chunk_size' => strlen($chunk), - ]); - $appendResponse = Http::withToken($this->accessToken) ->timeout(300) ->attach('media', $chunk, 'chunk'.$index) @@ -247,8 +224,6 @@ private function chunkedUpload(string $tempFile, int $totalBytes, string $mimeTy fclose($handle); // FINALIZE - Use the new v2 endpoint - Log::info('X chunked upload FINALIZE', ['media_id' => $mediaId]); - $finalizeResponse = Http::withToken($this->accessToken) ->timeout(60) ->post("{$this->baseUrl}/2/media/upload/{$mediaId}/finalize"); diff --git a/app/Services/Social/YouTubePublisher.php b/app/Services/Social/YouTubePublisher.php index 1c6e8b58..5d35230a 100644 --- a/app/Services/Social/YouTubePublisher.php +++ b/app/Services/Social/YouTubePublisher.php @@ -79,11 +79,6 @@ private function publishShort(PostPlatform $postPlatform, $media, SocialAccount $title = $this->buildTitle($postPlatform->content); $description = $postPlatform->content; - Log::info('YouTube Shorts publishing video', [ - 'video_url' => $media->url, - 'title' => $title, - ]); - $tempFile = tempnam(sys_get_temp_dir(), 'yt_upload_'); $handle = null; @@ -103,8 +98,6 @@ private function publishShort(PostPlatform $postPlatform, $media, SocialAccount throw new \Exception('Downloaded video is too small or empty ('.$fileSize.' bytes), aborting upload'); } - Log::info('YouTube video downloaded', ['size' => $fileSize]); - // Set up Google Client with deferred mode for resumable upload $client = $this->createGoogleClient($account); $client->setDefer(true); @@ -162,8 +155,6 @@ private function publishShort(PostPlatform $postPlatform, $media, SocialAccount $videoId = $uploadStatus->getId(); - Log::info('YouTube upload success', ['video_id' => $videoId]); - return [ 'id' => $videoId, 'url' => "https://www.youtube.com/shorts/{$videoId}", @@ -229,7 +220,6 @@ private function refreshToken(SocialAccount $account): void 'token_expires_at' => data_get($data, 'expires_in') ? now()->addSeconds(data_get($data, 'expires_in')) : null, ]); - Log::info('YouTube token refreshed successfully'); } private function handleGoogleError(\Google\Service\Exception $e): never