From 5c4b7d05db9f2c8d712b864ca230393677d26682 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 25 Apr 2023 01:51:28 +0000 Subject: [PATCH] bug fixes and subscription improvements --- Controller/ApiController.php | 31 +++++++++++++++++++++++++++---- Controller/CliController.php | 12 ++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 44d2f9d..9d65f52 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -505,6 +505,20 @@ final class ApiController extends Controller $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Template', 'Template successfully created', $template); } + /** + * Install a new workflow template. + * + * Some actions have a install function, which must be called when first installing/registering a new action in a template. + * An example could be the cron job for a timed trigger, which must be installed when the template is installed. + * + * @param WorkflowTemplate $template Workflow template + * @param array $actions Actions + * + * @return void + * + * @since 1.0.0 + * @todo: also implement the delete and update functions + */ private function installWorkflowModel(WorkflowTemplate $template, array $actions) : void { $schema = $template->schema; @@ -519,9 +533,18 @@ final class ApiController extends Controller } } + /** + * Installs a timed trigger for a workflow template. + * + * @param WorkflowTemplate $template Workflow template + * + * @return void + * + * @since 1.0.0 + */ public function installTimedTrigger(WorkflowTemplate $template) : void { - $id = 'Workflow-' . $template->getId(); + $id = 'Workflow-' . $template->getId(); $scheduler = SchedulerFactory::create(); if (!empty($scheduler->getAllByName($id))) { @@ -531,9 +554,9 @@ final class ApiController extends Controller $job = TaskFactory::create($id); $job->interval = $template->schema['settings']['interval'] ?? ''; - $job->command = 'php ' - . FileUtils::absolute(__DIR__ . '/../../../Cli/cli.php') - . ' /workflow/instance -id ' + $job->command = 'php ' + . FileUtils::absolute(__DIR__ . '/../../../Cli/cli.php') + . ' /workflow/instance -id ' . $template->getId() . ' -trigger 1005500005'; diff --git a/Controller/CliController.php b/Controller/CliController.php index 5943d9c..69a63a5 100755 --- a/Controller/CliController.php +++ b/Controller/CliController.php @@ -164,7 +164,7 @@ final class CliController extends Controller * @param RequestAbstract $request Request * * @return WorkflowInstanceAbstract - * + * * @todo: How to handle workflow instances which are not saved in the database and are continued? * * @since 1.0.0 @@ -178,7 +178,15 @@ final class CliController extends Controller $instance = new WorkflowInstance(); - $actions = \json_decode(\file_get_contents(__DIR__ . '/../Definitions/actions.json'), true); + $actionString = \file_get_contents(__DIR__ . '/../Definitions/actions.json'); + if ($actionString === false) { + return $instance; + } + + $actions = \json_decode($actionString, true); + if (!\is_array($actions)) { + return $instance; + } foreach ($template->schema as $e) { if ($e['id'] === $request->getDataString('trigger')) {