Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

1.1 KB
Raw Blame
<?php

declare(strict_types=1);

namespace App\Jobs\Analytics;

use App\Actions\Analytics\QueuePublicationMetricsForPage;
use App\Actions\Analytics\SyncTryPostPublication as SyncTryPostPublicationAction;
use App\Dto\Analytics\TryPostPublicationIdentity;
use App\Models\Post;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;

class SyncTryPostPublication implements ShouldQueue
{
    use Queueable;

    public function __construct(
        public TryPostPublicationIdentity $identity,
        public string $postId,
    ) {
        $this->onQueue('analytics');
    }

    public function handle(SyncTryPostPublicationAction $sync, QueuePublicationMetricsForPage $metrics): void
    {
        $post = Post::query()
            ->publicationPublished()
            ->find($this->postId);

        if (! $post || ! filled($post->platform_post_id)) {
            return;
        }

        $publication = $sync->fromIdentity($this->identity, $post);

        if ($post->workspace->account->hasAppAccess()) {
            $metrics->queue($publication);
        }
    }
}