Add a Publisher abstraction and queued job to publish from the UI

Introduce Publisher/PublisherManager (WordPress + Reddit implementations)
so publishing logic is shared between the CLI, the queue, and future
network integrations. Add a "Publish" button on the Posts page that
dispatches PublishPostJob instead of blocking the request — Reddit's
publisher shells out to the existing Playwright sidecar and can take
tens of seconds, so it can't run synchronously in a web request.

Adds a `target` field (e.g. subreddit) and `publishing` status to Post,
plus a `publish_error` field so failures surface in the UI. Refactors
posts:publish to delegate to WordPressPublisher without changing its
CLI output contract (existing tests pass unchanged).

Also fixes two bugs found along the way: UpdatePostRequest was silently
dropping `published_url` from PATCH requests (never in its validation
rules, despite AI_API.md documenting it), and three Livewire index-page
tests were broken by the earlier auth change (never re-run after adding
the `auth` middleware) since they hit routes via HTTP without a logged-in
user.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
m105
2026-07-21 14:04:45 +03:00
co-authored by Claude Sonnet 5
parent 0cf72b44b7
commit 9278d2e8a0
26 changed files with 735 additions and 76 deletions
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Jobs;
use App\Models\Post;
use App\Support\Publishing\PublisherManager;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class PublishPostJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $timeout = 150;
public function __construct(public readonly int $postId) {}
public function handle(PublisherManager $publishers): void
{
$post = Post::with(['site', 'socialAccount'])->find($this->postId);
if (! $post) {
return;
}
$publisher = $publishers->resolve($post);
if (! $publisher) {
$post->update(['status' => 'draft', 'publish_error' => "No publisher available for post type '{$post->type}'."]);
return;
}
$result = $publisher->publish($post);
if ($result->success) {
$post->update(['status' => 'published', 'published_url' => $result->url, 'publish_error' => null]);
return;
}
$post->update([
'status' => $result->attempted ? 'failed' : 'draft',
'publish_error' => $result->error,
]);
Log::error('post publish failed', ['post_id' => $post->id, 'error' => $result->error]);
}
}