浏览代码

Fix for Trac #497: allow bulk modification of "duration" fields.
- Proper display of the modifications on the SynchroAttributes in the History of a SynchroDataSource
- Better display of the history of Boolean atrtibutes (false is no longer displayed as an empty string)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2478 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 12 年之前
父节点
当前提交
7b776554c1

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

@@ -1263,6 +1263,10 @@ class AttributeBoolean extends AttributeInteger
 	{
 		return $sValue ? '1' : '0';
 	}
+	public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
+	{
+		return $sValue ? '1' : '0';
+	}
 }
 
 /**

+ 14 - 1
core/cmdbchangeop.class.inc.php

@@ -735,13 +735,26 @@ class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks
 			$sAttName = $oAttDef->GetLabel();
 
 			$sLinkClass = $oAttDef->GetLinkedClass();
+			$aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL);
 
 			// Search for changes on the corresponding link
 			//
 			$oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute');
 			$oSearch->AddCondition('change', $this->Get('change'), '=');
-			$oSearch->AddCondition('objclass', $sLinkClass, '=');
 			$oSearch->AddCondition('objkey', $this->Get('link_id'), '=');
+			if (count($aLinkClasses) == 1)
+			{
+				// Faster than the whole building of the expression below for just one value ??
+				$oSearch->AddCondition('objclass', $sLinkClass, '=');
+			}
+			else
+			{
+				$oField = new FieldExpression('objclass',  $oSearch->GetClassAlias());
+				$sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')';
+				$sOQLCondition = $oField->Render()." IN $sListExpr";
+				$oNewCondition = Expression::FromOQL($sOQLCondition);
+				$oSearch->AddConditionExpression($oNewCondition);
+			}
 			$oSet = new DBObjectSet($oSearch);
 			$aChanges = array();
 			while ($oChangeOp = $oSet->Fetch())

+ 10 - 0
core/cmdbobject.class.inc.php

@@ -297,6 +297,16 @@ abstract class CMDBObject extends DBObject
 				$oMyChangeOp->Set("prevdata", $original);
 				$iId = $oMyChangeOp->DBInsertNoReload();
 			}
+			elseif ($oAttDef instanceOf AttributeBoolean)
+			{
+				$oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeScalar");
+				$oMyChangeOp->Set("objclass", get_class($this));
+				$oMyChangeOp->Set("objkey", $this->GetKey());
+				$oMyChangeOp->Set("attcode", $sAttCode);
+				$oMyChangeOp->Set("oldvalue", $original ? 1 : 0);
+				$oMyChangeOp->Set("newvalue", $value ? 1 : 0);
+				$iId = $oMyChangeOp->DBInsertNoReload();
+			}
 			else
 			{
 				// Scalars

+ 1 - 1
core/metamodel.class.php

@@ -896,7 +896,7 @@ abstract class MetaModel
 				foreach (MetaModel::ListAttributeDefs($sRemoteClass) as $sRemoteAttCode => $oRemoteAttDef)
 				{
 					if (!$oRemoteAttDef->IsLinkSet()) continue;
-					if ($oRemoteAttDef->GetLinkedClass() != $sClass) continue;
+					if (!is_subclass_of($sClass, $oRemoteAttDef->GetLinkedClass()) && $oRemoteAttDef->GetLinkedClass() != $sClass) continue;
 					if ($oRemoteAttDef->GetExtKeyToMe() != $sAttCode) continue;
 					$aRes[$sAttCode] = $oRemoteAttDef;
 				}

+ 12 - 1
pages/UI.php

@@ -1063,7 +1063,18 @@ EOF
 			{
 				if (preg_match('/attr_(.+)/', $sKey, $aMatches))
 				{
-					$oP->add("<input type=\"hidden\" name=\"$sKey\" value=\"$value\">\n");
+					// Beware: some values (like durations) are passed as arrays
+					if (is_array($value))
+					{
+						foreach($value as $vKey => $vValue)
+						{
+							$oP->add("<input type=\"hidden\" name=\"{$sKey}[$vKey]\" value=\"$vValue\">\n");
+						}
+					}
+					else
+					{
+						$oP->add("<input type=\"hidden\" name=\"$sKey\" value=\"$value\">\n");
+					}
 				}
 			}
 			$oP->add("</form>\n");

+ 4 - 4
synchro/synchrodatasource.class.inc.php

@@ -76,7 +76,7 @@ class SynchroDataSource extends cmdbAbstractObject
 		// Format: seconds (unsigned int)
 		MetaModel::Init_AddAttribute(new AttributeDuration("delete_policy_retention", array("allowed_values"=>null, "sql"=>"delete_policy_retention", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
 
-		MetaModel::Init_AddAttribute(new AttributeLinkedSet("attribute_list", array("linked_class"=>"SynchroAttribute", "ext_key_to_me"=>"sync_source_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
+		MetaModel::Init_AddAttribute(new AttributeLinkedSet("attribute_list", array("linked_class"=>"SynchroAttribute", "ext_key_to_me"=>"sync_source_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array(), 'tracking_level' => LINKSET_TRACKING_DETAILS)));
 		// Not used yet !
 		MetaModel::Init_AddAttribute(new AttributeEnum("user_delete_policy", array("allowed_values"=>new ValueSetEnum('everybody,administrators,nobody'), "sql"=>"user_delete_policy", "default_value"=>"nobody", "is_null_allowed"=>true, "depends_on"=>array())));
 
@@ -1171,7 +1171,7 @@ class SynchroAttribute extends cmdbAbstractObject
 		(
 			"category" => "core/cmdb,view_in_gui",
 			"key_type" => "autoincrement",
-			"name_attcode" => "",
+			"name_attcode" => "attcode",
 			"state_attcode" => "",
 			"reconc_keys" => array(),
 			"db_table" => "priv_sync_att",
@@ -1205,7 +1205,7 @@ class SynchroAttExtKey extends SynchroAttribute
 		(
 			"category" => "core/cmdb,view_in_gui",
 			"key_type" => "autoincrement",
-			"name_attcode" => "",
+			"name_attcode" => "attcode",
 			"state_attcode" => "",
 			"reconc_keys" => array(),
 			"db_table" => "priv_sync_att_extkey",
@@ -1253,7 +1253,7 @@ class SynchroAttLinkSet extends SynchroAttribute
 		(
 			"category" => "core/cmdb,view_in_gui",
 			"key_type" => "autoincrement",
-			"name_attcode" => "",
+			"name_attcode" => "attcode",
 			"state_attcode" => "",
 			"reconc_keys" => array(),
 			"db_table" => "priv_sync_att_linkset",