Errors from triggers in a process need to be stored in a different file of the error_log.
This commit is contained in:
dheeyi william
2017-04-19 11:30:54 -04:00
parent b5eeafb420
commit e16119a73c
7 changed files with 81 additions and 60 deletions

View File

@@ -5826,6 +5826,39 @@ class G
{
return $e->getMessage();
}
/**
* Add log of execution of triggers
* @param $data
* @param string $stringError
* @param string $typeTriggerError
* @param int $executionTime
*/
public static function logTriggerExecution($data, $sError = 'NO-ERROR', $typeError = '', $executionTime = 0)
{
if ((!empty($data['_CODE_']) || $typeError == 'FATAL_ERROR') && isset($data['_DATA_TRIGGER_']) &&
!isset($data['_DATA_TRIGGER_']['_TRI_LOG_'])
) {
$lg = Bootstrap::getDefaultContextLog();
$lg['TRI_TITLE'] = isset($data['_DATA_TRIGGER_']['TRI_TITLE']) ? $data['_DATA_TRIGGER_']['TRI_TITLE'] : '';
$lg['TRI_UID'] = isset($data['_DATA_TRIGGER_']['TRI_UID']) ? $data['_DATA_TRIGGER_']['TRI_UID'] : '';
$lg['TRI_CODE'] = isset($data['_DATA_TRIGGER_']['TRI_WEBBOT']) ? $data['_DATA_TRIGGER_']['TRI_WEBBOT'] : '';
$lg['TRI_EXECUTION_TIME'] = $executionTime;
$lg['TRI_MSG_ERROR'] = $sError;
$lg['APP_UID'] = isset($data['APPLICATION']) ? $data['APPLICATION'] : '';
$lg['PRO_UID'] = isset($data['PROCESS']) ? $data['PROCESS'] : '';
$lg['TAS_UID'] = isset($data['TASK']) ? $data['TASK'] : '';
$lg['USR_UID'] = isset($data['USER_LOGGED']) ? $data['USER_LOGGED'] : '';
Bootstrap::registerMonolog(
(empty($sError)) ? 'TriggerExecution' : 'TriggerExecutionError',
(empty($sError)) ? 200 : 400,
(empty($sError)) ? 'Trigger Execution' : 'Trigger Execution Error',
$lg, $lg['workspace'], 'processmaker.log');
$_SESSION['_DATA_TRIGGER_']['_TRI_LOG_'] = true;
}
}
}
/**

View File

@@ -3478,11 +3478,13 @@ class Cases
$bExecute = true;
if ($aTrigger['ST_CONDITION'] !== '') {
$oPMScript->setDataTrigger($aTrigger);
$oPMScript->setScript($aTrigger['ST_CONDITION']);
$bExecute = $oPMScript->evaluate();
}
if ($bExecute) {
$oPMScript->setDataTrigger($aTrigger);
$oPMScript->setScript($aTrigger['TRI_WEBBOT']);
$oPMScript->execute();
@@ -7154,9 +7156,6 @@ class Cases
unset($aFields['APP_PIN']);
$this->updateCase($aFields['APP_UID'], $aFields);
//Log
Bootstrap::registerMonolog('triggerExecutionTime', 200, 'Trigger execution time', ['proUid' => $aFields['APP_DATA']['PROCESS'], 'tasUid' => $aFields['APP_DATA']['TASK'], 'appUid' => $aFields['APP_DATA']['APPLICATION'], 'action' => $action, 'triggerInfo' => ['triUid' => $arrayWebBotTrigger['TRI_UID'], 'triExecutionTime' => $oPMScript->scriptExecutionTime]], SYS_SYS, 'processmaker.log');
return true;
}
return false;

View File

@@ -97,6 +97,10 @@ if (file_exists( $dir )) {
*/
class PMScript
{
/**
* @var array $dataTrigger
*/
public $dataTrigger = array();
/**
* Original fields
@@ -208,15 +212,35 @@ class PMScript
return true;
}
/**
* @param $dataTrigger
*/
public function setDataTrigger($dataTrigger)
{
$this->dataTrigger = is_array($dataTrigger) ? $dataTrigger : array();
}
/**
* @param $sScript
* @param $sCode
*/
public function executeAndCatchErrors($sScript, $sCode)
{
ob_start('handleFatalErrors');
set_error_handler('handleErrors');
$_SESSION['_CODE_'] = $sCode;
$_SESSION['_DATA_TRIGGER_'] = $this->dataTrigger;
$_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'] = microtime(true);
eval($sScript);
$this->scriptExecutionTime = round(microtime(true) -
$_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'], 5);
$this->evaluateVariable();
unset( $_SESSION['_CODE_'] );
ob_end_flush();
//log trigger execution in processmaker.log
G::logTriggerExecution($_SESSION, '', '', $this->scriptExecutionTime);
unset($_SESSION['_CODE_']);
unset($_SESSION['_DATA_TRIGGER_']);
}
/**
@@ -363,14 +387,8 @@ class PMScript
$sScript = "try {\n" . $sScript . "\n} catch (Exception \$oException) {\n " . " \$this->aFields['__ERROR__'] = utf8_encode(\$oException->getMessage());\n}";
//echo '<pre>-->'; print_r($this->aFields); echo '<---</pre>';
$timeStart = microtime(true);
$this->executeAndCatchErrors($sScript, $this->sScript);
$timeEnd = microtime(true);
$this->scriptExecutionTime = round($timeEnd - $timeStart, 5);
$this->aFields["__VAR_CHANGED__"] = implode(",", $this->affected_fields);
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]] : ''
@@ -692,16 +710,19 @@ function pmSqlEscape ($vValue)
* author: Julio Cesar Laura Avenda<64>o <juliocesar@colosa.com>
* date: 2009-10-01
* ************************************************************************* */
/*
* Convert to data base escaped string
* @param string $errno
* @param string $errstr
* @param string $errfile
* @param string $errline
* @return void
/**
* @param $errno
* @param $errstr
* @param $errfile
* @param $errline
*/
function handleErrors($errno, $errstr, $errfile, $errline)
{
if ($errno != 2048 && isset($_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'])) {
G::logTriggerExecution($_SESSION, $errstr, '', round(microtime(true) -
$_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'], 5));
}
if ($errno != '' && ($errno != 8) && ($errno != 2048)) {
if (isset( $_SESSION['_CODE_'] )) {
$sCode = $_SESSION['_CODE_'];
@@ -726,9 +747,13 @@ function handleErrors ($errno, $errstr, $errfile, $errline)
function handleFatalErrors ($buffer)
{
if (!empty($buffer)) {
G::logTriggerExecution($_SESSION, $buffer, 'FATAL_ERROR');
}
if (preg_match( '/(error<\/b>:)(.+)(<br)/', $buffer, $regs )) {
G::LoadClass( 'case' );
$oCase = new Cases();
if (preg_match( '/(error<\/b>:)(.+)(<br)/', $buffer, $regs )) {
$err = preg_replace( '/<.*?>/', '', $regs[2] );
$aAux = explode( ' in ', $err );
$sCode = isset($_SESSION['_CODE_']) ? $_SESSION['_CODE_'] : null;

View File

@@ -2614,9 +2614,6 @@ class wsBase
$oPMScript->setScript( $row['TRI_WEBBOT'] );
$oPMScript->execute();
//Log
Bootstrap::registerMonolog('triggerExecutionTime', 200, 'Trigger execution time', ['proUid' => $appFields['APP_DATA']['PROCESS'], 'tasUid' => $appFields['APP_DATA']['TASK'], 'appUid' => $appFields['APP_DATA']['APPLICATION'], 'triggerInfo' => ['triUid' => $row['TRI_UID'], 'triExecutionTime' => $oPMScript->scriptExecutionTime]], SYS_SYS, 'processmaker.log');
if (isset($oPMScript->aFields["__ERROR__"]) && trim($oPMScript->aFields["__ERROR__"]) != "" && $oPMScript->aFields["__ERROR__"] != "none") {
throw new Exception($oPMScript->aFields["__ERROR__"]);
}

View File

@@ -103,14 +103,6 @@ try {
$_SESSION['TRIGGER_DEBUG']['info'][0]['TRIGGERS_NAMES'] = array_column($triggers, 'TRI_TITLE');
$_SESSION['TRIGGER_DEBUG']['info'][0]['TRIGGERS_VALUES'] = $triggers;
$_SESSION['TRIGGER_DEBUG']['info'][0]['TRIGGERS_EXECUTION_TIME'] = $oCase->arrayTriggerExecutionTime;
$arrayInfoTriggerExecutionTime = [];
foreach ($_SESSION['TRIGGER_DEBUG']['info'][0]['TRIGGERS_EXECUTION_TIME'] as $key => $value) {
$arrayInfoTriggerExecutionTime[] = ['triUid' => $key, 'triExecutionTime' => $value];
}
//Log
Bootstrap::registerMonolog('triggerExecutionTime', 200, 'Trigger execution time', ['proUid' => $appFields['APP_DATA']['PROCESS'], 'tasUid' => $appFields['APP_DATA']['TASK'], 'appUid' => $appFields['APP_DATA']['APPLICATION'], 'before' => 'ASSIGN_TASK', 'triggerInfo' => $arrayInfoTriggerExecutionTime], SYS_SYS, 'processmaker.log');
}
unset($appFields['APP_STATUS']);
@@ -174,14 +166,6 @@ try {
$_SESSION['TRIGGER_DEBUG']['info'][1]['TRIGGERS_NAMES'] = array_column($triggers, 'TRI_TITLE');
$_SESSION['TRIGGER_DEBUG']['info'][1]['TRIGGERS_VALUES'] = $triggers;
$_SESSION['TRIGGER_DEBUG']['info'][1]['TRIGGERS_EXECUTION_TIME'] = $oCase->arrayTriggerExecutionTime;
$arrayInfoTriggerExecutionTimeAux = [];
foreach ($_SESSION['TRIGGER_DEBUG']['info'][1]['TRIGGERS_EXECUTION_TIME'] as $key => $value) {
$arrayInfoTriggerExecutionTimeAux[] = ['triUid' => $key, 'triExecutionTime' => $value];
}
//Log
Bootstrap::registerMonolog('triggerExecutionTime', 200, 'Trigger execution time', ['proUid' => $appFields['APP_DATA']['PROCESS'], 'tasUid' => $appFields['APP_DATA']['TASK'], 'appUid' => $appFields['APP_DATA']['APPLICATION'], 'after' => 'ASSIGN_TASK', 'triggerInfo' => $arrayInfoTriggerExecutionTimeAux], SYS_SYS, 'processmaker.log');
}
unset($appFields['APP_STATUS']);
unset($appFields['APP_PROC_STATUS']);

View File

@@ -183,14 +183,6 @@ try {
//Execute after triggers - End
$_SESSION['TRIGGER_DEBUG']['TRIGGERS_EXECUTION_TIME'] = $oCase->arrayTriggerExecutionTime;
$arrayInfoTriggerExecutionTime = [];
foreach ($_SESSION['TRIGGER_DEBUG']['TRIGGERS_EXECUTION_TIME'] as $key => $value) {
$arrayInfoTriggerExecutionTime[] = ['triUid' => $key, 'triExecutionTime' => $value];
}
//Log
Bootstrap::registerMonolog('triggerExecutionTime', 200, 'Trigger execution time', ['proUid' => $_SESSION['PROCESS'], 'tasUid' => $_SESSION['TASK'], 'appUid' => $_SESSION['APPLICATION'], 'after' => 'DYNAFORM', 'triggerInfo' => $arrayInfoTriggerExecutionTime], SYS_SYS, 'processmaker.log');
}
//save data in PM Tables if necessary

View File

@@ -219,16 +219,7 @@ if ($flagExecuteBeforeTriggers) {
//Execute before triggers - End
$_SESSION['TRIGGER_DEBUG']['TRIGGERS_EXECUTION_TIME'] = $oCase->arrayTriggerExecutionTime;
$arrayInfoTriggerExecutionTime = [];
foreach ($_SESSION['TRIGGER_DEBUG']['TRIGGERS_EXECUTION_TIME'] as $key => $value) {
$arrayInfoTriggerExecutionTime[] = ['triUid' => $key, 'triExecutionTime' => $value];
}
//Log
if(sizeof($arrayInfoTriggerExecutionTime)>0){
Bootstrap::registerMonolog('triggerExecutionTime', 200, 'Trigger execution time', ['proUid' => $Fields['APP_DATA']['PROCESS'], 'tasUid' => $Fields['APP_DATA']['TASK'], 'appUid' => $Fields['APP_DATA']['APPLICATION'], 'before' => $_GET['TYPE'], 'triggerInfo' => $arrayInfoTriggerExecutionTime], SYS_SYS, 'processmaker.log');
}
} else {
unset( $_SESSION['_NO_EXECUTE_TRIGGERS_'] );
}