From 86df9ac0353e23737d6b884cae243b8efba562d6 Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Tue, 2 Jul 2024 10:37:36 +0200 Subject: [PATCH 1/2] =?UTF-8?q?N=C2=B07619=20-=20Object=20deletion=20not?= =?UTF-8?q?=20cascaded=20to=20legacy=20extensions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/cmdbabstract.class.inc.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 5ac7365c0..d5d4cf99a 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -4583,6 +4583,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'); @@ -4664,7 +4666,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(); } @@ -4678,6 +4695,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'); @@ -4699,6 +4718,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'); @@ -4758,6 +4778,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'); @@ -4808,6 +4830,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'); From 5fd8678a3ae84638cc948392e1a2f4bb5b74df1e Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Tue, 2 Jul 2024 10:38:25 +0200 Subject: [PATCH 2/2] =?UTF-8?q?N=C2=B07619=20-=20Object=20deletion=20not?= =?UTF-8?q?=20cascaded=20to=20legacy=20extensions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/dbobject.class.php | 81 ++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 0b78c5605..5047c6547 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -766,6 +766,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 @@ -4090,16 +4126,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__); @@ -4110,29 +4147,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