- Added new automation-related routes and controllers for managing automations. - Introduced automation nodes in the UI with distinct styles and interactions. - Updated sidebar to include navigation for automations. - Enhanced post creation logic to support automation metadata. - Refactored content type and platform enums into types for better type safety. - Added localization for automation-related terms in English, Spanish, and Portuguese. - Improved error handling in various components to accommodate new features.
59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Automation\Node;
|
|
|
|
use App\DataTransferObjects\Automation\NodeRunResult;
|
|
use App\Enums\Automation\Publish\Mode;
|
|
use App\Enums\Post\Status as PostStatus;
|
|
use App\Jobs\PublishPost;
|
|
use App\Models\AutomationRun;
|
|
use App\Models\Post;
|
|
|
|
class RunPublishNode
|
|
{
|
|
public function __invoke(AutomationRun $run, array $config): NodeRunResult
|
|
{
|
|
$mode = Mode::from($config['mode'] ?? 'now');
|
|
|
|
// Dry runs never have a generated Post (RunGenerateNode skipped
|
|
// persistence). Mirror the call site without touching the DB or
|
|
// queueing PublishPost.
|
|
if ($run->is_dry_run) {
|
|
return NodeRunResult::completed(output: [
|
|
'publish' => ['mode' => $mode->value, 'post_id' => null, 'dry_run' => true],
|
|
]);
|
|
}
|
|
|
|
$post = $run->generatedPost;
|
|
|
|
if ($post === null) {
|
|
return NodeRunResult::failed(__('automations.errors.no_generated_post'));
|
|
}
|
|
|
|
match ($mode) {
|
|
Mode::Now => $this->publishNow($post),
|
|
Mode::Scheduled => $this->schedule($post, (int) ($config['scheduled_offset'] ?? 60)),
|
|
Mode::Draft => null,
|
|
};
|
|
|
|
return NodeRunResult::completed(output: [
|
|
'publish' => ['mode' => $mode->value, 'post_id' => $post->id],
|
|
]);
|
|
}
|
|
|
|
private function publishNow(Post $post): void
|
|
{
|
|
$post->update(['status' => PostStatus::Publishing]);
|
|
PublishPost::dispatch($post);
|
|
}
|
|
|
|
private function schedule(Post $post, int $offsetMinutes): void
|
|
{
|
|
$post->update([
|
|
'status' => PostStatus::Scheduled,
|
|
'scheduled_at' => now()->addMinutes($offsetMinutes),
|
|
]);
|
|
}
|
|
}
|