From 8d8510a412e2465ab5e0e521105f7c7b064ecba2 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Tue, 2 Dec 2014 10:53:59 +0000 Subject: [PATCH] #1030 Missing values in the history tab (TTO/TTR) The regression has been introduced in iTop 2.0.2 with the fix for #703 (escape HTML entities). There is no data loss: changes were correctly made and all the changes already recorded will be correctly displayed with the current fix. The current change consists in a little rework: GetAsHTMLForHistory has been renamed DescribeChange, and it now calls oAttDef->GetAsHTMLForHistory instead of calling oAttDef->GetAsHTML, thus allowing for the factorization of the code that format the change description. AttributeSubitem does not overload DescribeChange. Rather, it simply overloads GetAsHTMLForHistory (viewing the diff may be confusing here). SVN:trunk[3443] --- core/attributedef.class.inc.php | 58 +++++++++++++++++---------------- core/cmdbchangeop.class.inc.php | 2 +- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 6d23aeb2e..dbedb1c41 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -480,6 +480,14 @@ abstract class AttributeDefinition return (string)$sValue; } + /** + * Override to differentiate a value displayed in the UI or in the history + */ + public function GetAsHTMLForHistory($sValue, $oHostObject = null, $bLocalize = true) + { + return $this->GetAsHTML($sValue, $oHostObject, $bLocalize); + } + public function GetAllowedValues($aArgs = array(), $sContains = '') { $oValSetDef = $this->GetValuesDef(); @@ -487,15 +495,18 @@ abstract class AttributeDefinition return $oValSetDef->GetValues($aArgs, $sContains); } - public function GetAsHTMLForHistory($sOldValue, $sNewValue, $sLabel = null) + /** + * Explain the change of the attribute (history) + */ + public function DescribeChangeAsHTML($sOldValue, $sNewValue, $sLabel = null) { if (is_null($sLabel)) { $sLabel = $this->GetLabel(); } - $sNewValueHtml = $this->GetAsHTML($sNewValue); - $sOldValueHtml = $this->GetAsHTML($sOldValue); + $sNewValueHtml = $this->GetAsHTMLForHistory($sNewValue); + $sOldValueHtml = $this->GetAsHTMLForHistory($sOldValue); if($this->IsExternalKey()) { @@ -3981,19 +3992,17 @@ class AttributeStopWatch extends AttributeDefinition return Dict::S('BooleanLabel:'.$sDictKey, 'def:'.$sDictKey); } - public function GetSubItemAsHTMLForHistory($sItemCode, $sOldValue, $sNewValue, $sLabel) + public function GetSubItemAsHTMLForHistory($sItemCode, $sValue) { switch($sItemCode) { case 'timespent': - $sHtmlOld = (int)$sOldValue ? AttributeDuration::FormatDuration($sOldValue) : null; - $sHtmlNew = (int)$sNewValue ? AttributeDuration::FormatDuration($sNewValue) : null; + $sHtml = (int)$sValue ? Str::pure2html(AttributeDuration::FormatDuration($sValue)) : null; break; case 'started': case 'laststart': case 'stopped': - $sHtmlOld = (int)$sOldValue ? date(self::GetDateFormat(), (int)$sOldValue) : null; - $sHtmlNew = (int)$sNewValue ? date(self::GetDateFormat(), (int)$sNewValue) : null; + $sHtml = (int)$sValue ? date(self::GetDateFormat(), (int)$sValue) : null; break; default: @@ -4007,26 +4016,21 @@ class AttributeStopWatch extends AttributeDefinition switch($sThresholdCode) { case 'deadline': - $sHtmlOld = (int)$sOldValue ? date(self::GetDateFormat(true /*full*/), (int)$sOldValue) : null; - $sHtmlNew = (int)$sNewValue ? date(self::GetDateFormat(true /*full*/), (int)$sNewValue) : null; + $sHtml = (int)$sValue ? date(self::GetDateFormat(true /*full*/), (int)$sValue) : null; break; case 'passed': - $sHtmlOld = $this->GetBooleanLabel((int)$sOldValue); - $sHtmlNew = $this->GetBooleanLabel((int)$sNewValue); + $sHtml = $this->GetBooleanLabel((int)$sValue); break; case 'triggered': - $sHtmlOld = $this->GetBooleanLabel((int)$sOldValue); - $sHtmlNew = $this->GetBooleanLabel((int)$sNewValue); + $sHtml = $this->GetBooleanLabel((int)$sValue); break; case 'overrun': - $sHtmlOld = (int)$sOldValue > 0 ? AttributeDuration::FormatDuration((int)$sOldValue) : ''; - $sHtmlNew = (int)$sNewValue > 0 ? AttributeDuration::FormatDuration((int)$sNewValue) : ''; + $sHtml = (int)$sValue > 0 ? Str::pure2html(AttributeDuration::FormatDuration((int)$sValue)) : ''; } } } } - $sRes = parent::GetAsHTMLForHistory($sHtmlOld, $sHtmlNew, $sLabel); - return $sRes; + return $sHtml; } static protected function GetDateFormat($bFull = false) @@ -4341,6 +4345,13 @@ class AttributeSubItem extends AttributeDefinition return $res; } + public function GetAsHTMLForHistory($value, $oHostObject = null, $bLocalize = true) + { + $oParent = $this->GetTargetAttDef(); + $res = $oParent->GetSubItemAsHTMLForHistory($this->Get('item_code'), $value); + return $res; + } + public function GetAsCSV($value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true) { $oParent = $this->GetTargetAttDef(); @@ -4355,15 +4366,6 @@ class AttributeSubItem extends AttributeDefinition return $res; } - public function GetAsHTMLForHistory($sOldValue, $sNewValue, $sLabel = null) - { - $sLabel = $this->GetLabel(); - - $oParent = $this->GetTargetAttDef(); - $sValue = $oParent->GetSubItemAsHTMLForHistory($this->Get('item_code'), $sOldValue, $sNewValue, $sLabel); - return $sValue; - } - /** * As of now, this function must be implemented to have the value in spreadsheet format */ @@ -4923,7 +4925,7 @@ class AttributeFriendlyName extends AttributeComputedFieldVoid } // Do not display friendly names in the history of change - public function GetAsHTMLForHistory($sOldValue, $sNewValue, $sLabel = null) + public function DescribeChangeAsHTML($sOldValue, $sNewValue, $sLabel = null) { return ''; } diff --git a/core/cmdbchangeop.class.inc.php b/core/cmdbchangeop.class.inc.php index de8306080..898429082 100644 --- a/core/cmdbchangeop.class.inc.php +++ b/core/cmdbchangeop.class.inc.php @@ -237,7 +237,7 @@ class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute $sAttName = $oAttDef->GetLabel(); $sNewValue = $this->Get('newvalue'); $sOldValue = $this->Get('oldvalue'); - $sResult = $oAttDef->GetAsHTMLForHistory($sOldValue, $sNewValue); + $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue); } return $sResult; }