Merged in bugfix/PMCORE-546 (pull request #7249)
PMCORE-546 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -6075,6 +6075,7 @@ class G
|
||||
|
||||
/**
|
||||
* Add log of execution of triggers
|
||||
*
|
||||
* @param $data
|
||||
* @param string $error
|
||||
* @param string $typeError
|
||||
@@ -6082,24 +6083,22 @@ class G
|
||||
*/
|
||||
public static function logTriggerExecution($data, $error = 'NO-ERROR', $typeError = '', $executionTime = 0)
|
||||
{
|
||||
if ((!empty($data['_CODE_']) || $typeError == 'FATAL_ERROR') && isset($data['_DATA_TRIGGER_']) &&
|
||||
!isset($data['_DATA_TRIGGER_']['_TRI_LOG_'])
|
||||
) {
|
||||
if ((!empty($data['_CODE_']) || $typeError == 'FATAL_ERROR') && empty($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'] = $error;
|
||||
$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'] : '';
|
||||
$lg['triTitle'] = isset($data['_DATA_TRIGGER_']['TRI_TITLE']) ? $data['_DATA_TRIGGER_']['TRI_TITLE'] : '';
|
||||
$lg['triUid'] = isset($data['_DATA_TRIGGER_']['TRI_UID']) ? $data['_DATA_TRIGGER_']['TRI_UID'] : '';
|
||||
$lg['triCode'] = isset($data['_DATA_TRIGGER_']['TRI_WEBBOT']) ? $data['_DATA_TRIGGER_']['TRI_WEBBOT'] : '';
|
||||
$lg['triExecutionTime'] = $executionTime;
|
||||
$lg['triMessageError'] = $error;
|
||||
$lg['appUid'] = isset($data['APPLICATION']) ? $data['APPLICATION'] : '';
|
||||
$lg['proUid'] = isset($data['PROCESS']) ? $data['PROCESS'] : '';
|
||||
$lg['tasUid'] = isset($data['TASK']) ? $data['TASK'] : '';
|
||||
$lg['usrUid'] = isset($data['USER_LOGGED']) ? $data['USER_LOGGED'] : '';
|
||||
|
||||
Bootstrap::registerMonolog(
|
||||
(empty($sError)) ? 'TriggerExecution' : 'TriggerExecutionError',
|
||||
(empty($sError)) ? 200 : 400,
|
||||
(empty($sError)) ? 'Trigger Execution' : 'Trigger Execution Error',
|
||||
(empty($error)) ? 'TriggerExecution' : 'TriggerExecutionError',
|
||||
(empty($error)) ? 200 : 400,
|
||||
(empty($error)) ? 'Trigger Execution' : 'Trigger Execution Error',
|
||||
$lg,
|
||||
$lg['workspace'],
|
||||
'processmaker.log'
|
||||
|
||||
@@ -3,8 +3,12 @@
|
||||
namespace Tests\unit\gulliver\system;
|
||||
|
||||
use G;
|
||||
use MonologProvider;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \G
|
||||
*/
|
||||
class gTest extends TestCase
|
||||
{
|
||||
/**
|
||||
@@ -350,4 +354,27 @@ class gTest extends TestCase
|
||||
$this->assertContains($word, $res);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests if the errors related to the trigger execution was registered
|
||||
*
|
||||
* @covers ::logTriggerExecution
|
||||
* @test
|
||||
*/
|
||||
public function it_check_log_trigger_execution()
|
||||
{
|
||||
$data = [];
|
||||
$error = 'This is some error';
|
||||
$_SESSION['_DATA_TRIGGER_']['_TRI_LOG_'] = false;
|
||||
G::logTriggerExecution($data, $error, 'FATAL_ERROR', 60);
|
||||
$log = MonologProvider::getSingleton('TriggerExecutionError', 'processmaker.log', true);
|
||||
$this->assertNotEmpty($log->getPathFile());
|
||||
$this->assertTrue($_SESSION['_DATA_TRIGGER_']['_TRI_LOG_']);
|
||||
|
||||
$_SESSION['_DATA_TRIGGER_']['_TRI_LOG_'] = false;
|
||||
G::logTriggerExecution($data, '', '', 100);
|
||||
$log = MonologProvider::getSingleton('TriggerExecution', 'processmaker.log', true);
|
||||
$this->assertNotEmpty($log->getPathFile());
|
||||
$this->assertFalse($_SESSION['_DATA_TRIGGER_']['_TRI_LOG_']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user