Foundational layer for the YouTube Content Creation System project, built as a fully independent domain per the earlier decision (task #47) — no foreign keys into the existing projects/tasks/ideas tables. Schema: video_projects, workflow_steps, assets, ai_providers, workflow_templates (named to avoid colliding with the existing Post-templates `templates` table). WorkflowEngine (app/Support/VideoWorkflow/) drives a project's step sequence: start/startFromTemplate, currentStep, completeStep (with optional approval gating), approveStep/rejectStep, failStep/retryStep, skipStep. It only manages state transitions — actual step execution (AI calls, rendering, etc.) is out of scope here (tasks #33+). Also fixes four Publisher classes (WordPress/Reddit/Twitter/LinkedIn) that were missing a `use App\Models\SocialAccount;` import after an earlier interface change, which broke the entire test suite at bootstrap; and PostFactory, which still set the now-removed `social_account_id` column instead of the SocialAccount pivot. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Support\Publishing;
|
|
|
|
use App\Models\Post;
|
|
use App\Models\SocialAccount;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Process;
|
|
|
|
class RedditPublisher implements Publisher
|
|
{
|
|
public function supports(Post $post): bool
|
|
{
|
|
return $post->type === 'reddit';
|
|
}
|
|
|
|
public function publish(Post $post, ?SocialAccount $socialAccount = null): PublishResult
|
|
{
|
|
if (! $post->title) {
|
|
return PublishResult::rejected("Post {$post->id} has no title, required for a Reddit post.");
|
|
}
|
|
|
|
if (! $post->target) {
|
|
return PublishResult::rejected("Post {$post->id} has no target subreddit set.");
|
|
}
|
|
|
|
// Use the passed social account, or fall back to the first linked one
|
|
$account = $socialAccount ?: $post->socialAccounts->first();
|
|
|
|
if (! $account || $account->network !== 'reddit') {
|
|
return PublishResult::rejected("Post {$post->id} has no linked Reddit social account.");
|
|
}
|
|
|
|
$result = Process::timeout(120)->run([
|
|
base_path('sidecars/reddit-post/run.sh'),
|
|
"--username={$account->username}",
|
|
"--password={$account->password}",
|
|
"--subreddit={$post->target}",
|
|
"--title={$post->title}",
|
|
"--body={$post->body}",
|
|
]);
|
|
|
|
$data = json_decode(trim($result->output()), true);
|
|
|
|
if (! is_array($data) || ! array_key_exists('success', $data)) {
|
|
Log::error('reddit sidecar returned unparseable output', [
|
|
'post_id' => $post->id,
|
|
'output' => $result->output(),
|
|
'stderr' => $result->errorOutput(),
|
|
]);
|
|
|
|
return PublishResult::failed('Reddit sidecar returned unparseable output — check logs.');
|
|
}
|
|
|
|
if (! $data['success']) {
|
|
return PublishResult::failed($data['error'] ?? 'unknown Reddit sidecar failure');
|
|
}
|
|
|
|
return PublishResult::success($data['url']);
|
|
}
|
|
}
|