Merged in bugfix/PMCORE-3556 (pull request #8307)

PMCORE-3556

Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
Paula Quispe
2021-12-02 14:40:01 +00:00
committed by Julio Cesar Laura Avendaño

View File

@@ -4,6 +4,8 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use ProcessMaker\BusinessModel\Cases as BusinessModelCases; use ProcessMaker\BusinessModel\Cases as BusinessModelCases;
use ProcessMaker\Core\System; use ProcessMaker\Core\System;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\GroupUser; use ProcessMaker\Model\GroupUser;
use ProcessMaker\Model\Groupwf; use ProcessMaker\Model\Groupwf;
use ProcessMaker\Model\RbacRoles; 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 * 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, * be executed, the specified step much exist and if it contains a condition,
* it must evaluate to true. * it must evaluate to true.
@@ -2502,79 +2501,76 @@ function PMFgetLabelOption ($PROCESS, $DYNAFORM_UID, $FIELD_NAME, $FIELD_SELECTE
* @label PMF Redirect To Step * @label PMF Redirect To Step
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFRedirectToStep.28.29 * @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 string(32) | $appUid | Case ID | The unique ID for a case,
* @param int | $iDelegation | Delegation index | The delegation index of a case. * @param int | $index | 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) | $stepType | 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) | $stepUid | Step ID | The unique ID for the step.
* @return none | $none | None | None * @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 = new G();
$g->sessionVarSave(); $g->sessionVarSave();
$_SESSION["APPLICATION"] = $appUid;
$iDelegation = intval($iDelegation); $_SESSION["INDEX"] = $index;
// Get the caseNumber
$_SESSION["APPLICATION"] = $sApplicationUID; $appNumber = Application::getCaseNumber($appUid);
$_SESSION["INDEX"] = $iDelegation; // Get thread information
$thread = Delegation::getThreadInfo($appNumber, $index);
require_once 'classes/model/AppDelegation.php'; // Review if exist a thread
$oCriteria = new Criteria('workflow'); if (!empty($thread)) {
$oCriteria->addSelectColumn(AppDelegationPeer::TAS_UID); global $oPMScript;
$oCriteria->add(AppDelegationPeer::APP_UID, $sApplicationUID); // Load the data
$oCriteria->add(AppDelegationPeer::DEL_INDEX, $iDelegation); $case = new Cases();
$oDataset = AppDelegationPeer::doSelectRS($oCriteria); // Get the step information
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $step = new Step();
$oDataset->next(); $theStep = $step->loadByType($thread['TAS_UID'], $stepType, $stepUid);
global $oPMScript; // Save data if the case fields loaded in the $oPMScript is related to the same case in execution
$aRow = $oDataset->getRow(); if ($sessionCase === $appUid && !is_null($oPMScript)) {
if ($aRow) { $fields = [];
require_once 'classes/model/Step.php'; $fields['APP_DATA'] = $oPMScript->aFields;
$oStep = new Step(); unset($fields['APP_STATUS']);
$oTheStep = $oStep->loadByType($aRow['TAS_UID'], $sStepType, $sStepUid); unset($fields['APP_PROC_STATUS']);
$bContinue = true; unset($fields['APP_PROC_CODE']);
$oCase = new Cases(); unset($fields['APP_PIN']);
$aFields = $oCase->loadCase($sApplicationUID); $case->updateCase($appUid, $fields);
if ($oTheStep->getStepCondition() != '') {
$pmScript = new PMScript();
$pmScript->setFields($aFields['APP_DATA']);
$pmScript->setScript($oTheStep->getStepCondition());
$pmScript->setExecutedOn(PMScript::CONDITION);
$bContinue = $pmScript->evaluate();
} }
if ($bContinue) { $fields = $case->loadCase($appUid);
switch ($oTheStep->getStepTypeObj()) { // 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': case 'DYNAFORM':
$sAction = 'EDIT'; $action = 'EDIT';
break; break;
case 'OUTPUT_DOCUMENT': case 'OUTPUT_DOCUMENT':
$sAction = 'GENERATE'; $action = 'GENERATE';
break; break;
case 'INPUT_DOCUMENT': case 'INPUT_DOCUMENT':
$sAction = 'ATTACH'; $action = 'ATTACH';
break; break;
case 'EXTERNAL': case 'EXTERNAL':
$sAction = 'EDIT'; $action = 'EDIT';
break; break;
case 'MESSAGE': case 'MESSAGE':
$sAction = ''; $action = '';
break; 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->sessionVarRestore();
G::header('Location: ' . 'cases_Step?TYPE=' . $stepType . '&UID=' . $stepUid . '&POSITION=' . $theStep->getStepPosition() . '&ACTION=' . $action);
G::header('Location: ' . 'cases_Step?TYPE=' . $sStepType . '&UID=' . $sStepUid . '&POSITION=' . $oTheStep->getStepPosition() . '&ACTION=' . $sAction);
die(); die();
} }
} }