Execute send email step progress when email is sent
[MAILPOET-4977]
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace MailPoet\Automation\Integrations\MailPoet\Actions;
|
namespace MailPoet\Automation\Integrations\MailPoet\Actions;
|
||||||
|
|
||||||
use MailPoet\AutomaticEmails\WooCommerce\Events\AbandonedCart;
|
use MailPoet\AutomaticEmails\WooCommerce\Events\AbandonedCart;
|
||||||
|
use MailPoet\Automation\Engine\Control\AutomationController;
|
||||||
use MailPoet\Automation\Engine\Control\StepRunController;
|
use MailPoet\Automation\Engine\Control\StepRunController;
|
||||||
use MailPoet\Automation\Engine\Data\Automation;
|
use MailPoet\Automation\Engine\Data\Automation;
|
||||||
use MailPoet\Automation\Engine\Data\Step;
|
use MailPoet\Automation\Engine\Data\Step;
|
||||||
@@ -49,6 +50,9 @@ class SendEmailAction implements Action {
|
|||||||
'woocommerce-subscriptions:trial-started',
|
'woocommerce-subscriptions:trial-started',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** @var AutomationController */
|
||||||
|
private $automationController;
|
||||||
|
|
||||||
/** @var SettingsController */
|
/** @var SettingsController */
|
||||||
private $settings;
|
private $settings;
|
||||||
|
|
||||||
@@ -71,6 +75,7 @@ class SendEmailAction implements Action {
|
|||||||
private $newsletterOptionFieldsRepository;
|
private $newsletterOptionFieldsRepository;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
AutomationController $automationController,
|
||||||
SettingsController $settings,
|
SettingsController $settings,
|
||||||
NewslettersRepository $newslettersRepository,
|
NewslettersRepository $newslettersRepository,
|
||||||
SubscriberSegmentRepository $subscriberSegmentRepository,
|
SubscriberSegmentRepository $subscriberSegmentRepository,
|
||||||
@@ -79,6 +84,7 @@ class SendEmailAction implements Action {
|
|||||||
NewsletterOptionsRepository $newsletterOptionsRepository,
|
NewsletterOptionsRepository $newsletterOptionsRepository,
|
||||||
NewsletterOptionFieldsRepository $newsletterOptionFieldsRepository
|
NewsletterOptionFieldsRepository $newsletterOptionFieldsRepository
|
||||||
) {
|
) {
|
||||||
|
$this->automationController = $automationController;
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->newslettersRepository = $newslettersRepository;
|
$this->newslettersRepository = $newslettersRepository;
|
||||||
$this->subscriberSegmentRepository = $subscriberSegmentRepository;
|
$this->subscriberSegmentRepository = $subscriberSegmentRepository;
|
||||||
@@ -179,6 +185,31 @@ class SendEmailAction implements Action {
|
|||||||
$controller->scheduleProgress(time() + MONTH_IN_SECONDS);
|
$controller->scheduleProgress(time() + MONTH_IN_SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param mixed $data */
|
||||||
|
public function handleEmailSent($data): void {
|
||||||
|
if (!is_array($data)) {
|
||||||
|
throw InvalidStateException::create()->withMessage(
|
||||||
|
sprintf('Invalid automation step data. Array expected, got: %s', gettype($data))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$runId = $data['run_id'] ?? null;
|
||||||
|
if (!is_int($runId)) {
|
||||||
|
throw InvalidStateException::create()->withMessage(
|
||||||
|
sprintf("Invalid automation step data. Expected 'run_id' to be an integer, got: %s", gettype($runId))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stepId = $data['step_id'] ?? null;
|
||||||
|
if (!is_string($stepId)) {
|
||||||
|
throw InvalidStateException::create()->withMessage(
|
||||||
|
sprintf("Invalid automation step data. Expected 'step_id' to be a string, got: %s", gettype($runId))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->automationController->enqueueProgress($runId, $stepId);
|
||||||
|
}
|
||||||
|
|
||||||
private function checkSendingStatus(NewsletterEntity $newsletter, SubscriberEntity $subscriber): void {
|
private function checkSendingStatus(NewsletterEntity $newsletter, SubscriberEntity $subscriber): void {
|
||||||
$scheduledTaskSubscriber = $this->automationEmailScheduler->getScheduledTaskSubscriber($newsletter, $subscriber);
|
$scheduledTaskSubscriber = $this->automationEmailScheduler->getScheduledTaskSubscriber($newsletter, $subscriber);
|
||||||
if (!$scheduledTaskSubscriber) {
|
if (!$scheduledTaskSubscriber) {
|
||||||
|
@@ -4,6 +4,7 @@ namespace MailPoet\Automation\Integrations\MailPoet;
|
|||||||
|
|
||||||
use MailPoet\Automation\Engine\Integration;
|
use MailPoet\Automation\Engine\Integration;
|
||||||
use MailPoet\Automation\Engine\Registry;
|
use MailPoet\Automation\Engine\Registry;
|
||||||
|
use MailPoet\Automation\Engine\WordPress;
|
||||||
use MailPoet\Automation\Integrations\MailPoet\Actions\SendEmailAction;
|
use MailPoet\Automation\Integrations\MailPoet\Actions\SendEmailAction;
|
||||||
use MailPoet\Automation\Integrations\MailPoet\Analytics\Analytics;
|
use MailPoet\Automation\Integrations\MailPoet\Analytics\Analytics;
|
||||||
use MailPoet\Automation\Integrations\MailPoet\Hooks\AutomationEditorLoadingHooks;
|
use MailPoet\Automation\Integrations\MailPoet\Hooks\AutomationEditorLoadingHooks;
|
||||||
@@ -65,6 +66,9 @@ class MailPoetIntegration implements Integration {
|
|||||||
/** @var Analytics */
|
/** @var Analytics */
|
||||||
private $registerAnalytics;
|
private $registerAnalytics;
|
||||||
|
|
||||||
|
/** @var WordPress */
|
||||||
|
private $wordPress;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ContextFactory $contextFactory,
|
ContextFactory $contextFactory,
|
||||||
SegmentSubject $segmentSubject,
|
SegmentSubject $segmentSubject,
|
||||||
@@ -80,7 +84,8 @@ class MailPoetIntegration implements Integration {
|
|||||||
AutomationEditorLoadingHooks $automationEditorLoadingHooks,
|
AutomationEditorLoadingHooks $automationEditorLoadingHooks,
|
||||||
CreateAutomationRunHook $createAutomationRunHook,
|
CreateAutomationRunHook $createAutomationRunHook,
|
||||||
TemplatesFactory $templatesFactory,
|
TemplatesFactory $templatesFactory,
|
||||||
Analytics $registerAnalytics
|
Analytics $registerAnalytics,
|
||||||
|
WordPress $wordPress
|
||||||
) {
|
) {
|
||||||
$this->contextFactory = $contextFactory;
|
$this->contextFactory = $contextFactory;
|
||||||
$this->segmentSubject = $segmentSubject;
|
$this->segmentSubject = $segmentSubject;
|
||||||
@@ -97,6 +102,7 @@ class MailPoetIntegration implements Integration {
|
|||||||
$this->createAutomationRunHook = $createAutomationRunHook;
|
$this->createAutomationRunHook = $createAutomationRunHook;
|
||||||
$this->templatesFactory = $templatesFactory;
|
$this->templatesFactory = $templatesFactory;
|
||||||
$this->registerAnalytics = $registerAnalytics;
|
$this->registerAnalytics = $registerAnalytics;
|
||||||
|
$this->wordPress = $wordPress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register(Registry $registry): void {
|
public function register(Registry $registry): void {
|
||||||
@@ -125,6 +131,9 @@ class MailPoetIntegration implements Integration {
|
|||||||
$this->sendEmailAction->getKey()
|
$this->sendEmailAction->getKey()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// execute send email step progress when email is sent
|
||||||
|
$this->wordPress->addAction('mailpoet_automation_email_sent', [$this->sendEmailAction, 'handleEmailSent']);
|
||||||
|
|
||||||
$this->automationEditorLoadingHooks->init();
|
$this->automationEditorLoadingHooks->init();
|
||||||
$this->createAutomationRunHook->init();
|
$this->createAutomationRunHook->init();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user