diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index e00bdb97a..733c42255 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -4570,6 +4570,8 @@ HTML; /** @var \iApplicationObjectExtension $oExtensionInstance */ foreach(MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance) { + $sExtensionClass = get_class($oExtensionInstance); + $this->LogCRUDDebug(__METHOD__, "Calling $sExtensionClass::OnDBInsert()"); $oKPI = new ExecutionKPI(); $oExtensionInstance->OnDBInsert($oNewObj, self::GetCurrentChange()); $oKPI->ComputeStatsForExtension($oExtensionInstance, 'OnDBInsert'); @@ -4651,7 +4653,22 @@ HTML; return $oDeletionPlan; } - protected function PostDeleteActions(): void + final protected function PreDeleteActions(): void + { + /** @var \iApplicationObjectExtension $oExtensionInstance */ + foreach(MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance) + { + $sExtensionClass = get_class($oExtensionInstance); + $this->LogCRUDDebug(__METHOD__, "Calling $sExtensionClass::OnDBDelete()"); + $oKPI = new ExecutionKPI(); + $oExtensionInstance->OnDBDelete($this, self::GetCurrentChange()); + $oKPI->ComputeStatsForExtension($oExtensionInstance, 'OnDBDelete'); + } + + parent::PreDeleteActions(); + } + + final protected function PostDeleteActions(): void { parent::PostDeleteActions(); } @@ -4665,6 +4682,8 @@ HTML; /** @var \iApplicationObjectExtension $oExtensionInstance */ foreach(MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance) { + $sExtensionClass = get_class($oExtensionInstance); + $this->LogCRUDDebug(__METHOD__, "Calling $sExtensionClass::OnDBDelete()"); $oKPI = new ExecutionKPI(); $oExtensionInstance->OnDBDelete($this, self::GetCurrentChange()); $oKPI->ComputeStatsForExtension($oExtensionInstance, 'OnDBDelete'); @@ -4686,6 +4705,7 @@ HTML; foreach(MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance) { $sExtensionClass = get_class($oExtensionInstance); + $this->LogCRUDDebug(__METHOD__, "Calling $sExtensionClass::OnIsModified()"); $oKPI = new ExecutionKPI(); $bIsModified = $oExtensionInstance->OnIsModified($this); $oKPI->ComputeStatsForExtension($oExtensionInstance, 'OnIsModified'); @@ -4745,6 +4765,8 @@ HTML; /** @var \iApplicationObjectExtension $oExtensionInstance */ foreach(MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance) { + $sExtensionClass = get_class($oExtensionInstance); + $this->LogCRUDDebug(__METHOD__, "Calling $sExtensionClass::OnCheckToWrite()"); $oKPI = new ExecutionKPI(); $aNewIssues = $oExtensionInstance->OnCheckToWrite($this); $oKPI->ComputeStatsForExtension($oExtensionInstance, 'OnCheckToWrite'); @@ -4795,6 +4817,8 @@ HTML; /** @var \iApplicationObjectExtension $oExtensionInstance */ foreach(MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance) { + $sExtensionClass = get_class($oExtensionInstance); + $this->LogCRUDDebug(__METHOD__, "Calling $sExtensionClass::OnCheckToDelete()"); $oKPI = new ExecutionKPI(); $aNewIssues = $oExtensionInstance->OnCheckToDelete($this); $oKPI->ComputeStatsForExtension($oExtensionInstance, 'OnCheckToDelete'); diff --git a/core/dbobject.class.php b/core/dbobject.class.php index d4ad0fedf..4f63633e2 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -768,6 +768,42 @@ abstract class DBObject implements iDisplay $this->Set($sAttCode, $sValue); } + /** + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MySQLException + * @throws \OQLException + * @throws \ReflectionException + */ + protected function PreDeleteActions(): void + { + $this->SetReadOnly('No modification allowed before delete'); + $this->FireEventAboutToDelete(); + $oKPI = new ExecutionKPI(); + $this->OnDelete(); + $oKPI->ComputeStatsForExtension($this, 'OnDelete'); + + // Activate any existing trigger + $sClass = get_class($this); + $aParams = array('class_list' => MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL)); + $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT TriggerOnObjectDelete AS t WHERE t.target_class IN (:class_list)'), array(), + $aParams); + while ($oTrigger = $oSet->Fetch()) { + /** @var \TriggerOnObjectDelete $oTrigger */ + try { + $oKPI = new ExecutionKPI(); + $oTrigger->DoActivate($this->ToArgs('this')); + } + catch (Exception $e) { + $oTrigger->LogException($e, $this); + utils::EnrichRaisedException($oTrigger, $e); + } + finally { + $oKPI->ComputeStatsForExtension($this, 'TriggerOnObjectDelete'); + } + } + } + /** * @return void * @throws \ReflectionException @@ -4092,16 +4128,17 @@ abstract class DBObject implements iDisplay CMDBSource::DeleteFrom($sDeleteSQL); } - /** - * @internal - * - * @throws ArchivedObjectException - * @throws CoreException - * @throws CoreUnexpectedValue - * @throws MySQLException - * @throws MySQLHasGoneAwayException - * @throws OQLException - */ + /** + * @internal + * + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + * @throws \OQLException + * @throws \Random\RandomException + * @throws \ReflectionException + */ protected function DBDeleteSingleObject() { $this->LogCRUDEnter(__METHOD__); @@ -4112,29 +4149,7 @@ abstract class DBObject implements iDisplay return; } - $this->SetReadOnly("No modification allowed before delete"); - $this->FireEventAboutToDelete(); - $oKPI = new ExecutionKPI(); - $this->OnDelete(); - $oKPI->ComputeStatsForExtension($this, 'OnDelete'); - - // Activate any existing trigger - $sClass = get_class($this); - $aParams = array('class_list' => MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL)); - $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObjectDelete AS t WHERE t.target_class IN (:class_list)"), array(), - $aParams); - while ($oTrigger = $oSet->Fetch()) - { - /** @var \TriggerOnObjectDelete $oTrigger */ - try - { - $oTrigger->DoActivate($this->ToArgs('this')); - } - catch(Exception $e) { - $oTrigger->LogException($e, $this); - utils::EnrichRaisedException($oTrigger, $e); - } - } + $this->PreDeleteActions(); $this->RecordObjDeletion($this->m_iKey); // May cause a reload for storing history information