Pinterest Integration: - Add Pinterest OAuth controller and routes - Add PinterestPublisher service with support for pins, video pins, and carousels - Add PinterestPreview component with board selector and content type options - Add Pinterest content types enum (Pin, VideoPin, Carousel) - Add Pinterest to Platform enum with proper configuration - Support sandbox mode via PINTEREST_SANDBOX env variable - Pass platform-specific data (boards) through PlatformPreview Language Feature: - Add languages table with migration - Add Language model and seeder (en-US, pt-BR) - Add LanguageCombobox component for profile settings - Set default language (en-US) on user registration - Add language_id foreign key to users table UI Improvements: - Refactor PlatformPreview to support contentTypeOptions, meta, and platformData props - Move content type and board selectors into platform-specific preview components Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
112 lines
4.1 KiB
PHP
112 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Enums\SocialAccount\Platform as SocialPlatform;
|
|
use App\Events\PostPlatformStatusUpdated;
|
|
use App\Exceptions\TokenExpiredException;
|
|
use App\Models\PostPlatform;
|
|
use App\Services\Social\FacebookPublisher;
|
|
use App\Services\Social\InstagramPublisher;
|
|
use App\Services\Social\LinkedInPagePublisher;
|
|
use App\Services\Social\LinkedInPublisher;
|
|
use App\Services\Social\PinterestPublisher;
|
|
use App\Services\Social\ThreadsPublisher;
|
|
use App\Services\Social\TikTokPublisher;
|
|
use App\Services\Social\XPublisher;
|
|
use App\Services\Social\YouTubePublisher;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class PublishToSocialPlatform implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public int $tries = 3;
|
|
|
|
public int $backoff = 60;
|
|
|
|
public function __construct(public PostPlatform $postPlatform) {}
|
|
|
|
public function handle(): void
|
|
{
|
|
$this->postPlatform->markAsPublishing();
|
|
$this->broadcastStatus();
|
|
|
|
try {
|
|
$publisher = $this->getPublisher();
|
|
$result = $publisher->publish($this->postPlatform);
|
|
|
|
$this->postPlatform->markAsPublished($result['id'], $result['url'] ?? null);
|
|
} catch (TokenExpiredException $e) {
|
|
Log::error('Token expired while publishing to social platform', [
|
|
'post_platform_id' => $this->postPlatform->id,
|
|
'platform' => $this->postPlatform->platform->value,
|
|
'error' => $e->getMessage(),
|
|
'platform_error_code' => $e->platformErrorCode,
|
|
]);
|
|
|
|
$this->postPlatform->markAsFailed($e->getMessage());
|
|
$this->postPlatform->socialAccount->markAsDisconnected($e->getMessage());
|
|
} catch (\Exception $e) {
|
|
Log::error('Failed to publish to social platform', [
|
|
'post_platform_id' => $this->postPlatform->id,
|
|
'platform' => $this->postPlatform->platform->value,
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
|
|
$this->postPlatform->markAsFailed($e->getMessage());
|
|
}
|
|
|
|
// Always check and update post status after each platform finishes
|
|
$this->updatePostStatus();
|
|
|
|
// Broadcast final status
|
|
$this->broadcastStatus();
|
|
}
|
|
|
|
private function broadcastStatus(): void
|
|
{
|
|
PostPlatformStatusUpdated::dispatch($this->postPlatform->fresh());
|
|
}
|
|
|
|
private function getPublisher(): LinkedInPublisher|LinkedInPagePublisher|XPublisher|TikTokPublisher|YouTubePublisher|FacebookPublisher|InstagramPublisher|ThreadsPublisher|PinterestPublisher
|
|
{
|
|
return match ($this->postPlatform->platform) {
|
|
SocialPlatform::LinkedIn => app(LinkedInPublisher::class),
|
|
SocialPlatform::LinkedInPage => app(LinkedInPagePublisher::class),
|
|
SocialPlatform::X => app(XPublisher::class),
|
|
SocialPlatform::TikTok => app(TikTokPublisher::class),
|
|
SocialPlatform::YouTube => app(YouTubePublisher::class),
|
|
SocialPlatform::Facebook => app(FacebookPublisher::class),
|
|
SocialPlatform::Instagram => app(InstagramPublisher::class),
|
|
SocialPlatform::Threads => app(ThreadsPublisher::class),
|
|
SocialPlatform::Pinterest => app(PinterestPublisher::class),
|
|
};
|
|
}
|
|
|
|
private function updatePostStatus(): void
|
|
{
|
|
$post = $this->postPlatform->post->fresh();
|
|
$enabledPlatforms = $post->postPlatforms->where('enabled', true);
|
|
|
|
$total = $enabledPlatforms->count();
|
|
$publishedCount = $enabledPlatforms->where('status', 'published')->count();
|
|
$failedCount = $enabledPlatforms->where('status', 'failed')->count();
|
|
$finishedCount = $publishedCount + $failedCount;
|
|
|
|
// Only update post status when all platforms have finished
|
|
if ($finishedCount < $total) {
|
|
return;
|
|
}
|
|
|
|
if ($publishedCount === $total) {
|
|
$post->markAsPublished();
|
|
} elseif ($publishedCount > 0) {
|
|
$post->markAsPartiallyPublished();
|
|
} else {
|
|
$post->markAsFailed();
|
|
}
|
|
}
|
|
}
|