Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/support/3.0' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/dbobject.class.php
#	core/trigger.class.inc.php
  • Loading branch information
Molkobain committed Feb 28, 2023
2 parents ba21687 + 143410f commit a048373
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
12 changes: 8 additions & 4 deletions core/dbobject.class.php
Expand Up @@ -3094,11 +3094,12 @@ public function DBInsertNoReload()
$aParams = array('class_list' => MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL));
$oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT TriggerOnObjectCreate AS t WHERE t.target_class IN (:class_list)'), array(), $aParams);
while ($oTrigger = $oSet->Fetch()) {
/** @var \Trigger $oTrigger */
/** @var \TriggerOnObjectCreate $oTrigger */
try {
$oTrigger->DoActivate($this->ToArgs('this'));
}
catch (Exception $e) {
$oTrigger->LogException($e, $this);
utils::EnrichRaisedException($oTrigger, $e);
}
}
Expand Down Expand Up @@ -3396,6 +3397,7 @@ public function DBUpdate()
$oTrigger->DoActivate($this->ToArgs());
}
catch (Exception $e) {
$oTrigger->LogException($e, $this);
utils::EnrichRaisedException($oTrigger, $e);
}
}
Expand Down Expand Up @@ -3634,13 +3636,13 @@ protected function DBDeleteSingleObject()
$aParams);
while ($oTrigger = $oSet->Fetch())
{
/** @var \Trigger $oTrigger */
/** @var \TriggerOnObjectDelete $oTrigger */
try
{
$oTrigger->DoActivate($this->ToArgs('this'));
}
catch(Exception $e)
{
catch(Exception $e) {
$oTrigger->LogException($e, $this);
utils::EnrichRaisedException($oTrigger, $e);
}
}
Expand Down Expand Up @@ -4046,6 +4048,7 @@ public function ApplyStimulus($sStimulusCode, $bDoNotWrite = false)
$oTrigger->DoActivate($this->ToArgs('this'));
}
catch (Exception $e) {
$oTrigger->LogException($e, $this);
utils::EnrichRaisedException($oTrigger, $e);
}
}
Expand All @@ -4057,6 +4060,7 @@ public function ApplyStimulus($sStimulusCode, $bDoNotWrite = false)
$oTrigger->DoActivate($this->ToArgs('this'));
}
catch (Exception $e) {
$oTrigger->LogException($e, $this);
utils::EnrichRaisedException($oTrigger, $e);
}
}
Expand Down
37 changes: 32 additions & 5 deletions core/trigger.class.inc.php
Expand Up @@ -252,21 +252,48 @@ public function DoActivate($aContextArgs)
public function IsTargetObject($iObjectId, $aChanges = array())
{
$sFilter = trim($this->Get('filter') ?? '');
if (strlen($sFilter) > 0)
{
if (strlen($sFilter) > 0) {
$oSearch = DBObjectSearch::FromOQL($sFilter);
$oSearch->AddCondition('id', $iObjectId, '=');
$oSearch->AllowAllData();
$oSet = new DBObjectSet($oSearch);
$bRet = ($oSet->Count() > 0);
}
else
{
} else {
$bRet = true;
}

return $bRet;
}

/**
* @param Exception $oException
* @param \DBObject $oObject
*
* @return void
*
* @uses \IssueLog::Error()
*
* @since 2.7.9 3.0.3 3.1.0 N°5893
*/
public function LogException($oException, $oObject)
{
$sObjectKey = $oObject->GetKey(); // if object wasn't persisted yet, then we'll have a negative value

$aContext = [
'exception.class' => get_class($oException),
'exception.message' => $oException->getMessage(),
'trigger.class' => get_class($this),
'trigger.id' => $this->GetKey(),
'trigger.friendlyname' => $this->GetRawName(),
'object.class' => get_class($oObject),
'object.id' => $sObjectKey,
'object.friendlyname' => $oObject->GetRawName(),
'current_user' => UserRights::GetUser(),
'exception.stack' => $oException->getTraceAsString(),
];

IssueLog::Error('A trigger did throw an exception', null, $aContext);
}
}

/**
Expand Down

0 comments on commit a048373

Please sign in to comment.