- 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.
36 lines
980 B
PHP
36 lines
980 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Automation\Trigger;
|
|
|
|
use App\Actions\Automation\TriggerItem\EnrollTriggerItem;
|
|
use App\Models\Automation;
|
|
use Cron\CronExpression;
|
|
|
|
class FireScheduleTrigger
|
|
{
|
|
public function __construct(private EnrollTriggerItem $enroll) {}
|
|
|
|
public function __invoke(Automation $automation): bool
|
|
{
|
|
$triggerNode = collect($automation->nodes ?? [])->firstWhere('type', 'trigger');
|
|
$cron = data_get($triggerNode, 'data.cron');
|
|
$timezone = data_get($triggerNode, 'data.schedule_timezone', config('app.timezone'));
|
|
|
|
if ($cron === null) {
|
|
return false;
|
|
}
|
|
|
|
$expression = new CronExpression($cron);
|
|
|
|
if (! $expression->isDue(now(), $timezone)) {
|
|
return false;
|
|
}
|
|
|
|
$key = now()->format('Y-m-d\TH:i');
|
|
$payload = ['fired_at' => now()->toIso8601String()];
|
|
|
|
return ($this->enroll)($automation, $key, $payload) !== null;
|
|
}
|
|
}
|