CreateAutomationFromTemplateController.php
2 months ago
DeleteAutomationController.php
2 months ago
DuplicateAutomationController.php
2 months ago
UpdateAutomationController.php
2 months ago
UpdateStepsController.php
11 months ago
index.php
3 years ago
DeleteAutomationController.php
43 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Engine\Builder; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Automation\Engine\Data\Automation; |
| 9 | use MailPoet\Automation\Engine\Exceptions; |
| 10 | use MailPoet\Automation\Engine\Hooks; |
| 11 | use MailPoet\Automation\Engine\Storage\AutomationStorage; |
| 12 | |
| 13 | class DeleteAutomationController { |
| 14 | /** @var AutomationStorage */ |
| 15 | private $automationStorage; |
| 16 | |
| 17 | /** @var Hooks */ |
| 18 | private $hooks; |
| 19 | |
| 20 | public function __construct( |
| 21 | AutomationStorage $automationStorage, |
| 22 | Hooks $hooks |
| 23 | ) { |
| 24 | $this->automationStorage = $automationStorage; |
| 25 | $this->hooks = $hooks; |
| 26 | } |
| 27 | |
| 28 | public function deleteAutomation(int $id): Automation { |
| 29 | $automation = $this->automationStorage->getAutomation($id); |
| 30 | if (!$automation) { |
| 31 | throw Exceptions::automationNotFound($id); |
| 32 | } |
| 33 | |
| 34 | if ($automation->getStatus() !== Automation::STATUS_TRASH) { |
| 35 | throw Exceptions::automationNotTrashed($id); |
| 36 | } |
| 37 | |
| 38 | $this->automationStorage->deleteAutomation($automation); |
| 39 | $this->hooks->doAutomationAfterDelete($automation); |
| 40 | return $automation; |
| 41 | } |
| 42 | } |
| 43 |