diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 59049c7c2..1a1fc51f3 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -2925,13 +2925,14 @@ abstract class DBObject implements iDisplay $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); } } @@ -3396,6 +3397,7 @@ abstract class DBObject implements iDisplay $oTrigger->DoActivate($this->ToArgs('this')); } catch (Exception $e) { + $oTrigger->LogException($e, $this); utils::EnrichRaisedException($oTrigger, $e); } } @@ -3575,13 +3577,13 @@ abstract class DBObject implements iDisplay $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); } } @@ -3970,6 +3972,7 @@ abstract class DBObject implements iDisplay $oTrigger->DoActivate($this->ToArgs('this')); } catch (Exception $e) { + $oTrigger->LogException($e, $this); utils::EnrichRaisedException($oTrigger, $e); } } @@ -3981,6 +3984,7 @@ abstract class DBObject implements iDisplay $oTrigger->DoActivate($this->ToArgs('this')); } catch (Exception $e) { + $oTrigger->LogException($e, $this); utils::EnrichRaisedException($oTrigger, $e); } } diff --git a/core/trigger.class.inc.php b/core/trigger.class.inc.php index a01981210..303aacf8d 100644 --- a/core/trigger.class.inc.php +++ b/core/trigger.class.inc.php @@ -250,21 +250,48 @@ abstract class TriggerOnObject extends Trigger 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); + } } /**