- Pagination: drop the perPage override from ListAutomations and the
hardcoded page size from GetAutomationInvocations; both use
config('app.pagination.default'). Document the rule in CLAUDE.md.
- Imports: import DomainException / InvalidArgumentException / Throwable
instead of inline backslash references across the automation actions.
- i18n: move the hardcoded Fetch RSS and HTTP Request failure strings to
automations.errors.* in all three locales.
- Publish: require scheduled_offset when mode is scheduled (validation)
and drop the magic 60-minute default in the node. Fixes the required_if
rules to reference the concrete node index instead of a wildcard that
never resolved (also repairs the trigger cron rule).
- Condition handles: back the yes/no output handles with a shared
Condition\Handle enum (PHP) and ConditionHandle const (TS).
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(data_get($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) data_get($config, 'scheduled_offset')),
|
|
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),
|
|
]);
|
|
}
|
|
}
|