New option DEL_MOVEUP (move the children up one level) for 'on_target_delete' for HierarchicalKey attributes.

SVN:trunk[1430]
This commit is contained in:
Denis Flaven
2011-08-07 12:24:45 +00:00
parent 435d943f47
commit 772c892b15
3 changed files with 23 additions and 6 deletions

View File

@@ -64,7 +64,14 @@ define('DEL_MANUAL', 1);
* @package iTopORM
*/
define('DEL_AUTO', 2);
/**
* Fully silent delete... not yet implemented
*/
define('DEL_SILENT', 2);
/**
* For HierarchicalKeys only: move all the children up one level automatically
*/
define('DEL_MOVEUP', 3);
/**

View File

@@ -1403,7 +1403,7 @@ abstract class DBObject
$iDelta =$iMyRight - $iMyLeft + 1;
MetaModel::HKTemporaryCutBranch($iMyLeft, $iMyRight, $oAttDef, $sTable);
// No new parent, insert completely at the right of the tree
// No new parent for now, insert completely at the right of the tree
$sSQL = "SELECT max(`".$oAttDef->GetSQLRight()."`) AS max FROM `$sTable`";
$aRes = CMDBSource::QueryToArray($sSQL);
if (count($aRes) == 0)
@@ -1464,7 +1464,7 @@ abstract class DBObject
$oToUpdate = $aData['to_reset'];
foreach ($aData['attributes'] as $sRemoteExtKey => $aRemoteAttDef)
{
$oToUpdate->Set($sRemoteExtKey, 0);
$oToUpdate->Set($sRemoteExtKey, $aData['values'][$sRemoteExtKey]);
$oToUpdate->DBUpdate();
}
}
@@ -1718,7 +1718,16 @@ abstract class DBObject
if ($oAttDef->IsNullAllowed())
{
// Optional external key, list to reset
$oDeletionPlan->AddToUpdate($oDependentObj, $oAttDef);
if (($iDeletePropagationOption == DEL_MOVEUP) && ($oAttDef->IsHierarchicalKey()))
{
// Move the child up one level i.e. set the same parent as the current object
$iParentId = $this->Get($oAttDef->GetCode());
$oDeletionPlan->AddToUpdate($oDependentObj, $oAttDef, $iParentId);
}
else
{
$oDeletionPlan->AddToUpdate($oDependentObj, $oAttDef);
}
}
else
{

View File

@@ -109,11 +109,11 @@ class DeletionPlan
{
$this->m_iToUpdate++;
$oObject = $aData['to_reset'];
$oObject = $aData['to_reset'];
$aExtKeyLabels = array();
foreach ($aData['attributes'] as $sRemoteExtKey => $aRemoteAttDef)
{
$oObject->Set($sRemoteExtKey, 0);
$oObject->Set($sRemoteExtKey, $aData['values'][$sRemoteExtKey]);
$aExtKeyLabels[] = $aRemoteAttDef->GetLabel();
}
$this->m_aToUpdate[$sClass][$iId]['attributes_list'] = implode(', ', $aExtKeyLabels);
@@ -264,7 +264,7 @@ class DeletionPlan
}
}
public function AddToUpdate($oObject, $oAttDef)
public function AddToUpdate($oObject, $oAttDef, $value = 0)
{
$sClass = get_class($oObject);
$iId = $oObject->GetKey();
@@ -281,6 +281,7 @@ class DeletionPlan
);
}
$this->m_aToUpdate[$sClass][$iId]['attributes'][$oAttDef->GetCode()] = $oAttDef;
$this->m_aToUpdate[$sClass][$iId]['values'][$oAttDef->GetCode()] = $value;
}
}
}