From 772c892b15ffcf52a93713143dc192615fc804cc Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Sun, 7 Aug 2011 12:24:45 +0000 Subject: [PATCH] New option DEL_MOVEUP (move the children up one level) for 'on_target_delete' for HierarchicalKey attributes. SVN:trunk[1430] --- core/attributedef.class.inc.php | 7 +++++++ core/dbobject.class.php | 15 ++++++++++++--- core/deletionplan.class.inc.php | 7 ++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index ea0f76c32..6734c024b 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -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); /** diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 3a06c2321..a7bda3684 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -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 { diff --git a/core/deletionplan.class.inc.php b/core/deletionplan.class.inc.php index 3064e5172..deb94d8fb 100644 --- a/core/deletionplan.class.inc.php +++ b/core/deletionplan.class.inc.php @@ -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; } } }