Pārlūkot izejas kodu

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

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1430 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 14 gadi atpakaļ
vecāks
revīzija
31e23c5282

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

+ 12 - 3
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
 					{

+ 4 - 3
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;
 		}
 	}
 }