소스 검색

#1215: URL fields can now store up to 2048 characters

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4030 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 9 년 전
부모
커밋
99816a3830
4개의 변경된 파일76개의 추가작업 그리고 2개의 파일을 삭제
  1. 8 1
      core/attributedef.class.inc.php
  2. 1 1
      core/bulkchange.class.inc.php
  3. 55 0
      core/cmdbchangeop.class.inc.php
  4. 12 0
      core/cmdbobject.class.inc.php

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

@@ -4698,6 +4698,13 @@ class AttributeURL extends AttributeString
 		return array_merge(parent::ListExpectedParams(), array("target"));
 	}
 
+	protected function GetSQLCol($bFullSpec = false) {return "VARCHAR(2048)".($bFullSpec ? $this->GetSQLColSpec() : '');}
+
+	public function GetMaxSize()
+	{
+		return 2048;
+	}
+	
 	public function GetEditClass() {return "String";}
 
 	public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
@@ -4705,7 +4712,7 @@ class AttributeURL extends AttributeString
 		$sTarget = $this->Get("target");
 		if (empty($sTarget)) $sTarget = "_blank";
 		$sLabel = Str::pure2html($sValue);
-		if (strlen($sLabel) > 255)
+		if (strlen($sLabel) > 128)
 		{
 			// Truncate the length to 128 characters, by removing the middle
 			$sLabel = substr($sLabel, 0, 100).'.....'.substr($sLabel, -20);

+ 1 - 1
core/bulkchange.class.inc.php

@@ -1201,7 +1201,7 @@ EOF
 			{
 				$sAttCode = $oOperation->Get('attcode');
 
-				if (get_class($oOperation) == 'CMDBChangeOpSetAttributeScalar')
+				if ((get_class($oOperation) == 'CMDBChangeOpSetAttributeScalar') || (get_class($oOperation) == 'CMDBChangeOpSetAttributeURL'))
 				{
 					$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
 					if ($oAttDef->IsExternalKey())

+ 55 - 0
core/cmdbchangeop.class.inc.php

@@ -242,6 +242,61 @@ class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute
 		return $sResult;
 	}
 }
+/**
+ * Record the modification of an URL 
+ *
+ * @package     iTopORM
+ */
+class CMDBChangeOpSetAttributeURL extends CMDBChangeOpSetAttribute
+{
+	public static function Init()
+	{
+		$aParams = array
+		(
+			"category" => "core/cmdb",
+			"key_type" => "",
+			"name_attcode" => "change",
+			"state_attcode" => "",
+			"reconc_keys" => array(),
+			"db_table" => "priv_changeop_setatt_url",
+			"db_key_field" => "id",
+			"db_finalclass_field" => "",
+		);
+		MetaModel::Init_Params($aParams);
+		MetaModel::Init_InheritAttributes();
+		MetaModel::Init_AddAttribute(new AttributeURL("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "target" => '_blank', "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
+		MetaModel::Init_AddAttribute(new AttributeURL("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "target" => '_blank', "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
+		
+		// Display lists
+		MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details
+		MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list
+	}
+	
+	/**
+	 * Describe (as a text string) the modifications corresponding to this change
+	 */	 
+	public function GetDescription()
+	{
+		$sResult = '';
+		$oTargetObjectClass = $this->Get('objclass');
+		$oTargetObjectKey = $this->Get('objkey');
+		$oTargetSearch = new DBObjectSearch($oTargetObjectClass);
+		$oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
+
+		$oMonoObjectSet = new DBObjectSet($oTargetSearch);
+		if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
+		{
+			if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
+
+			$oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
+			$sAttName = $oAttDef->GetLabel();
+			$sNewValue = $this->Get('newvalue');
+			$sOldValue = $this->Get('oldvalue');
+			$sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue);
+		}
+		return $sResult;
+	}
+}
 
 /**
  * Record the modification of a blob

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

@@ -407,6 +407,18 @@ abstract class CMDBObject extends DBObject
 				$oMyChangeOp->Set("prevdata", json_encode($original->GetValues()));
 				$iId = $oMyChangeOp->DBInsertNoReload();
 			}
+			elseif ($oAttDef instanceOf AttributeURL)
+			{
+				// URLs
+				//
+				$oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeURL");
+				$oMyChangeOp->Set("objclass", get_class($this));
+				$oMyChangeOp->Set("objkey", $this->GetKey());
+				$oMyChangeOp->Set("attcode", $sAttCode);
+				$oMyChangeOp->Set("oldvalue", $original);
+				$oMyChangeOp->Set("newvalue", $value);
+				$iId = $oMyChangeOp->DBInsertNoReload();
+			}
 			else
 			{
 				// Scalars