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);
$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; global $oPMScript;
$aRow = $oDataset->getRow(); // Load the data
if ($aRow) { $case = new Cases();
require_once 'classes/model/Step.php'; // Get the step information
$oStep = new Step(); $step = new Step();
$oTheStep = $oStep->loadByType($aRow['TAS_UID'], $sStepType, $sStepUid); $theStep = $step->loadByType($thread['TAS_UID'], $stepType, $stepUid);
$bContinue = true; // Save data if the case fields loaded in the $oPMScript is related to the same case in execution
$oCase = new Cases(); if ($sessionCase === $appUid && !is_null($oPMScript)) {
$aFields = $oCase->loadCase($sApplicationUID); $fields = [];
if ($oTheStep->getStepCondition() != '') { $fields['APP_DATA'] = $oPMScript->aFields;
$pmScript = new PMScript(); unset($fields['APP_STATUS']);
$pmScript->setFields($aFields['APP_DATA']); unset($fields['APP_PROC_STATUS']);
$pmScript->setScript($oTheStep->getStepCondition()); unset($fields['APP_PROC_CODE']);
$pmScript->setExecutedOn(PMScript::CONDITION); unset($fields['APP_PIN']);
$bContinue = $pmScript->evaluate(); $case->updateCase($appUid, $fields);
} }
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();
} }
} }