From 42b69899a7cf924a2dfbb5409471bf3abd64bd03 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Tue, 30 Nov 2021 14:52:59 -0400 Subject: [PATCH] PMCORE-3556 --- workflow/engine/classes/class.pmFunctions.php | 108 +++++++++--------- 1 file changed, 52 insertions(+), 56 deletions(-) diff --git a/workflow/engine/classes/class.pmFunctions.php b/workflow/engine/classes/class.pmFunctions.php index 4e6923fd2..cc5b47913 100644 --- a/workflow/engine/classes/class.pmFunctions.php +++ b/workflow/engine/classes/class.pmFunctions.php @@ -4,6 +4,8 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use ProcessMaker\BusinessModel\Cases as BusinessModelCases; use ProcessMaker\Core\System; +use ProcessMaker\Model\Application; +use ProcessMaker\Model\Delegation; use ProcessMaker\Model\GroupUser; use ProcessMaker\Model\Groupwf; use ProcessMaker\Model\RbacRoles; @@ -2491,9 +2493,6 @@ function PMFgetLabelOption ($PROCESS, $DYNAFORM_UID, $FIELD_NAME, $FIELD_SELECTE } /** - * - * @method - * * Redirects a case to any step in the current task. In order for the step to * be executed, the specified step much exist and if it contains a condition, * it must evaluate to true. @@ -2502,79 +2501,76 @@ function PMFgetLabelOption ($PROCESS, $DYNAFORM_UID, $FIELD_NAME, $FIELD_SELECTE * @label PMF Redirect To Step * @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFRedirectToStep.28.29 * - * @param string(32) | $sApplicationUID | Case ID | The unique ID for a case, - * @param int | $iDelegation | Delegation index | The delegation index of a case. - * @param string(32) | $sStepType | Type of Step | The type of step, which can be "DYNAFORM", "INPUT_DOCUMENT" or "OUTPUT_DOCUMENT". - * @param string(32) | $sStepUid | Step ID | The unique ID for the step. + * @param string(32) | $appUid | Case ID | The unique ID for a case, + * @param int | $index | Delegation index | The delegation index of a case. + * @param string(32) | $stepType | Type of Step | The type of step, which can be "DYNAFORM", "INPUT_DOCUMENT" or "OUTPUT_DOCUMENT". + * @param string(32) | $stepUid | Step ID | The unique ID for the step. * @return none | $none | None | None * */ -function PMFRedirectToStep($sApplicationUID, $iDelegation, $sStepType, $sStepUid) +function PMFRedirectToStep($appUid, $index, $stepType, $stepUid) { + // Set initial values + $index = intval($index); + $sessionCase = $_SESSION["APPLICATION"]; + // Save the session variables $g = new G(); - $g->sessionVarSave(); - - $iDelegation = intval($iDelegation); - - $_SESSION["APPLICATION"] = $sApplicationUID; - $_SESSION["INDEX"] = $iDelegation; - - require_once 'classes/model/AppDelegation.php'; - $oCriteria = new Criteria('workflow'); - $oCriteria->addSelectColumn(AppDelegationPeer::TAS_UID); - $oCriteria->add(AppDelegationPeer::APP_UID, $sApplicationUID); - $oCriteria->add(AppDelegationPeer::DEL_INDEX, $iDelegation); - $oDataset = AppDelegationPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - global $oPMScript; - $aRow = $oDataset->getRow(); - if ($aRow) { - require_once 'classes/model/Step.php'; - $oStep = new Step(); - $oTheStep = $oStep->loadByType($aRow['TAS_UID'], $sStepType, $sStepUid); - $bContinue = true; - $oCase = new Cases(); - $aFields = $oCase->loadCase($sApplicationUID); - if ($oTheStep->getStepCondition() != '') { - $pmScript = new PMScript(); - $pmScript->setFields($aFields['APP_DATA']); - $pmScript->setScript($oTheStep->getStepCondition()); - $pmScript->setExecutedOn(PMScript::CONDITION); - $bContinue = $pmScript->evaluate(); + $_SESSION["APPLICATION"] = $appUid; + $_SESSION["INDEX"] = $index; + // Get the caseNumber + $appNumber = Application::getCaseNumber($appUid); + // Get thread information + $thread = Delegation::getThreadInfo($appNumber, $index); + // Review if exist a thread + if (!empty($thread)) { + global $oPMScript; + // Load the data + $case = new Cases(); + // Get the step information + $step = new Step(); + $theStep = $step->loadByType($thread['TAS_UID'], $stepType, $stepUid); + // Save data if the case fields loaded in the $oPMScript is related to the same case in execution + if ($sessionCase === $appUid && !is_null($oPMScript)) { + $fields = []; + $fields['APP_DATA'] = $oPMScript->aFields; + unset($fields['APP_STATUS']); + unset($fields['APP_PROC_STATUS']); + unset($fields['APP_PROC_CODE']); + unset($fields['APP_PIN']); + $case->updateCase($appUid, $fields); } - if ($bContinue) { - switch ($oTheStep->getStepTypeObj()) { + $fields = $case->loadCase($appUid); + // Review the step condition + $continue = true; + if (!empty($theStep->getStepCondition())) { + $pmScript = new PMScript(); + $pmScript->setFields($fields['APP_DATA']); + $pmScript->setScript($theStep->getStepCondition()); + $pmScript->setExecutedOn(PMScript::CONDITION); + $continue = $pmScript->evaluate(); + } + if ($continue) { + switch ($theStep->getStepTypeObj()) { case 'DYNAFORM': - $sAction = 'EDIT'; + $action = 'EDIT'; break; case 'OUTPUT_DOCUMENT': - $sAction = 'GENERATE'; + $action = 'GENERATE'; break; case 'INPUT_DOCUMENT': - $sAction = 'ATTACH'; + $action = 'ATTACH'; break; case 'EXTERNAL': - $sAction = 'EDIT'; + $action = 'EDIT'; break; case 'MESSAGE': - $sAction = ''; + $action = ''; break; } - // save data - if (!is_null($oPMScript)) { - $aFields['APP_DATA'] = $oPMScript->aFields; - unset($aFields['APP_STATUS']); - unset($aFields['APP_PROC_STATUS']); - unset($aFields['APP_PROC_CODE']); - unset($aFields['APP_PIN']); - $oCase->updateCase($sApplicationUID, $aFields); - } $g->sessionVarRestore(); - - G::header('Location: ' . 'cases_Step?TYPE=' . $sStepType . '&UID=' . $sStepUid . '&POSITION=' . $oTheStep->getStepPosition() . '&ACTION=' . $sAction); + G::header('Location: ' . 'cases_Step?TYPE=' . $stepType . '&UID=' . $stepUid . '&POSITION=' . $theStep->getStepPosition() . '&ACTION=' . $action); die(); } }