Kaynağa Gözat

Generalized the option tracking_level to any kind of attributes. Defaults to 'all', can be set to 'none' to disable the change tracking on a single attribute (LinkSets still have the same allowed values: none, list, details and all).

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2863 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 yıl önce
ebeveyn
işleme
d4d5f71dbc

+ 8 - 0
core/attributedef.class.inc.php

@@ -81,6 +81,8 @@ define('DEL_MOVEUP', 3);
  *
  * @package     iTopORM
  */
+define('ATTRIBUTE_TRACKING_NONE', 0); // Do not track changes of the attribute
+define('ATTRIBUTE_TRACKING_ALL', 3); // Do track all changes of the attribute
 define('LINKSET_TRACKING_NONE', 0); // Do not track changes in the link set
 define('LINKSET_TRACKING_LIST', 1); // Do track added/removed items
 define('LINKSET_TRACKING_DETAILS', 2); // Do track modified items
@@ -341,6 +343,12 @@ abstract class AttributeDefinition
 			return $this->GetDescription();
 		}
 	}
+
+	public function GetTrackingLevel()
+	{
+		return $this->GetOptional('tracking_level', ATTRIBUTE_TRACKING_ALL);
+	}
+
 	public function GetValuesDef() {return null;} 
 	public function GetPrerequisiteAttributes() {return array();} 
 

+ 3 - 2
core/cmdbobject.class.inc.php

@@ -189,8 +189,9 @@ abstract class CMDBObject extends DBObject
 		foreach ($aValues as $sAttCode=> $value)
 		{
 			$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
-			if ($oAttDef->IsExternalField()) continue; // #@# temporary
-			if ($oAttDef->IsLinkSet()) continue; // #@# temporary
+			if ($oAttDef->IsExternalField()) continue;
+			if ($oAttDef->IsLinkSet()) continue;
+			if ($oAttDef->GetTrackingLevel() == TRACKING_NONE) continue;
 
 			if (array_key_exists($sAttCode, $aOrigValues))
 			{

+ 25 - 14
setup/compiler.class.inc.php

@@ -381,18 +381,34 @@ EOF;
 	 * @param string $sTrackingLevel Value set from within the XML
 	 * Returns string PHP flag
 	 */ 
-	protected function TrackingLevelToPHP($sTrackingLevel)
+	protected function TrackingLevelToPHP($sAttType, $sTrackingLevel)
 	{
-		static $aXmlToPHP = array(
+		static $aXmlToPHP_Links = array(
 			'none' => 'LINKSET_TRACKING_NONE',
 			'list' => 'LINKSET_TRACKING_LIST',
 			'details' => 'LINKSET_TRACKING_DETAILS',
 			'all' => 'LINKSET_TRACKING_ALL',
 		);
 	
+		static $aXmlToPHP_Others = array(
+			'none' => 'ATTRIBUTE_TRACKING_NONE',
+			'all' => 'ATTRIBUTE_TRACKING_ALL',
+		);
+
+		switch ($sAttType)
+		{
+		case 'AttributeLinkedSetIndirect':
+		case 'AttributeLinkedSet':
+			$aXmlToPHP = $aXmlToPHP_Links;
+			break;
+
+		default:
+			$aXmlToPHP = $aXmlToPHP_Others;
+		}
+
 		if (!array_key_exists($sTrackingLevel, $aXmlToPHP))
 		{
-			throw new DOMFormatException("Tracking level: unknown value '$sTrackingLevel'");
+			throw new DOMFormatException("Tracking level: unknown value '$sTrackingLevel', expecting a value in {".implode(', ', array_keys($aXmlToPHP))."}");
 		}
 		return $aXmlToPHP[$sTrackingLevel];
 	}
@@ -413,7 +429,7 @@ EOF;
 	
 		if (!array_key_exists($sEditMode, $aXmlToPHP))
 		{
-			throw new DOMFormatException("Edit mode: unknown value '$sTrackingLevel'");
+			throw new DOMFormatException("Edit mode: unknown value '$sEditMode'");
 		}
 		return $aXmlToPHP[$sEditMode];
 	}
@@ -685,11 +701,6 @@ EOF;
 				$aParameters['count_min'] = $this->GetPropNumber($oField, 'count_min', 0);
 				$aParameters['count_max'] = $this->GetPropNumber($oField, 'count_max', 0);
 				$aParameters['duplicates'] = $this->GetPropBoolean($oField, 'duplicates', false);
-				$sTrackingLevel = $oField->GetChildText('tracking_level');
-				if (!is_null($sTrackingLevel))
-				{
-					$aParameters['tracking_level'] = $this->TrackingLevelToPHP($sTrackingLevel);
-				}
 				$aParameters['depends_on'] = $sDependencies;
 			}
 			elseif ($sAttType == 'AttributeLinkedSet')
@@ -699,11 +710,6 @@ EOF;
 				$aParameters['allowed_values'] = 'null';
 				$aParameters['count_min'] = $this->GetPropNumber($oField, 'count_min', 0);
 				$aParameters['count_max'] = $this->GetPropNumber($oField, 'count_max', 0);
-				$sTrackingLevel = $oField->GetChildText('tracking_level');
-				if (!is_null($sTrackingLevel))
-				{
-					$aParameters['tracking_level'] = $this->TrackingLevelToPHP($sTrackingLevel);
-				}
 				$sEditMode = $oField->GetChildText('edit_mode');
 				if (!is_null($sEditMode))
 				{
@@ -857,6 +863,11 @@ EOF;
 			$aParameters['height'] = $this->GetPropNumber($oField, 'height');
 			$aParameters['digits'] = $this->GetPropNumber($oField, 'digits');
 			$aParameters['decimals'] = $this->GetPropNumber($oField, 'decimals');
+			$sTrackingLevel = $oField->GetChildText('tracking_level');
+			if (!is_null($sTrackingLevel))
+			{
+				$aParameters['tracking_level'] = $this->TrackingLevelToPHP($sAttType, $sTrackingLevel);
+			}
 	
 			$aParams = array();
 			foreach($aParameters as $sKey => $sValue)