Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $engine = $execution->getEngine();
     $name = $this->getStringValue($this->name, $execution->getExpressionContext());
     $execution->getEngine()->debug('Executing manual task "{task}"', ['task' => $name]);
     $engine->notify(new TaskExecutedEvent($name, new DelegateExecution($execution), $engine));
     $this->leave($execution);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $execution->getEngine()->debug('Reached terminate end event "{name}"', ['name' => $this->getStringValue($this->name, $execution->getExpressionContext())]);
     $engine = $execution->getEngine();
     $engine->notify(new ActivityCompletedEvent($execution->getNode()->getId(), $execution, $engine));
     $root = $execution->getScopeRoot();
     $root->setNode($execution->getNode());
     $root->setTransition($execution->getTransition());
     $root->terminate(false);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function leave(VirtualExecution $execution, array $transitions = NULL, $canceled = false)
 {
     $root = $execution->getScope();
     $this->clearEventSubscriptions($root, $this->activityId);
     // Fetch outer execution and move it to target node before transition.
     $outer = $root->getParentExecution();
     $outer->setNode($execution->getNode());
     $root->terminate(false);
     if ($canceled) {
         $execution->getEngine()->notify(new ActivityCanceledEvent($this->activityId, $outer, $outer->getEngine()));
     }
     $execution->getEngine()->notify(new ActivityCompletedEvent($this->activityId, $outer, $outer->getEngine()));
     $execution->getEngine()->info('LEAVE: scope <{scope}> at level {level} using {execution}', ['scope' => $this->activityId, 'level' => $outer->getExecutionDepth(), 'execution' => (string) $outer]);
     $outer->takeAll($transitions);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $engine = $execution->getEngine();
     $name = $this->getStringValue($this->name, $execution->getExpressionContext());
     $engine->debug('Evaluate <{language}> script task "{task}"', ['language' => $this->language, 'task' => $name]);
     if ($this->scriptResource !== NULL) {
         $process = $engine->getRepositoryService()->createProcessDefinitionQuery()->processDefinitionId($execution->getProcessModel()->getId())->findOne();
         $deployment = $engine->getRepositoryService()->createDeploymentQuery()->deploymentId($process->getDeploymentId())->findOne();
         $resource = $deployment->findResourceById($process->getResourceId());
         $file = str_replace('./', '', dirname($resource->getName()) . '/' . $this->scriptResource);
         $script = '?>' . $deployment->findResource($file)->getContents();
     } else {
         $script = $this->script;
     }
     // Isolate scope to prevent manipulation of local / instance variables:
     $callback = function (DelegateExecution $execution, $script) {
         return eval($script);
     };
     if (method_exists($callback, 'bindTo')) {
         $callback = $callback->bindTo(NULL, NULL);
     }
     $result = $callback(new DelegateExecution($execution), $script);
     if ($this->resultVariable !== NULL) {
         $execution->setVariable($this->resultVariable, $result);
     }
     $engine->notify(new TaskExecutedEvent($name, new DelegateExecution($execution), $engine));
     $this->leave($execution);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function processSignal(VirtualExecution $execution, $signal, array $variables = [], array $delegation = [])
 {
     $engine = $execution->getEngine();
     $engine->notify(new ActivityCompletedEvent($execution->getNode()->getId(), $execution, $engine));
     $node = $execution->getProcessModel()->findNode($delegation['nodeId']);
     $engine->notify(new ActivityStartedEvent($node->getId(), $execution, $engine));
     $this->delegateSignal($execution, $signal, $variables, $delegation);
 }
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $engine = $execution->getEngine();
     $name = $this->getStringValue($this->name, $execution->getExpressionContext());
     $engine->debug('{execution} reached checkpoint "{checkpoint}" ({node})', ['execution' => (string) $execution, 'checkpoint' => $this->name, 'node' => $execution->getNode()->getId()]);
     $engine->notify(new CheckpointReachedEvent($name, new DelegateExecution($execution), $engine));
     $this->leave($execution);
 }
 /**
  * {@inheritdoc}
  */
 public function createEventSubscriptions(VirtualExecution $execution, $activityId, Node $node = NULL)
 {
     $date = $this->getDateValue($this->date, $execution->getExpressionContext());
     if (!$date instanceof \DateTimeInterface) {
         throw new \RuntimeException(sprintf('Expecting DateTimeInterface, given %s', is_object($date) ? get_class($date) : gettype($date)));
     }
     $execution->getEngine()->executeCommand(new CreateTimerSubscriptionCommand($date, $execution, $activityId, $node === NULL ? $execution->getNode() : $node));
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $model = $execution->getProcessModel();
     $execution->getEngine()->debug('Starting sub process "{process}"', ['process' => $this->getStringValue($this->name, $execution->getExpressionContext())]);
     $startNode = $model->findNode($this->startNodeId);
     if (!$startNode->getBehavior() instanceof NoneStartEventBehavior) {
         throw new \RuntimeException(sprintf('Cannot start sub process %s ("%s") because it is missing start node %s', $execution->getNode()->getId(), $this->getStringValue($this->name, $execution->getExpressionContext()), $this->startNodeId));
     }
     $execution->waitForSignal();
     $sub = $execution->createNestedExecution($model, $startNode, true, false);
     $sub->execute($startNode);
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $context = $execution->getExpressionContext();
     $definition = $execution->getEngine()->getRepositoryService()->createProcessDefinitionQuery()->processDefinitionKey($this->processDefinitionKey)->findOne();
     $execution->getEngine()->debug('Starting process {process} from call activity "{task}"', ['process' => $this->processDefinitionKey, 'task' => $this->getStringValue($this->name, $context)]);
     $start = $definition->getModel()->findInitialNodes();
     if (count($start) !== 1) {
         throw new \RuntimeException(sprintf('Missing single non start event in process %s', $definition->getKey()));
     }
     $startNode = array_shift($start);
     $sub = $execution->createNestedExecution($definition->getModel(), $startNode, true, true);
     foreach ($this->inputs as $target => $source) {
         if ($source instanceof ExpressionInterface) {
             $sub->setVariable($target, $source($context));
         } elseif ($execution->hasVariable($source)) {
             $sub->setVariable($target, $execution->getVariable($source));
         }
     }
     $execution->waitForSignal();
     $sub->execute($startNode);
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function processSignal(VirtualExecution $execution, $signal, array $variables = [], array $delegation = [])
 {
     $engine = $execution->getEngine();
     // Log activity, boundary events do not have a duration > 0.
     $engine->notify(new ActivityStartedEvent($this->activityId, $execution, $engine));
     $engine->notify(new ActivityCompletedEvent($this->activityId, $execution, $engine));
     if ($this->isInterrupting()) {
         $this->findScopeActivity($execution)->interrupt($execution);
     } else {
         $this->findScopeActivity($execution)->leaveConcurrent($execution);
     }
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $engine = $execution->getEngine();
     $name = $this->getStringValue($this->name, $execution->getExpressionContext());
     $engine->debug('Execute expression in service task "{task}"', ['task' => $name]);
     $result = $this->getValue($this->expression, $execution->getExpressionContext());
     if ($this->resultVariable !== NULL) {
         $execution->setVariable($this->resultVariable, $result);
     }
     $engine->notify(new TaskExecutedEvent($name, new DelegateExecution($execution), $engine));
     $this->leave($execution);
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $engine = $execution->getEngine();
     $typeName = $this->getStringValue($this->typeName, $execution->getExpressionContext());
     $name = $this->getStringValue($this->name, $execution->getExpressionContext());
     $task = $engine->createDelegateTask($typeName);
     if (!$task instanceof DelegateTaskInterface) {
         throw new \RuntimeException('Invalid service task implementation: ' . get_class($task));
     }
     $engine->debug('Execute delegate task "{task}" implemented by <{class}>', ['task' => $name, 'class' => get_class($task)]);
     $task->execute(new DelegateExecution($execution));
     $engine->notify(new TaskExecutedEvent($name, new DelegateExecution($execution), $engine));
     $this->leave($execution);
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function interrupt(VirtualExecution $execution, array $transitions = NULL)
 {
     $engine = $execution->getEngine();
     $root = $execution->getScope();
     $params = ['e1' => $root->getId()];
     $i = 1;
     foreach ($root->findChildExecutions() as $child) {
         $params['e' . ++$i] = $child->getId();
     }
     $placeholders = implode(', ', array_map(function ($p) {
         return ':' . $p;
     }, array_keys($params)));
     $stmt = $engine->prepareQuery("SELECT `id` FROM `#__bpmn_user_task` WHERE `execution_id` IN ({$placeholders})");
     $stmt->bindAll($params);
     $stmt->transform('id', new UUIDTransformer());
     $stmt->execute();
     foreach ($stmt->fetchColumns('id') as $taskId) {
         $engine->executeCommand(new RemoveUserTaskCommand($taskId));
     }
     parent::interrupt($execution, $transitions);
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function createEventSubscriptions(VirtualExecution $execution, $activityId, Node $node = NULL)
 {
     $execution->getEngine()->executeCommand(new CreateSignalSubscriptionCommand($this->signal, $execution, $activityId, $node, true));
 }
Exemplo n.º 15
0
 /**
  * Delegate signal to a target node using the same execution.
  * 
  * @param VirtualExecution $execution
  * @param string $signal
  * @param array $variables
  * @param array $delegation
  * @return boolean Returns true if the signal could be delegated.
  */
 protected function delegateSignal(VirtualExecution $execution, $signal, array $variables, array $delegation)
 {
     if (empty($delegation['nodeId'])) {
         return false;
     }
     $node = $execution->getProcessModel()->findNode($delegation['nodeId']);
     $execution->getEngine()->debug('Delegating signal <{signal}> to {node}', ['signal' => $signal === NULL ? 'NULL' : $signal, 'node' => (string) $node]);
     $execution->setNode($node);
     $execution->waitForSignal();
     $execution->signal($signal, $variables);
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function createEventSubscriptions(VirtualExecution $execution, $activityId, Node $node = NULL)
 {
     $execution->getEngine()->pushCommand(new CreateSignalSubscriptionCommand($this->signal, $execution, $activityId, $node === NULL ? $execution->getNode() : $node));
     parent::createEventSubscriptions($execution, $activityId, $node);
 }
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $execution->getEngine()->pushCommand(new SignalEventReceivedCommand($this->signalName, NULL, [], $execution));
     $execution->waitForSignal();
 }
Exemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public function createEventSubscriptions(VirtualExecution $execution, $activityId, Node $node = NULL)
 {
     $execution->getEngine()->executeCommand(new CreateMessageSubscriptionCommand($this->message, $execution, $activityId, $node === NULL ? $execution->getNode() : $node));
 }
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $execution->getEngine()->pushCommand(new ThrowMessageCommand($execution));
     $execution->waitForSignal();
 }