diff --git a/mailpoet/lib/Automation/Engine/Workflows/Step.php b/mailpoet/lib/Automation/Engine/Workflows/Step.php index 0a375001a4..483570a3f7 100644 --- a/mailpoet/lib/Automation/Engine/Workflows/Step.php +++ b/mailpoet/lib/Automation/Engine/Workflows/Step.php @@ -2,8 +2,12 @@ namespace MailPoet\Automation\Engine\Workflows; +use MailPoet\Validator\Schema\ObjectSchema; + interface Step { public function getKey(): string; public function getName(): string; + + public function getArgsSchema(): ObjectSchema; } diff --git a/mailpoet/lib/Automation/Integrations/Core/Actions/DelayAction.php b/mailpoet/lib/Automation/Integrations/Core/Actions/DelayAction.php index 6fee9c8af9..625951dae2 100644 --- a/mailpoet/lib/Automation/Integrations/Core/Actions/DelayAction.php +++ b/mailpoet/lib/Automation/Integrations/Core/Actions/DelayAction.php @@ -8,6 +8,8 @@ use MailPoet\Automation\Engine\Data\Workflow; use MailPoet\Automation\Engine\Data\WorkflowRun; use MailPoet\Automation\Engine\Hooks; use MailPoet\Automation\Engine\Workflows\Action; +use MailPoet\Validator\Builder; +use MailPoet\Validator\Schema\ObjectSchema; class DelayAction implements Action { /** @var ActionScheduler */ @@ -27,6 +29,13 @@ class DelayAction implements Action { return __('Delay', 'mailpoet'); } + public function getArgsSchema(): ObjectSchema { + return Builder::object([ + 'delay' => Builder::integer()->minimum(1), + 'delay_type' => Builder::string()->default('HOURS'), + ]); + } + public function run(Workflow $workflow, WorkflowRun $workflowRun, Step $step): void { $this->actionScheduler->schedule(time() + $this->calculateSeconds($step), Hooks::WORKFLOW_STEP, [ [ diff --git a/mailpoet/lib/Automation/Integrations/MailPoet/Actions/SendEmailAction.php b/mailpoet/lib/Automation/Integrations/MailPoet/Actions/SendEmailAction.php index 98ab31cee4..b9393aa943 100644 --- a/mailpoet/lib/Automation/Integrations/MailPoet/Actions/SendEmailAction.php +++ b/mailpoet/lib/Automation/Integrations/MailPoet/Actions/SendEmailAction.php @@ -15,10 +15,16 @@ use MailPoet\InvalidStateException; use MailPoet\Newsletter\NewslettersRepository; use MailPoet\Newsletter\Scheduler\AutomationEmailScheduler; use MailPoet\Newsletter\Sending\ScheduledTasksRepository; +use MailPoet\Settings\SettingsController; use MailPoet\Subscribers\SubscriberSegmentRepository; +use MailPoet\Validator\Builder; +use MailPoet\Validator\Schema\ObjectSchema; use Throwable; class SendEmailAction implements Action { + /** @var SettingsController */ + private $settings; + /** @var NewslettersRepository */ private $newslettersRepository; @@ -32,11 +38,13 @@ class SendEmailAction implements Action { private $automationEmailScheduler; public function __construct( + SettingsController $settings, NewslettersRepository $newslettersRepository, ScheduledTasksRepository $scheduledTasksRepository, SubscriberSegmentRepository $subscriberSegmentRepository, AutomationEmailScheduler $automationEmailScheduler ) { + $this->settings = $settings; $this->newslettersRepository = $newslettersRepository; $this->scheduledTasksRepository = $scheduledTasksRepository; $this->subscriberSegmentRepository = $subscriberSegmentRepository; @@ -51,6 +59,15 @@ class SendEmailAction implements Action { return __('Send email', 'mailpoet'); } + public function getArgsSchema(): ObjectSchema { + return Builder::object([ + 'subject' => Builder::string()->default(__('Subject', 'mailpoet')), + 'preheader' => Builder::string(), + 'from_name' => Builder::string()->default($this->settings->get('sender.name')), + 'email' => Builder::string()->default($this->settings->get('sender.address')), + ]); + } + public function isValid(array $subjects, Step $step, Workflow $workflow): bool { try { $this->getEmailForStep($step); diff --git a/mailpoet/lib/Automation/Integrations/MailPoet/Triggers/SegmentSubscribedTrigger.php b/mailpoet/lib/Automation/Integrations/MailPoet/Triggers/SegmentSubscribedTrigger.php index efce304620..8d2564f9c6 100644 --- a/mailpoet/lib/Automation/Integrations/MailPoet/Triggers/SegmentSubscribedTrigger.php +++ b/mailpoet/lib/Automation/Integrations/MailPoet/Triggers/SegmentSubscribedTrigger.php @@ -8,6 +8,8 @@ use MailPoet\Automation\Integrations\MailPoet\Subjects\SegmentSubject; use MailPoet\Automation\Integrations\MailPoet\Subjects\SubscriberSubject; use MailPoet\Entities\SubscriberSegmentEntity; use MailPoet\InvalidStateException; +use MailPoet\Validator\Builder; +use MailPoet\Validator\Schema\ObjectSchema; use MailPoet\WP\Functions as WPFunctions; class SegmentSubscribedTrigger implements Trigger { @@ -28,6 +30,10 @@ class SegmentSubscribedTrigger implements Trigger { return __('Subscribed to segment'); } + public function getArgsSchema(): ObjectSchema { + return Builder::object(); + } + public function registerHooks(): void { $this->wp->addAction('mailpoet_segment_subscribed', [$this, 'handleSubscription'], 10, 2); }