AutomationTemplateEmailPreviewEndpoint.php
1 month ago
AutomationTemplateGetEndpoint.php
1 year ago
AutomationTemplatesGetEndpoint.php
2 years ago
AutomationVersionsGetEndpoint.php
2 months ago
AutomationsCreateFromTemplateEndpoint.php
2 months ago
AutomationsDeleteEndpoint.php
2 years ago
AutomationsDuplicateEndpoint.php
2 years ago
AutomationsGetEndpoint.php
9 months ago
AutomationsPutEndpoint.php
2 months ago
index.php
3 years ago
AutomationsDuplicateEndpoint.php
44 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Engine\Endpoints\Automations; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\API\REST\Request; |
| 9 | use MailPoet\API\REST\Response; |
| 10 | use MailPoet\Automation\Engine\API\Endpoint; |
| 11 | use MailPoet\Automation\Engine\Builder\DuplicateAutomationController; |
| 12 | use MailPoet\Automation\Engine\Mappers\AutomationMapper; |
| 13 | use MailPoet\Validator\Builder; |
| 14 | |
| 15 | class AutomationsDuplicateEndpoint extends Endpoint { |
| 16 | /** @var AutomationMapper */ |
| 17 | private $automationMapper; |
| 18 | |
| 19 | /** @var DuplicateAutomationController */ |
| 20 | private $duplicateController; |
| 21 | |
| 22 | public function __construct( |
| 23 | DuplicateAutomationController $duplicateController, |
| 24 | AutomationMapper $automationMapper |
| 25 | ) { |
| 26 | $this->automationMapper = $automationMapper; |
| 27 | $this->duplicateController = $duplicateController; |
| 28 | } |
| 29 | |
| 30 | public function handle(Request $request): Response { |
| 31 | /** @var int $automationId */ |
| 32 | $automationId = $request->getParam('id'); |
| 33 | $automationId = intval($automationId); |
| 34 | $duplicate = $this->duplicateController->duplicateAutomation($automationId); |
| 35 | return new Response($this->automationMapper->buildAutomation($duplicate)); |
| 36 | } |
| 37 | |
| 38 | public static function getRequestSchema(): array { |
| 39 | return [ |
| 40 | 'id' => Builder::integer()->required(), |
| 41 | ]; |
| 42 | } |
| 43 | } |
| 44 |