trypost/app/Actions/Automation/TriggerItem/EnrollTriggerItem.php
Paulo Castellano b23ab0166e feat(automations): implement automation features and UI enhancements
- 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.
2026-05-24 09:17:19 -03:00

35 lines
946 B
PHP

<?php
declare(strict_types=1);
namespace App\Actions\Automation\TriggerItem;
use App\Actions\Automation\Run\DispatchAutomationRun;
use App\Models\Automation;
use App\Models\AutomationRun;
use App\Models\AutomationTriggerItem;
class EnrollTriggerItem
{
public function __construct(private DispatchAutomationRun $dispatchRun) {}
public function __invoke(Automation $automation, string $itemKey, array $payload): ?AutomationRun
{
$existing = AutomationTriggerItem::where('automation_id', $automation->id)
->where('item_key', $itemKey)
->first();
if ($existing !== null) {
return null;
}
$item = AutomationTriggerItem::create([
'automation_id' => $automation->id,
'item_key' => $itemKey,
'payload' => $payload,
'first_seen_at' => now(),
]);
return ($this->dispatchRun)($automation, $item);
}
}