diff --git a/Admin/Install/Workflow.install.json b/Admin/Install/Workflow.install.json index 1df7ed0..436a7f8 100755 --- a/Admin/Install/Workflow.install.json +++ b/Admin/Install/Workflow.install.json @@ -369,7 +369,7 @@ "de": "Zeitgesteuerter Trigger (Job/Task)" }, "function_type": "Api", - "function": "apiRun", + "function": "", "module": "Workflow", "function_install": { "module": "Workflow", @@ -408,7 +408,7 @@ "de": "Konsolenbefehl" }, "function_type": "Api", - "function": "apiRun", + "function": "", "module": "Workflow", "inputs": [ "cmd", @@ -443,7 +443,7 @@ "de": "Workflow Script" }, "function_type": "Api", - "function": "apiRun", + "function": "", "module": "Workflow", "inputs": [ "{*}" diff --git a/Admin/Routes/Cli.php b/Admin/Routes/Cli.php index 675b3f3..9fd63c6 100755 --- a/Admin/Routes/Cli.php +++ b/Admin/Routes/Cli.php @@ -7,7 +7,7 @@ return [ '^.*/workflow/instance.*$' => [ [ 'dest' => '\Modules\Workflow\Controller\CliController:cliWorkflowInstanceCreate', - 'verb' => RouteVerb::PUT, + 'verb' => RouteVerb::ANY, ], ], ]; diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 92c8c17..04022cc 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -21,7 +21,6 @@ use Modules\Media\Models\PathSettings; use Modules\Workflow\Models\PermissionCategory; use Modules\Workflow\Models\WorkflowInstanceAbstract; use Modules\Workflow\Models\WorkflowInstanceAbstractMapper; -use Modules\Workflow\Models\WorkflowStatus; use Modules\Workflow\Models\WorkflowTemplate; use Modules\Workflow\Models\WorkflowTemplateMapper; use phpOMS\Account\PermissionType; @@ -497,7 +496,7 @@ final class ApiController extends Controller $job->interval = $settings['settings']['interval'] ?? ''; $job->command = 'php ' - . FileUtils::absolute(__DIR__ . '/../../../Cli/cli.php') + . FileUtils::absolute(__DIR__ . '/../../../cli.php') . ' /workflow/instance -id ' . $template->id . ' -trigger 1005500005'; diff --git a/Controller/CliController.php b/Controller/CliController.php index 7a0240d..42870cd 100755 --- a/Controller/CliController.php +++ b/Controller/CliController.php @@ -16,7 +16,7 @@ namespace Modules\Workflow\Controller; use Modules\Workflow\Models\WorkflowInstance; use Modules\Workflow\Models\WorkflowInstanceAbstract; -use Modules\Workflow\Models\WorkflowInstanceMapper; +use Modules\Workflow\Models\WorkflowInstanceAbstractMapper; use Modules\Workflow\Models\WorkflowStatus; use Modules\Workflow\Models\WorkflowTemplate; use Modules\Workflow\Models\WorkflowTemplateMapper; @@ -60,18 +60,14 @@ final class CliController extends Controller $triggerIsRegex = \stripos($data['@triggerGroup'], '/') === 0; $matched = false; - if ($triggerIsRegex) { - $matched = \preg_match($data['@triggerGroup'], $hook) === 1; - } else { - $matched = $data['@triggerGroup'] === $hook; - } - - if (!$matched && \stripos($hook, '/') === 0) { - $matched = \preg_match($hook, $data['@triggerGroup']) === 1; - } + $matched = $triggerIsRegex + ? \preg_match($data['@triggerGroup'], $hook) === 1 + : $data['@triggerGroup'] === $hook; if ($matched) { $this->runWorkflow($workflow, $hook, $data); + } elseif (\stripos($hook, '/') === 0) { + $matched = \preg_match($hook, $data['@triggerGroup']) === 1; } } } @@ -116,13 +112,13 @@ final class CliController extends Controller $response->header->status = RequestStatusCode::R_400; } - $instance = $this->createInstanceFromRequest($request, $response); - $this->createModel($request->header->account, $instance, WorkflowInstanceMapper::class, 'instance', $request->getOrigin()); + $instance = $this->createInstanceFromRequest($request); + $this->createModel($request->header->account, $instance, WorkflowInstanceAbstractMapper::class, 'instance', $request->getOrigin()); $this->startInstance($request, $response, $instance); $new = clone $instance; - $new->end = new \DateTime('now'); - $this->updateModel($request->header->account, $instance, $new, WorkflowInstanceMapper::class, 'instance', $request->getOrigin()); + $new->end = new \DateTimeImmutable('now'); + $this->updateModel($request->header->account, $instance, $new, WorkflowInstanceAbstractMapper::class, 'instance', $request->getOrigin()); $view->setTemplate('/Modules/Workflow/Theme/Cli/empty-command'); @@ -141,7 +137,7 @@ final class CliController extends Controller private function validateInstanceCreate(RequestAbstract $request) : array { $val = []; - if (($val['id'] = !$request->hasData('id'))) { + if (($val['id'] = !$request->hasData('-id'))) { return $val; } @@ -163,7 +159,7 @@ final class CliController extends Controller { /** @var \Modules\Workflow\Models\WorkflowTemplate $template */ $template = WorkflowTemplateMapper::get() - ->where('id', (int) $request->getData('id')) + ->where('id', (int) $request->getData('-id')) ->execute(); $instance = new WorkflowInstance(); @@ -185,7 +181,7 @@ final class CliController extends Controller } foreach ($instance->template->schema as $e) { - if ($e['id'] === $request->getDataString('trigger')) { + if ($e['id'] === $request->getDataString('-trigger')) { $this->runWorkflowElement($request, $response, $actions, $instance, $e); break; @@ -198,10 +194,12 @@ final class CliController extends Controller array $actions, WorkflowInstanceAbstract $instance, array $element ) : void { - if (isset($actions[$element['id']])) { + if (isset($actions[(int) $element['id']]) + && $actions[(int) $element['id']]['function'] !== '' + ) { $this->app->moduleManager - ->get($actions[$element['id']]['modules'], $actions[$element['id']]['function_type']) - ->{$actions[$element['id']]['function']}($request, $response, [$element]); + ->get($actions[(int) $element['id']]['module'], $actions[(int) $element['id']]['function_type']) + ->{$actions[(int) $element['id']]['function']}($request, $response, [$element]); } // @todo: currently all children are executed one after another, maybe consider parallel execution diff --git a/Models/WorkflowInstanceAbstract.php b/Models/WorkflowInstanceAbstract.php index 7c93bd7..bb6b784 100755 --- a/Models/WorkflowInstanceAbstract.php +++ b/Models/WorkflowInstanceAbstract.php @@ -43,6 +43,14 @@ class WorkflowInstanceAbstract */ public string $title = ''; + /** + * Instance data. + * + * @var string + * @since 1.0.0 + */ + public string $data = ''; + /** * Instance status. * diff --git a/Theme/Backend/workflow-template-list.tpl.php b/Theme/Backend/workflow-template-list.tpl.php index 6f7d608..e07128f 100755 --- a/Theme/Backend/workflow-template-list.tpl.php +++ b/Theme/Backend/workflow-template-list.tpl.php @@ -46,6 +46,7 @@ echo $this->getData('nav')->render(); ?>