Migrate existing endpoints to the new structure
[MAILPOET-4207]
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Automation\Engine\API\Endpoints;
|
||||
namespace MailPoet\Automation\Engine\Endpoints\System;
|
||||
|
||||
use MailPoet\Automation\Engine\API\Endpoint;
|
||||
use MailPoet\Automation\Engine\API\Request;
|
||||
@@ -9,7 +9,7 @@ use MailPoet\Automation\Engine\Migrations\Migrator;
|
||||
use MailPoet\Features\FeatureFlagsController;
|
||||
use MailPoet\Features\FeaturesController;
|
||||
|
||||
class SystemDatabaseEndpoint extends Endpoint {
|
||||
class DatabaseDeleteEndpoint extends Endpoint {
|
||||
/** @var FeatureFlagsController */
|
||||
private $featureFlagsController;
|
||||
|
||||
@@ -24,13 +24,7 @@ class SystemDatabaseEndpoint extends Endpoint {
|
||||
$this->featureFlagsController = $featureFlagsController;
|
||||
}
|
||||
|
||||
public function post(Request $request): Response {
|
||||
$this->migrator->deleteSchema();
|
||||
$this->migrator->createSchema();
|
||||
return new Response(null);
|
||||
}
|
||||
|
||||
public function delete(Request $request): Response {
|
||||
public function handle(Request $request): Response {
|
||||
$this->migrator->deleteSchema();
|
||||
$this->featureFlagsController->set(FeaturesController::AUTOMATION, false);
|
||||
return new Response(null);
|
@@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Automation\Engine\Endpoints\System;
|
||||
|
||||
use MailPoet\Automation\Engine\API\Endpoint;
|
||||
use MailPoet\Automation\Engine\API\Request;
|
||||
use MailPoet\Automation\Engine\API\Response;
|
||||
use MailPoet\Automation\Engine\Migrations\Migrator;
|
||||
|
||||
class DatabasePostEndpoint extends Endpoint {
|
||||
/** @var Migrator */
|
||||
private $migrator;
|
||||
|
||||
public function __construct(
|
||||
Migrator $migrator
|
||||
) {
|
||||
$this->migrator = $migrator;
|
||||
}
|
||||
|
||||
public function handle(Request $request): Response {
|
||||
$this->migrator->deleteSchema();
|
||||
$this->migrator->createSchema();
|
||||
return new Response(null);
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Automation\Engine\Endpoints\Workflows;
|
||||
|
||||
use MailPoet\Automation\Engine\API\Endpoint;
|
||||
use MailPoet\Automation\Engine\API\Request;
|
||||
use MailPoet\Automation\Engine\API\Response;
|
||||
|
||||
class WorkflowsGetEndpoint extends Endpoint {
|
||||
public function handle(Request $request): Response {
|
||||
return new Response(['message' => 'Hello world.']);
|
||||
}
|
||||
}
|
@@ -1,13 +1,13 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Automation\Engine\API\Endpoints;
|
||||
namespace MailPoet\Automation\Engine\Endpoints\Workflows;
|
||||
|
||||
use MailPoet\Automation\Engine\API\Endpoint;
|
||||
use MailPoet\Automation\Engine\API\Request;
|
||||
use MailPoet\Automation\Engine\API\Response;
|
||||
use MailPoet\Automation\Engine\Builder\CreateWorkflowController;
|
||||
|
||||
class WorkflowsEndpoint extends Endpoint {
|
||||
class WorkflowsPostEndpoint extends Endpoint {
|
||||
/** @var CreateWorkflowController */
|
||||
private $createController;
|
||||
|
||||
@@ -17,14 +17,10 @@ class WorkflowsEndpoint extends Endpoint {
|
||||
$this->createController = $createController;
|
||||
}
|
||||
|
||||
public function get(Request $request): Response {
|
||||
return new Response(['message' => 'Hello world.']);
|
||||
}
|
||||
|
||||
public function post(Request $request): Response {
|
||||
public function handle(Request $request): Response {
|
||||
// TODO: validation
|
||||
$body = $request->getBody();
|
||||
$this->createController->createWorkflow($body);
|
||||
$data = $request->getBody();
|
||||
$this->createController->createWorkflow($data);
|
||||
return new Response();
|
||||
}
|
||||
}
|
@@ -5,6 +5,10 @@ namespace MailPoet\Automation\Engine;
|
||||
use MailPoet\Automation\Engine\API\API;
|
||||
use MailPoet\Automation\Engine\Control\StepRunner;
|
||||
use MailPoet\Automation\Engine\Control\TriggerHandler;
|
||||
use MailPoet\Automation\Engine\Endpoints\System\DatabaseDeleteEndpoint;
|
||||
use MailPoet\Automation\Engine\Endpoints\System\DatabasePostEndpoint;
|
||||
use MailPoet\Automation\Engine\Endpoints\Workflows\WorkflowsGetEndpoint;
|
||||
use MailPoet\Automation\Engine\Endpoints\Workflows\WorkflowsPostEndpoint;
|
||||
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
|
||||
use MailPoet\Automation\Integrations\Core\CoreIntegration;
|
||||
|
||||
@@ -52,6 +56,8 @@ class Engine {
|
||||
// register Action Scheduler (when behind feature flag, do it only on initialization)
|
||||
require_once __DIR__ . '/../../../vendor/woocommerce/action-scheduler/action-scheduler.php';
|
||||
|
||||
$this->registerApiRoutes();
|
||||
|
||||
$this->api->initialize();
|
||||
$this->stepRunner->initialize();
|
||||
$this->triggerHandler->initialize();
|
||||
@@ -61,6 +67,15 @@ class Engine {
|
||||
$this->registerActiveTriggerHooks();
|
||||
}
|
||||
|
||||
private function registerApiRoutes(): void {
|
||||
$this->wordPress->addAction(Hooks::API_INITIALIZE, function (API $api) {
|
||||
$api->registerGetRoute('workflows', WorkflowsGetEndpoint::class);
|
||||
$api->registerPostRoute('workflows', WorkflowsPostEndpoint::class);
|
||||
$api->registerPostRoute('system/database', DatabasePostEndpoint::class);
|
||||
$api->registerDeleteRoute('system/database', DatabaseDeleteEndpoint::class);
|
||||
});
|
||||
}
|
||||
|
||||
private function registerActiveTriggerHooks(): void {
|
||||
$triggerKeys = $this->workflowStorage->getActiveTriggerKeys();
|
||||
foreach ($triggerKeys as $triggerKey) {
|
||||
|
@@ -108,8 +108,6 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
$container->autowire(\MailPoet\Automation\Engine\API\EndpointFactory::class)
|
||||
->setPublic(true)
|
||||
->setArgument('$container', new Reference(ContainerWrapper::class));
|
||||
$container->autowire(\MailPoet\Automation\Engine\API\Endpoints\SystemDatabaseEndpoint::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\API\Endpoints\WorkflowsEndpoint::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Builder\CreateWorkflowController::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Control\ActionScheduler::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Control\StepRunner::class)->setPublic(true);
|
||||
@@ -121,6 +119,11 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
$container->autowire(\MailPoet\Automation\Engine\Storage\WorkflowRunStorage::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Storage\WorkflowStorage::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\WordPress::class)->setPublic(true);
|
||||
// Automation - API endpoints
|
||||
$container->autowire(\MailPoet\Automation\Engine\Endpoints\Workflows\WorkflowsGetEndpoint::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Endpoints\Workflows\WorkflowsPostEndpoint::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Endpoints\System\DatabasePostEndpoint::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Endpoints\System\DatabaseDeleteEndpoint::class)->setPublic(true);
|
||||
// Automation - core integration
|
||||
$container->autowire(\MailPoet\Automation\Integrations\Core\Actions\WaitAction::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Integrations\Core\CoreIntegration::class)->setPublic(true);
|
||||
|
Reference in New Issue
Block a user