#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]
This commit is contained in:
Romain Quetiez
2014-12-02 10:53:59 +00:00
parent 4dd83a0eb6
commit 8d8510a412
2 changed files with 31 additions and 29 deletions

View File

@@ -480,6 +480,14 @@ abstract class AttributeDefinition
return (string)$sValue; 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 = '') public function GetAllowedValues($aArgs = array(), $sContains = '')
{ {
$oValSetDef = $this->GetValuesDef(); $oValSetDef = $this->GetValuesDef();
@@ -487,15 +495,18 @@ abstract class AttributeDefinition
return $oValSetDef->GetValues($aArgs, $sContains); 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)) if (is_null($sLabel))
{ {
$sLabel = $this->GetLabel(); $sLabel = $this->GetLabel();
} }
$sNewValueHtml = $this->GetAsHTML($sNewValue); $sNewValueHtml = $this->GetAsHTMLForHistory($sNewValue);
$sOldValueHtml = $this->GetAsHTML($sOldValue); $sOldValueHtml = $this->GetAsHTMLForHistory($sOldValue);
if($this->IsExternalKey()) if($this->IsExternalKey())
{ {
@@ -3981,19 +3992,17 @@ class AttributeStopWatch extends AttributeDefinition
return Dict::S('BooleanLabel:'.$sDictKey, 'def:'.$sDictKey); return Dict::S('BooleanLabel:'.$sDictKey, 'def:'.$sDictKey);
} }
public function GetSubItemAsHTMLForHistory($sItemCode, $sOldValue, $sNewValue, $sLabel) public function GetSubItemAsHTMLForHistory($sItemCode, $sValue)
{ {
switch($sItemCode) switch($sItemCode)
{ {
case 'timespent': case 'timespent':
$sHtmlOld = (int)$sOldValue ? AttributeDuration::FormatDuration($sOldValue) : null; $sHtml = (int)$sValue ? Str::pure2html(AttributeDuration::FormatDuration($sValue)) : null;
$sHtmlNew = (int)$sNewValue ? AttributeDuration::FormatDuration($sNewValue) : null;
break; break;
case 'started': case 'started':
case 'laststart': case 'laststart':
case 'stopped': case 'stopped':
$sHtmlOld = (int)$sOldValue ? date(self::GetDateFormat(), (int)$sOldValue) : null; $sHtml = (int)$sValue ? date(self::GetDateFormat(), (int)$sValue) : null;
$sHtmlNew = (int)$sNewValue ? date(self::GetDateFormat(), (int)$sNewValue) : null;
break; break;
default: default:
@@ -4007,26 +4016,21 @@ class AttributeStopWatch extends AttributeDefinition
switch($sThresholdCode) switch($sThresholdCode)
{ {
case 'deadline': case 'deadline':
$sHtmlOld = (int)$sOldValue ? date(self::GetDateFormat(true /*full*/), (int)$sOldValue) : null; $sHtml = (int)$sValue ? date(self::GetDateFormat(true /*full*/), (int)$sValue) : null;
$sHtmlNew = (int)$sNewValue ? date(self::GetDateFormat(true /*full*/), (int)$sNewValue) : null;
break; break;
case 'passed': case 'passed':
$sHtmlOld = $this->GetBooleanLabel((int)$sOldValue); $sHtml = $this->GetBooleanLabel((int)$sValue);
$sHtmlNew = $this->GetBooleanLabel((int)$sNewValue);
break; break;
case 'triggered': case 'triggered':
$sHtmlOld = $this->GetBooleanLabel((int)$sOldValue); $sHtml = $this->GetBooleanLabel((int)$sValue);
$sHtmlNew = $this->GetBooleanLabel((int)$sNewValue);
break; break;
case 'overrun': case 'overrun':
$sHtmlOld = (int)$sOldValue > 0 ? AttributeDuration::FormatDuration((int)$sOldValue) : ''; $sHtml = (int)$sValue > 0 ? Str::pure2html(AttributeDuration::FormatDuration((int)$sValue)) : '';
$sHtmlNew = (int)$sNewValue > 0 ? AttributeDuration::FormatDuration((int)$sNewValue) : '';
} }
} }
} }
} }
$sRes = parent::GetAsHTMLForHistory($sHtmlOld, $sHtmlNew, $sLabel); return $sHtml;
return $sRes;
} }
static protected function GetDateFormat($bFull = false) static protected function GetDateFormat($bFull = false)
@@ -4341,6 +4345,13 @@ class AttributeSubItem extends AttributeDefinition
return $res; 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) public function GetAsCSV($value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true)
{ {
$oParent = $this->GetTargetAttDef(); $oParent = $this->GetTargetAttDef();
@@ -4355,15 +4366,6 @@ class AttributeSubItem extends AttributeDefinition
return $res; 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 * 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 // 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 ''; return '';
} }

View File

@@ -237,7 +237,7 @@ class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute
$sAttName = $oAttDef->GetLabel(); $sAttName = $oAttDef->GetLabel();
$sNewValue = $this->Get('newvalue'); $sNewValue = $this->Get('newvalue');
$sOldValue = $this->Get('oldvalue'); $sOldValue = $this->Get('oldvalue');
$sResult = $oAttDef->GetAsHTMLForHistory($sOldValue, $sNewValue); $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue);
} }
return $sResult; return $sResult;
} }