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
AutomationsPutEndpoint.php
50 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\UpdateAutomationController; |
| 12 | use MailPoet\Automation\Engine\Mappers\AutomationMapper; |
| 13 | use MailPoet\Automation\Engine\Validation\AutomationSchema; |
| 14 | use MailPoet\Validator\Builder; |
| 15 | |
| 16 | class AutomationsPutEndpoint extends Endpoint { |
| 17 | /** @var UpdateAutomationController */ |
| 18 | private $updateController; |
| 19 | |
| 20 | /** @var AutomationMapper */ |
| 21 | private $automationMapper; |
| 22 | |
| 23 | public function __construct( |
| 24 | UpdateAutomationController $updateController, |
| 25 | AutomationMapper $automationMapper |
| 26 | ) { |
| 27 | $this->updateController = $updateController; |
| 28 | $this->automationMapper = $automationMapper; |
| 29 | } |
| 30 | |
| 31 | public function handle(Request $request): Response { |
| 32 | $data = $request->getParams(); |
| 33 | /** @var int $automationId */ |
| 34 | $automationId = $request->getParam('id'); |
| 35 | $automation = $this->updateController->updateAutomation(intval($automationId), $data); |
| 36 | return new Response($this->automationMapper->buildAutomation($automation)); |
| 37 | } |
| 38 | |
| 39 | public static function getRequestSchema(): array { |
| 40 | return [ |
| 41 | 'id' => Builder::integer()->required(), |
| 42 | 'name' => Builder::string()->minLength(1), |
| 43 | 'status' => Builder::string(), |
| 44 | 'steps' => AutomationSchema::getStepsSchema(), |
| 45 | 'meta' => Builder::object(), |
| 46 | 'cancel_running_runs' => Builder::boolean(), |
| 47 | ]; |
| 48 | } |
| 49 | } |
| 50 |