This commit is contained in:
Paula Quispe
2018-11-21 16:32:48 -04:00
parent 29cd1acc59
commit 7fff95b0f6
5 changed files with 210 additions and 111 deletions

View File

@@ -8,7 +8,6 @@ use ProcessMaker\ChangeLog\ChangeLog;
use ProcessMaker\Core\System; use ProcessMaker\Core\System;
use ProcessMaker\Plugins\PluginRegistry; use ProcessMaker\Plugins\PluginRegistry;
/** /**
* A Cases object where you can do start, load, update, refresh about cases * A Cases object where you can do start, load, update, refresh about cases
* This object is applied to Task * This object is applied to Task
@@ -20,6 +19,7 @@ class Cases
public $dir = 'ASC'; public $dir = 'ASC';
public $sort = 'APP_MSG_DATE'; public $sort = 'APP_MSG_DATE';
public $arrayTriggerExecutionTime = []; public $arrayTriggerExecutionTime = [];
private $triggerMessageExecution = '';
public function __construct() public function __construct()
{ {
@@ -29,6 +29,28 @@ class Cases
} }
} }
/**
* Get the triggerMessageExecution
*
* @return string
*/
public function getTriggerMessageExecution()
{
return $this->triggerMessageExecution;
}
/**
* Add messages related to the trigger execution
*
* @param string $v
*
* @return void
*/
public function addTriggerMessageExecution($v)
{
$this->triggerMessageExecution .= $v;
}
/** /**
* Ask if an user can start a case * Ask if an user can start a case
* @param string $sUIDUser * @param string $sUIDUser
@@ -3438,61 +3460,86 @@ class Cases
*/ */
public function executeTriggers($tasUid, $stepType, $stepUidObj, $triggerType, $fieldsCase = []) public function executeTriggers($tasUid, $stepType, $stepUidObj, $triggerType, $fieldsCase = [])
{ {
//Load the triggers assigned in the step
$triggersList = $this->loadTriggers($tasUid, $stepType, $stepUidObj, $triggerType);
//Execute the trigger defined in the step
$lastFields = $this->executeTriggerFromList($triggersList, $fieldsCase, $stepType, $stepUidObj, $triggerType);
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
ChangeLog::getChangeLog() ChangeLog::getChangeLog()
->setObjectUid($stepUidObj) ->setObjectUid($stepUidObj)
->getExecutedAtIdByTriggerType($triggerType); ->getExecutedAtIdByTriggerType($triggerType);
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
$listTriggers = $this->loadTriggers($tasUid, $stepType, $stepUidObj, $triggerType); return $lastFields;
}
if (count($listTriggers) > 0) { /**
* This method executes the triggers send in an array
*
* @param array $triggersList
* @param array $fieldsCase
* @param string $stepType
* @param string $stepUidObj
* @param string $triggerType
* @param string $labelAssignment
*
* @return array
*/
public function executeTriggerFromList(
array $triggersList,
array $fieldsCase,
$stepType,
$stepUidObj,
$triggerType,
$labelAssignment = ''
)
{
if (count($triggersList) > 0) {
global $oPMScript; global $oPMScript;
$this->addTriggerMessageExecution("<br /><b>" . $labelAssignment . "</b><br />");
if (!isset($oPMScript)) {
$oPMScript = new PMScript(); $oPMScript = new PMScript();
}
$oPMScript->setFields($fieldsCase); $oPMScript->setFields($fieldsCase);
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
$cs = new CodeScanner(config("system.workspace")); $cs = new CodeScanner(config("system.workspace"));
$strFoundDisabledCode = ""; $foundDisabledCode = "";
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
foreach ($listTriggers as $trigger) { $fieldsTrigger = [];
/*----------------------------------********---------------------------------*/ foreach ($triggersList as $trigger) {
if (PMLicensedFeatures::getSingleton()->verifyfeature("B0oWlBLY3hHdWY0YUNpZEtFQm5CeTJhQlIwN3IxMEkwaG4=")) { //Scan the code
//Check disabled code $disabledCode = $this->codeScannerReview($cs, $trigger["TRI_WEBBOT"], $trigger["TRI_TITLE"]);
$arrayFoundDisabledCode = $cs->checkDisabledCode("SOURCE", $trigger["TRI_WEBBOT"]); if (!empty($disabledCode)) {
$foundDisabledCode .= $disabledCode;
if (!empty($arrayFoundDisabledCode)) {
$strCodeAndLine = "";
foreach ($arrayFoundDisabledCode["source"] as $key => $value) {
$strCodeAndLine .= (($strCodeAndLine != "") ? ", " : "") . G::LoadTranslation("ID_DISABLED_CODE_CODE_AND_LINE", array($key, implode(", ", $value)));
}
$strFoundDisabledCode .= "<br />- " . $trigger["TRI_TITLE"] . ": " . $strCodeAndLine;
continue; continue;
} }
}
/*----------------------------------********---------------------------------*/
//Execute
$execute = true; $execute = true;
//Check if the trigger has conditions for the execution
if ($trigger['ST_CONDITION'] !== '') { if (!empty($trigger['ST_CONDITION'])) {
$oPMScript->setDataTrigger($trigger); $oPMScript->setDataTrigger($trigger);
$oPMScript->setScript($trigger['ST_CONDITION']); $oPMScript->setScript($trigger['ST_CONDITION']);
$oPMScript->setExecutedOn(PMScript::CONDITION); $oPMScript->setExecutedOn(PMScript::CONDITION);
$execute = $oPMScript->evaluate(); $execute = $oPMScript->evaluate();
} }
//Execute the trigger
if ($execute) { if ($execute) {
$oPMScript->setDataTrigger($trigger); $oPMScript->setDataTrigger($trigger);
$oPMScript->setScript($trigger['TRI_WEBBOT']); $oPMScript->setScript($trigger['TRI_WEBBOT']);
$executedOn = $oPMScript->getExecutionOriginForAStep($stepType, $stepUidObj, $triggerType); $executedOn = $oPMScript->getExecutionOriginForAStep($stepType, $stepUidObj, $triggerType);
$oPMScript->setExecutedOn($executedOn); $oPMScript->setExecutedOn($executedOn);
$oPMScript->execute(); $oPMScript->execute();
$fieldsTrigger = $oPMScript->aFields; $varsChanged = $oPMScript->getVarsChanged();
$appDataAfterTrigger = $oPMScript->aFields;
//Get the key and values changed
$fieldsTrigger = $this->findKeysAndValues($appDataAfterTrigger, $varsChanged);
//We will be load the last appData //We will be load the last appData
if ($oPMScript->executedOn() === $oPMScript::AFTER_ROUTING) { if ($oPMScript->executedOn() === $oPMScript::AFTER_ROUTING) {
@@ -3503,14 +3550,28 @@ class Cases
} }
} }
//Register the time execution
$this->arrayTriggerExecutionTime[$trigger['TRI_UID']] = $oPMScript->scriptExecutionTime; $this->arrayTriggerExecutionTime[$trigger['TRI_UID']] = $oPMScript->scriptExecutionTime;
//Register the message of execution
$varTriggers = "&nbsp;- " . nl2br(htmlentities($trigger["TRI_TITLE"], ENT_QUOTES)) . "<br/>";
$this->addTriggerMessageExecution($varTriggers);
} }
} }
/*----------------------------------********---------------------------------*/
if (!empty($foundDisabledCode)) {
G::SendTemporalMessage(
G::LoadTranslation("ID_DISABLED_CODE_TRIGGER_TO_EXECUTE", [$foundDisabledCode]),
"",
"string"
);
}
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
if ($strFoundDisabledCode != "") {
G::SendTemporalMessage(G::LoadTranslation("ID_DISABLED_CODE_TRIGGER_TO_EXECUTE", array($strFoundDisabledCode)), "", "string"); //The Code Scanner can be interrupt the execution
if (empty($fieldsTrigger)) {
return $fieldsCase;
} }
/*----------------------------------********---------------------------------*/
return $fieldsTrigger; return $fieldsTrigger;
} else { } else {
@@ -3518,6 +3579,56 @@ class Cases
} }
} }
/**
* Find keys and values into the appData
*
* @param array $appData
* @param array $keyToSearch
*
* @return array
*/
private function findKeysAndValues(array $appData, array $keyToSearch)
{
$keysAndValues = [];
foreach ($keyToSearch as $key) {
$keysAndValues[$key] = $appData[$key];
}
return $keysAndValues;
}
/**
* Review the code in the trigger if the feature is enable
*
* @param CodeScanner $cs
* @param string $code
* @param string $triTitle
*
* @return string
*
*/
private function codeScannerReview(CodeScanner $cs, $code, $triTitle)
{
$foundDisabledCode = "";
/*----------------------------------********---------------------------------*/
if (PMLicensedFeatures::getSingleton()->verifyfeature("B0oWlBLY3hHdWY0YUNpZEtFQm5CeTJhQlIwN3IxMEkwaG4=")) {
//Check disabled code
$arrayFoundDisabledCode = $cs->checkDisabledCode("SOURCE", $code);
if (!empty($arrayFoundDisabledCode)) {
$codeAndLine = "";
foreach ($arrayFoundDisabledCode["source"] as $key => $value) {
$codeAndLine .= (($codeAndLine != "") ? ", " : "") . G::LoadTranslation("ID_DISABLED_CODE_CODE_AND_LINE",
[$key, implode(", ", $value)]);
}
$foundDisabledCode .= "<br />- " . $triTitle . ": " . $codeAndLine;
}
}
/*----------------------------------********---------------------------------*/
return $foundDisabledCode;
}
/** /**
* Get the trigger's names * Get the trigger's names
* @name getTriggerNames * @name getTriggerNames

View File

@@ -2169,7 +2169,7 @@ class WsBase
* Execute the trigger defined in the steps * Execute the trigger defined in the steps
* This function is used when the case is derived from abe, Soap, PMFDerivateCase * This function is used when the case is derived from abe, Soap, PMFDerivateCase
* *
* @param string $caseId , Uid related to the case * @param string $appUid , Uid related to the case
* @param array $appData , contain all the information about the case related to the index [APP_DATA] * @param array $appData , contain all the information about the case related to the index [APP_DATA]
* @param string $tasUid , Uid related to the task * @param string $tasUid , Uid related to the task
* @param string $stepType , before or after step * @param string $stepType , before or after step
@@ -2180,7 +2180,7 @@ class WsBase
* @return string $varTriggers updated * @return string $varTriggers updated
*/ */
public function executeTriggerFromDerivate( public function executeTriggerFromDerivate(
$caseId, $appUid,
&$appData, &$appData,
$tasUid, $tasUid,
$stepType, $stepType,
@@ -2189,69 +2189,38 @@ class WsBase
$labelAssignment = '' $labelAssignment = ''
) )
{ {
$varTriggers = ""; $caseInstance = new Cases();
$oCase = new Cases();
//Load the triggers assigned in the $triggerType //Set new variables in the APP_DATA
$aTriggers = $oCase->loadTriggers($tasUid, $stepType, $stepUidObj, $triggerType);
if (count($aTriggers) > 0) {
$varTriggers = $varTriggers . "<br /><b>" . $labelAssignment . "</b><br />";
global $oPMScript;
if (!isset($oPMScript)) {
$oPMScript = new PMScript();
}
foreach ($aTriggers as $aTrigger) {
//Set variables
$params = new stdClass(); $params = new stdClass();
$params->appData = $appData; $params->appData = $appData;
if ($this->stored_system_variables) { if ($this->stored_system_variables) {
$params->option = "STORED SESSION"; $params->option = "STORED SESSION";
$params->SID = $this->wsSessionId; $params->SID = $this->wsSessionId;
} }
//We can set the index APP_DATA
$appFields["APP_DATA"] = array_merge($appData, G::getSystemConstants($params)); $appFields["APP_DATA"] = array_merge($appData, G::getSystemConstants($params));
//PMScript //Load the triggers assigned in the step
$oPMScript->setFields($appFields['APP_DATA']); $triggersList = $caseInstance->loadTriggers($tasUid, $stepType, $stepUidObj, $triggerType);
$bExecute = true;
if ($aTrigger['ST_CONDITION'] !== '') { //Execute the trigger defined in the step
$oPMScript->setScript($aTrigger['ST_CONDITION']); $lastFields = $caseInstance->executeTriggerFromList($triggersList, $appFields["APP_DATA"], $stepType, $stepUidObj, $triggerType, $labelAssignment);
$oPMScript->setExecutedOn(PMScript::CONDITION);
$bExecute = $oPMScript->evaluate();
}
if ($bExecute) { //Get message of the execution
$oPMScript->setDataTrigger($aTrigger); $varTriggers = $caseInstance->getTriggerMessageExecution();
$oPMScript->setScript($aTrigger['TRI_WEBBOT']);
$executedOn = $oPMScript->getExecutionOriginForAStep($stepType, $stepUidObj, $triggerType);
$oPMScript->setExecutedOn($executedOn);
$oPMScript->execute();
$trigger = TriggersPeer::retrieveByPk($aTrigger["TRI_UID"]); //Define the new APP_DATA
$varTriggers = $varTriggers . "&nbsp;- " . nl2br(htmlentities( $appFields['APP_DATA'] = $lastFields;
$trigger->getTriTitle(),
ENT_QUOTES
)) . "<br />";
$appFields['APP_DATA'] = $oPMScript->aFields;
unset($appFields['APP_STATUS']); unset($appFields['APP_STATUS']);
unset($appFields['APP_PROC_STATUS']); unset($appFields['APP_PROC_STATUS']);
unset($appFields['APP_PROC_CODE']); unset($appFields['APP_PROC_CODE']);
unset($appFields['APP_PIN']); unset($appFields['APP_PIN']);
$oCase->updateCase($caseId, $appFields);
//Update the APP_DATA
$caseInstance->updateCase($appUid, $appFields);
//We need to update the variable $appData for use the new variables in the next trigger //We need to update the variable $appData for use the new variables in the next trigger
$appData = array_merge($appData, $appFields['APP_DATA']); $appData = array_merge($appData, $appFields['APP_DATA']);
}
}
}
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
ChangeLog::getChangeLog() ChangeLog::getChangeLog()

View File

@@ -117,6 +117,11 @@ class PMScript
*/ */
protected $executedOn = self::UNDEFINED_ORIGIN; protected $executedOn = self::UNDEFINED_ORIGIN;
/**
* Variables changed in the trigger execution
*/
private $varsChanged = [];
/** /**
* Constructor of the class PMScript * Constructor of the class PMScript
* *
@@ -127,6 +132,28 @@ class PMScript
$this->aFields['__ERROR__'] = 'none'; $this->aFields['__ERROR__'] = 'none';
} }
/**
* Set the fields changed in the trigger execution
*
* @param array $v
*
* @return void
*/
public function setVarsChanged(array $v)
{
$this->varsChanged = $v;
}
/**
* Get the fields changed in the trigger execution
*
* @return array
*/
public function getVarsChanged()
{
return $this->varsChanged;
}
/** /**
* Set the fields to use * Set the fields to use
* *
@@ -437,7 +464,7 @@ class PMScript
$sScript = "try {\n" . $sScript . "\n} catch (Exception \$oException) {\n " . " \$this->aFields['__ERROR__'] = utf8_encode(\$oException->getMessage());\n}"; $sScript = "try {\n" . $sScript . "\n} catch (Exception \$oException) {\n " . " \$this->aFields['__ERROR__'] = utf8_encode(\$oException->getMessage());\n}";
$this->executeAndCatchErrors($sScript, $this->sScript); $this->executeAndCatchErrors($sScript, $this->sScript);
$this->setVarsChanged($this->affected_fields);
$this->aFields["__VAR_CHANGED__"] = implode(",", $this->affected_fields); $this->aFields["__VAR_CHANGED__"] = implode(",", $this->affected_fields);
for ($i = 0; $i < count($this->affected_fields); $i ++) { for ($i = 0; $i < count($this->affected_fields); $i ++) {
$_SESSION['TRIGGER_DEBUG']['DATA'][] = Array('key' => $this->affected_fields[$i], 'value' => isset($this->aFields[$this->affected_fields[$i]]) ? $this->aFields[$this->affected_fields[$i]] : '' $_SESSION['TRIGGER_DEBUG']['DATA'][] = Array('key' => $this->affected_fields[$i], 'value' => isset($this->aFields[$this->affected_fields[$i]]) ? $this->aFields[$this->affected_fields[$i]] : ''

View File

@@ -29,7 +29,7 @@ foreach ($aTriggers as $aTrigger) {
$triggersList[$i]['code'] = $geshi->parse_code(); //$aTrigger['TRIGGERS_VALUES'][$index]['TRI_WEBBOT']; $triggersList[$i]['code'] = $geshi->parse_code(); //$aTrigger['TRIGGERS_VALUES'][$index]['TRI_WEBBOT'];
$triggerUid = $aTrigger['TRIGGERS_VALUES'][$index]['TRI_UID']; $triggerUid = $aTrigger['TRIGGERS_VALUES'][$index]['TRI_UID'];
$triggersList[$i]['script_execution_time'] = $aTrigger['TRIGGERS_EXECUTION_TIME'][$triggerUid]; $triggersList[$i]['script_execution_time'] = isset($aTrigger['TRIGGERS_EXECUTION_TIME'][$triggerUid]) ? $aTrigger['TRIGGERS_EXECUTION_TIME'][$triggerUid] : '';
$i ++; $i ++;
} }
@@ -58,14 +58,6 @@ foreach ($DEBUG_ERRORS as $error) {
$i ++; $i ++;
} }
} }
/*echo '{total:5, data:[
{name:"trigger1", execution_time:"after"},
{name:"trigger2", execution_time:"before"},
{name:"trigger13", execution_time:"before"},
]}';
*/
$triggersRet = new StdClass(); $triggersRet = new StdClass();
$triggersRet->total = count( $triggersList ); $triggersRet->total = count( $triggersList );
$triggersRet->data = $triggersList; $triggersRet->data = $triggersList;

View File

@@ -81,8 +81,8 @@ switch ($request) {
$systemConstants = G::getSystemConstants(); $systemConstants = G::getSystemConstants();
//Add missing items //Add missing items
$systemConstants['PIN'] = $aVars['PIN']; $systemConstants['PIN'] = isset($aVars['PIN']) ? $aVars['PIN'] : '';
$systemConstants['APP_NUMBER'] = $aVars['APP_NUMBER']; $systemConstants['APP_NUMBER'] = isset($aVars['APP_NUMBER']) ? $aVars['APP_NUMBER'] : '';
//when a case with dynaform is started there are no changed variables, this event is validated //when a case with dynaform is started there are no changed variables, this event is validated
if (isset($aVars['__VAR_CHANGED__'])) { if (isset($aVars['__VAR_CHANGED__'])) {
$systemConstants['__VAR_CHANGED__'] = $aVars['__VAR_CHANGED__']; $systemConstants['__VAR_CHANGED__'] = $aVars['__VAR_CHANGED__'];