diff --git a/workflow/engine/classes/class.case.php b/workflow/engine/classes/class.case.php index b069420d4..be9b5ef3c 100644 --- a/workflow/engine/classes/class.case.php +++ b/workflow/engine/classes/class.case.php @@ -1225,6 +1225,35 @@ class Cases } } + + /* + * Determines if the all threads of a multiinstance task are closed + * + * @$appUid string appUid of the instance to be tested + * @$tasUid string task uid of the multiinstance task + * @$previousDelIndex int previous del index of the instance corresponding to the multiinstance task + */ + + public function multiInstanceIsCompleted($appUid, $tasUid, $previousDelIndex) + { + try { + $c = new Criteria(); + $c->clearSelectColumns(); + $c->addSelectColumn('COUNT(*)'); + $c->add(AppDelegationPeer::APP_UID, $appUid); + $c->add(AppDelegationPeer::TAS_UID, $tasUid); + $c->add(AppDelegationPeer::DEL_PREVIOUS, $previousDelIndex); + $c->add(AppDelegationPeer::DEL_THREAD_STATUS, 'OPEN'); + $rs = AppDelegationPeer::doSelectRs($c); + $rs->next(); + $row = $rs->getRow(); + //if no open threads exists, the multiinstance is completes + return intval($row[0]) === 0; + } catch (exception $e) { + throw ($e); + } + } + /* * GetOpenThreads * diff --git a/workflow/engine/classes/class.derivation.php b/workflow/engine/classes/class.derivation.php index a6d883abd..a320848ae 100644 --- a/workflow/engine/classes/class.derivation.php +++ b/workflow/engine/classes/class.derivation.php @@ -1003,12 +1003,27 @@ class Derivation case TASK_FINISH_TASK: $iAppThreadIndex = $appFields['DEL_THREAD']; $this->case->closeAppThread($currentDelegation['APP_UID'], $iAppThreadIndex); + if (isset($nextDel["TAS_UID_DUMMY"]) && !$flagTaskAssignTypeIsMultipleInstance) { $taskDummy = TaskPeer::retrieveByPK($nextDel["TAS_UID_DUMMY"]); if (preg_match("/^(?:END-MESSAGE-EVENT|END-EMAIL-EVENT)$/", $taskDummy->getTasType())) { $this->executeEvent($nextDel["TAS_UID_DUMMY"], $appFields, $flagFirstIteration, true); } } + + //if the next task is an end event and the multiinstance threads are finished the end event + //is triggered: + if (isset($nextDel["TAS_UID_DUMMY"]) && $flagTaskAssignTypeIsMultipleInstance) { + $taskDummy = TaskPeer::retrieveByPK($nextDel["TAS_UID_DUMMY"]); + $currentDeltegionAllData = AppDelegationPeer::retrieveByPK($currentDelegation['APP_UID'], $currentDelegation['DEL_INDEX']); + if ($this->case->multiInstanceIsCompleted($currentDeltegionAllData->getAppUid(), + $currentDeltegionAllData->getTasUid(), + $currentDeltegionAllData->getDelPrevious() + && preg_match("/^(?:END-MESSAGE-EVENT|END-EMAIL-EVENT)$/", $taskDummy->getTasType()))) { + $this->executeEvent($nextDel["TAS_UID_DUMMY"], $appFields, $flagFirstIteration, true); + } + } + $this->case->closeAppThread($currentDelegation['APP_UID'], $iAppThreadIndex); $aContext['action'] = 'finish-task'; //Logger