- Create post_social_account pivot table for many-to-many relationship - Add migration to migrate existing social_account_id to pivot table - Remove social_account_id column from posts table - Update Post model with socialAccounts() BelongsToMany relationship - Update Posts Livewire component to use array of selectedAccountIds - Update Posts view with checkboxes for selecting multiple accounts - Update PublishPostJob to iterate through all social accounts of matching type - Update Publisher interface to accept optional SocialAccount parameter - Update all Publishers (WordPress, Reddit, Twitter, LinkedIn) to support cross-posting - Display multiple social accounts as badges in posts table Now a single post can be published to multiple social accounts of the same type. For example: a Twitter post can be published to multiple Twitter accounts. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Support\Publishing;
|
|
|
|
use App\Models\Post;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Process;
|
|
|
|
class TwitterPublisher implements Publisher
|
|
{
|
|
public function supports(Post $post): bool
|
|
{
|
|
return $post->type === 'twitter';
|
|
}
|
|
|
|
public function publish(Post $post, ?SocialAccount $socialAccount = null): PublishResult
|
|
{
|
|
if (! $post->body) {
|
|
return PublishResult::rejected("Post {$post->id} has no body, required for a Twitter post.");
|
|
}
|
|
|
|
// Use the passed social account, or fall back to the first linked one
|
|
$account = $socialAccount ?: $post->socialAccounts->first();
|
|
|
|
if (! $account || $account->network !== 'twitter') {
|
|
return PublishResult::rejected("Post {$post->id} has no linked Twitter social account.");
|
|
}
|
|
|
|
// Twitter uses username (which may be email or username) and password
|
|
$result = Process::timeout(120)->run([
|
|
base_path('sidecars/twitter-post/run.sh'),
|
|
"--username={$account->username}",
|
|
"--password={$account->password}",
|
|
"--tweet=" . escapeshellarg($post->body),
|
|
]);
|
|
|
|
$data = json_decode(trim($result->output()), true);
|
|
|
|
if (! is_array($data) || ! array_key_exists('success', $data)) {
|
|
Log::error('twitter sidecar returned unparseable output', [
|
|
'post_id' => $post->id,
|
|
'output' => $result->output(),
|
|
'stderr' => $result->errorOutput(),
|
|
]);
|
|
|
|
return PublishResult::failed('Twitter sidecar returned unparseable output — check logs.');
|
|
}
|
|
|
|
if (! $data['success']) {
|
|
return PublishResult::failed($data['error'] ?? 'unknown Twitter sidecar failure');
|
|
}
|
|
|
|
return PublishResult::success($data['url']);
|
|
}
|
|
}
|