From b7bd1a5943fb506ebfb74bb1df52d13c63486c9e Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Thu, 21 Apr 2011 09:04:34 +0000 Subject: [PATCH] Data synchro: if the object is deleted from within iTop, do cleanup sync table and replica as well SVN:trunk[1223] --- application/cmdbabstract.class.inc.php | 4 ++-- core/dbobject.class.php | 19 ++++++++++++------- synchro/synchrodatasource.class.inc.php | 17 ++++++++++++----- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 1b72fe87d..224369ed3 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -2292,9 +2292,9 @@ EOF } } - protected function DoCheckToDelete() + protected function DoCheckToDelete(&$oDeletionPlan) { - parent::DoCheckToDelete(); + parent::DoCheckToDelete($oDeletionPlan); // Plugins // diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 1e7d7c749..c9091119d 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -839,7 +839,7 @@ abstract class DBObject // check if it is allowed to delete the existing object from the database // a displayable error is returned - protected function DoCheckToDelete() + protected function DoCheckToDelete(&$oDeletionPlan) { $this->m_aDeleteIssues = array(); // Ok @@ -850,20 +850,25 @@ abstract class DBObject { while($aData = $oReplicaSet->FetchAssoc()) { - if ($aData['datasource']->GetKey() == SynchroDataSource::GetCurrentTaskId()) + $oDataSource = $aData['datasource']; + $oReplica = $aData['replica']; + + $oDeletionPlan->AddToDelete($oReplica, DEL_SILENT); + + if ($oDataSource->GetKey() == SynchroDataSource::GetCurrentTaskId()) { // The current task has the right to delete the object continue; } - if ($aData['replica']->Get('status_dest_creator') != 1) + if ($oReplica->Get('status_dest_creator') != 1) { // The object is not owned by the task continue; } - $sLink = $aData['datasource']->GetName(); - $sUserDeletePolicy = $aData['datasource']->Get('user_delete_policy'); + $sLink = $oDataSource->GetName(); + $sUserDeletePolicy = $oDataSource->Get('user_delete_policy'); switch($sUserDeletePolicy) { case 'nobody': @@ -1319,7 +1324,7 @@ abstract class DBObject CMDBSource::DeleteFrom($sDeleteSQL); } - private function DBDeleteSingleObject() + protected function DBDeleteSingleObject() { $this->OnDelete(); @@ -1609,7 +1614,7 @@ abstract class DBObject return; } // Check the node itself - $this->DoCheckToDelete(); + $this->DoCheckToDelete($oDeletionPlan); $oDeletionPlan->SetDeletionIssues($this, $this->m_aDeleteIssues, $this->m_bSecurityIssue); $aDependentObjects = $this->GetReferencingObjects(true /* allow all data */); diff --git a/synchro/synchrodatasource.class.inc.php b/synchro/synchrodatasource.class.inc.php index 4521bc1f2..abef5de7f 100644 --- a/synchro/synchrodatasource.class.inc.php +++ b/synchro/synchrodatasource.class.inc.php @@ -1300,13 +1300,20 @@ class SynchroReplica extends DBObject implements iDisplay // Overload the deletion -> the replica has been created by the mean of a trigger, // it will be deleted by the mean of a trigger too - public function DBDelete(&$oDeletionPlan = null) + protected function DBDeleteSingleObject() { - $oDataSource = MetaModel::GetObject('SynchroDataSource', $this->Get('sync_source_id')); - $sTable = $oDataSource->GetDataTable(); + $this->OnDelete(); - $sSQL = "DELETE FROM `$sTable` WHERE id = '{$this->GetKey()}'"; - CMDBSource::Query($sSQL); + if (!MetaModel::DBIsReadOnly()) + { + $oDataSource = MetaModel::GetObject('SynchroDataSource', $this->Get('sync_source_id')); + $sTable = $oDataSource->GetDataTable(); + + $sSQL = "DELETE FROM `$sTable` WHERE id = '{$this->GetKey()}'"; + CMDBSource::Query($sSQL); + } + + $this->AfterDelete(); $this->m_bIsInDB = false; $this->m_iKey = null;