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