mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 01:58:47 +02:00
Data synchro: if the object is deleted from within iTop, do cleanup sync table and replica as well
SVN:trunk[1223]
This commit is contained in:
@@ -2292,9 +2292,9 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
protected function DoCheckToDelete()
|
||||
protected function DoCheckToDelete(&$oDeletionPlan)
|
||||
{
|
||||
parent::DoCheckToDelete();
|
||||
parent::DoCheckToDelete($oDeletionPlan);
|
||||
|
||||
// Plugins
|
||||
//
|
||||
|
||||
@@ -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 */);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user