From 3c4845cf99ee02c91399d1f73b6efbbad015339e Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Wed, 4 May 2016 09:55:24 +0000 Subject: [PATCH] #1215: URL fields can now store up to 2048 characters SVN:trunk[4030] --- core/attributedef.class.inc.php | 9 +++++- core/bulkchange.class.inc.php | 2 +- core/cmdbchangeop.class.inc.php | 55 +++++++++++++++++++++++++++++++++ core/cmdbobject.class.inc.php | 12 +++++++ 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index a9400b392..5e818071e 100644 --- a/core/attributedef.class.inc.php +++ b/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); diff --git a/core/bulkchange.class.inc.php b/core/bulkchange.class.inc.php index 98d47b9ba..0e2fe52c9 100644 --- a/core/bulkchange.class.inc.php +++ b/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()) diff --git a/core/cmdbchangeop.class.inc.php b/core/cmdbchangeop.class.inc.php index 38b23eeb0..83170f2d1 100644 --- a/core/cmdbchangeop.class.inc.php +++ b/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 diff --git a/core/cmdbobject.class.inc.php b/core/cmdbobject.class.inc.php index 78aedbd72..557610fa2 100644 --- a/core/cmdbobject.class.inc.php +++ b/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