فهرست منبع

Data synchro: if the object is deleted from within iTop, do cleanup sync table and replica as well

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1223 a333f486-631f-4898-b8df-5754b55c2be0
romainq 14 سال پیش
والد
کامیت
b8518f8963
3فایلهای تغییر یافته به همراه26 افزوده شده و 14 حذف شده
  1. 2 2
      application/cmdbabstract.class.inc.php
  2. 12 7
      core/dbobject.class.php
  3. 12 5
      synchro/synchrodatasource.class.inc.php

+ 2 - 2
application/cmdbabstract.class.inc.php

@@ -2292,9 +2292,9 @@ EOF
 		}
 	}
 
-	protected function DoCheckToDelete()
+	protected function DoCheckToDelete(&$oDeletionPlan)
 	{
-		parent::DoCheckToDelete();
+		parent::DoCheckToDelete($oDeletionPlan);
 
 		// Plugins
 		//

+ 12 - 7
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 */);

+ 12 - 5
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;