Skip to content

Commit

Permalink
Merge pull request #195 from ProcessMaker/testing/add_mi_data_tests
Browse files Browse the repository at this point in the history
Fix MultiInstance loop evaluation
  • Loading branch information
boliviacoca authored Apr 27, 2021
2 parents 5950cfe + 1db0f18 commit b6f9855
Show file tree
Hide file tree
Showing 12 changed files with 542 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ public function iterateNextState(StateInterface $nextState, ExecutionInstanceInt
// The number of instances are calculated once, when entering the activity.
$numberOfInstances = $this->calcNumberOfInstances($instance);
if ($this->getIsSequential()) {
// LoopInstance Counter
$loopCounter = $this->getLoopInstanceProperty($token, 'loopCounter', 0);
if ($loopCounter < $numberOfInstances) {
// Token loopCounter
$tokenLoopCounter = $token->getProperty('data', [])['loopCounter'] ?? 0;
if ($loopCounter === $tokenLoopCounter && $loopCounter < $numberOfInstances) {
$loopCounter++;
$numberOfActiveInstances = 1;
$this->createInstance(
Expand Down Expand Up @@ -181,10 +184,11 @@ private function createInstance(
$properties['data'] = array_merge($properties['data'], (array) $item);
}
$properties['data']['loopCounter'] = $loopCounter;
$newToken = $nextState->addNewToken($instance, $properties, $source);
$newToken = $nextState->createToken($instance, $properties, $source);
$this->setLoopInstanceProperty($newToken, 'numberOfActiveInstances', $numberOfActiveInstances);
$this->setLoopInstanceProperty($newToken, 'numberOfInstances', $numberOfInstances);
$this->setLoopInstanceProperty($newToken, 'loopCounter', $loopCounter);
$nextState->addToken($instance, $newToken, false, $source);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/ProcessMaker/Nayra/Bpmn/StateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ public function addNewToken(ExecutionInstanceInterface $instance = null, array $
return $token;
}

/**
* Create token for the current state.
*
* @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface|null $instance
* @param array $properties
* @param \ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface|null $source
*
* @return TokenInterface
*/
public function createToken(ExecutionInstanceInterface $instance = null, array $properties = [])
{
$token = $this->getRepository()->getTokenRepository()->createTokenInstance();
$token->setOwner($this);
$token->setProperties($properties);
$token->setOwner($this);
$token->setInstance($instance);
$this->getName() ? $token->setStatus($this->getName()) : '';
$token->setIndex($this->getIndex());
return $token;
}

/**
* Add a new token instance to the state.
*
Expand Down
10 changes: 10 additions & 0 deletions src/ProcessMaker/Nayra/Contracts/Bpmn/StateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public function consumeToken(TokenInterface $token);
*/
public function addNewToken(ExecutionInstanceInterface $instance = null, array $properties = [], TransitionInterface $source = null);

/**
* Create token for the current state.
*
* @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface|null $instance
* @param array $properties
*
* @return TokenInterface
*/
public function createToken(ExecutionInstanceInterface $instance = null, array $properties = []);

/**
* Add a new token to the current state.
*
Expand Down
Loading

0 comments on commit b6f9855

Please sign in to comment.