API
3 years ago
Builder
2 months ago
Control
3 weeks ago
Data
2 months ago
Endpoints
1 month ago
Exceptions
1 year ago
Integration
11 months ago
Mappers
9 months ago
Storage
2 months ago
Templates
2 years ago
Utils
8 months ago
Validation
2 months ago
Engine.php
1 month ago
Exceptions.php
1 month ago
Hooks.php
2 months ago
Integration.php
4 years ago
Registry.php
2 months ago
WordPress.php
2 months ago
index.php
3 years ago
Hooks.php
98 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Engine; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Automation\Engine\Data\Automation; |
| 9 | use MailPoet\Automation\Engine\Data\AutomationRunLog; |
| 10 | use MailPoet\Automation\Engine\Data\Step; |
| 11 | |
| 12 | class Hooks { |
| 13 | /** @var WordPress */ |
| 14 | private $wordPress; |
| 15 | |
| 16 | public function __construct( |
| 17 | WordPress $wordPress |
| 18 | ) { |
| 19 | $this->wordPress = $wordPress; |
| 20 | } |
| 21 | |
| 22 | public const INITIALIZE = 'mailpoet/automation/initialize'; |
| 23 | public const API_INITIALIZE = 'mailpoet/automation/api/initialize'; |
| 24 | public const TRIGGER = 'mailpoet/automation/trigger'; |
| 25 | public const AUTOMATION_STEP = 'mailpoet/automation/step'; |
| 26 | |
| 27 | public const EDITOR_BEFORE_LOAD = 'mailpoet/automation/editor/before_load'; |
| 28 | |
| 29 | public const AUTOMATION_BEFORE_SAVE = 'mailpoet/automation/before_save'; |
| 30 | public const AUTOMATION_STEP_BEFORE_SAVE = 'mailpoet/automation/step/before_save'; |
| 31 | public const AUTOMATION_AFTER_SAVE = 'mailpoet/automation/after_save'; |
| 32 | public const AUTOMATION_AFTER_CREATE = 'mailpoet/automation/after_create'; |
| 33 | public const AUTOMATION_AFTER_CREATE_FROM_TEMPLATE = 'mailpoet/automation/after_create_from_template'; |
| 34 | public const AUTOMATION_AFTER_UPDATE = 'mailpoet/automation/after_update'; |
| 35 | public const AUTOMATION_AFTER_DELETE = 'mailpoet/automation/after_delete'; |
| 36 | public const AUTOMATION_AFTER_DUPLICATE = 'mailpoet/automation/after_duplicate'; |
| 37 | |
| 38 | public const AUTOMATION_STEP_LOG_AFTER_RUN = 'mailpoet/automation/step/log_after_run'; |
| 39 | |
| 40 | public const AUTOMATION_RUN_CREATE = 'mailpoet/automation/run/create'; |
| 41 | |
| 42 | public function doAutomationBeforeSave(Automation $automation): void { |
| 43 | $this->wordPress->doAction(self::AUTOMATION_BEFORE_SAVE, $automation); |
| 44 | } |
| 45 | |
| 46 | public function doAutomationAfterSave(Automation $automation, ?Automation $previousAutomation = null): void { |
| 47 | $this->wordPress->doAction(self::AUTOMATION_AFTER_SAVE, $automation, $previousAutomation); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Fires after a plain automation create and then cascades to after-save. |
| 52 | */ |
| 53 | public function doAutomationAfterCreate(Automation $automation): void { |
| 54 | $this->wordPress->doAction(self::AUTOMATION_AFTER_CREATE, $automation); |
| 55 | $this->doAutomationAfterSave($automation); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Fires after creating from a template, then cascades to after-create and after-save. |
| 60 | */ |
| 61 | public function doAutomationAfterCreateFromTemplate(Automation $automation, string $templateSlug): void { |
| 62 | $this->wordPress->doAction(self::AUTOMATION_AFTER_CREATE_FROM_TEMPLATE, $automation, $templateSlug); |
| 63 | $this->doAutomationAfterCreate($automation); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Fires after updating an automation and then cascades to after-save with the previous persisted state. |
| 68 | */ |
| 69 | public function doAutomationAfterUpdate(Automation $automation, Automation $previousAutomation): void { |
| 70 | $this->wordPress->doAction(self::AUTOMATION_AFTER_UPDATE, $automation, $previousAutomation); |
| 71 | $this->doAutomationAfterSave($automation, $previousAutomation); |
| 72 | } |
| 73 | |
| 74 | public function doAutomationAfterDelete(Automation $automation): void { |
| 75 | $this->wordPress->doAction(self::AUTOMATION_AFTER_DELETE, $automation); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Fires after duplicating an automation, then cascades to after-create and after-save. |
| 80 | */ |
| 81 | public function doAutomationAfterDuplicate(Automation $automation, Automation $sourceAutomation): void { |
| 82 | $this->wordPress->doAction(self::AUTOMATION_AFTER_DUPLICATE, $automation, $sourceAutomation); |
| 83 | $this->doAutomationAfterCreate($automation); |
| 84 | } |
| 85 | |
| 86 | public function doAutomationStepBeforeSave(Step $step, Automation $automation): void { |
| 87 | $this->wordPress->doAction(self::AUTOMATION_STEP_BEFORE_SAVE, $step, $automation); |
| 88 | } |
| 89 | |
| 90 | public function doAutomationStepByKeyBeforeSave(Step $step, Automation $automation): void { |
| 91 | $this->wordPress->doAction(self::AUTOMATION_STEP_BEFORE_SAVE . '/key=' . $step->getKey(), $step, $automation); |
| 92 | } |
| 93 | |
| 94 | public function doAutomationStepAfterRun(AutomationRunLog $automationRunLog): void { |
| 95 | $this->wordPress->doAction(self::AUTOMATION_STEP_LOG_AFTER_RUN, $automationRunLog); |
| 96 | } |
| 97 | } |
| 98 |