Skip to content

Commit

Permalink
Add recursion protection
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Jun 3, 2017
1 parent 18e5200 commit 5692945
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Core/WorkflowServiceFacade.php
Expand Up @@ -21,12 +21,14 @@ class WorkflowServiceFacade
protected $cacheDir;
protected $debugMode;
protected $logger;

protected $recursionLimit;
protected static $workflowExecuting = 0;

public function __construct(MigrationService $innerService, $cacheDir, $debugMode = false, LoggerInterface $logger = null)
public function __construct(MigrationService $innerService, $recursionLimit, $cacheDir, $debugMode = false,
LoggerInterface $logger = null)
{
$this->innerService = $innerService;
$this->recursionLimit = $recursionLimit;
$this->cacheDir = $cacheDir;
$this->debugMode = $debugMode;
$this->logger = $logger;
Expand Down Expand Up @@ -61,6 +63,10 @@ public function triggerWorkflow($signalName, array $signalParameters)
return;
}

if (self::$workflowExecuting >= $this->recursionLimit) {
throw new \Exception("Workflow execution halted as we reached {$this->recursionLimit} nested workflows");
}

$wfd = new WorkflowDefinition(
$workflowDefinition->name,
$workflowDefinition->path,
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/services.yml
Expand Up @@ -3,6 +3,8 @@ parameters:
ez_workflowengine_bundle.workflow_directory: 'WorkflowDefinitions'
# Set to false to disable completely the debug log of executed migration steps (also echoed to cli in verbose mode)
ez_workflowengine_bundle.enable_debug_output: true
# Abort execution when workflows triggered in cascade reach this limit
ez_workflowengine_bundle.recursion_limit: 100

ez_workflowengine_bundle.workflow_service.facade.class: Kaliop\eZWorkflowEngineBundle\Core\WorkflowServiceFacade
ez_workflowengine_bundle.workflow_service.inner.class: Kaliop\eZWorkflowEngineBundle\Core\WorkflowServiceInner
Expand All @@ -29,6 +31,7 @@ services:
class: '%ez_workflowengine_bundle.workflow_service.facade.class%'
arguments:
- '@ez_workflowengine_bundle.workflow_service.inner'
- '%ez_workflowengine_bundle.recursion_limit%'
- '%kernel.cache_dir%/ezworkflowdefinitions'
- '%kernel.debug%'
- '@?logger'
Expand Down

0 comments on commit 5692945

Please sign in to comment.