N.701 Data Synchro: dates can be reset by the mean of an empty string (still, integers and enums cannot be reset)

SVN:trunk[4596]
This commit is contained in:
Romain Quetiez
2017-03-17 09:14:11 +00:00
parent 0b2ce4289d
commit e41a8833e2
3 changed files with 39 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
<?php
// Copyright (C) 2010-2016 Combodo SARL
// Copyright (C) 2010-2017 Combodo SARL
//
// This file is part of iTop.
//
@@ -20,7 +20,7 @@
/**
* Typology for the attributes
*
* @copyright Copyright (C) 2010-2016 Combodo SARL
* @copyright Copyright (C) 2010-2017 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
@@ -3725,6 +3725,15 @@ class AttributeDateTime extends AttributeDBField
}
protected function GetSQLCol($bFullSpec = false) {return "DATETIME";}
public function GetImportColumns()
{
// Allow an empty string to be a valid value (synonym for "reset")
$aColumns = array();
$aColumns[$this->GetCode()] = 'VARCHAR(19)';
return $aColumns;
}
public static function GetAsUnixSeconds($value)
{
$oDeadlineDateTime = new DateTime($value);
@@ -3837,6 +3846,8 @@ class AttributeDateTime extends AttributeDBField
elseif (empty($value))
{
// Make a valid date for MySQL. TO DO: support NULL as a literal value for fields that can be null.
// todo: this is NOT valid in strict mode (default setting for MySQL 5.7)
// todo: if to be kept, this should be overloaded for AttributeDate (0000-00-00)
return '0000-00-00 00:00:00';
}
return $value;
@@ -4119,7 +4130,15 @@ class AttributeDate extends AttributeDateTime
public function GetEditClass() {return "Date";}
protected function GetSQLCol($bFullSpec = false) {return "DATE";}
public function GetImportColumns()
{
// Allow an empty string to be a valid value (synonym for "reset")
$aColumns = array();
$aColumns[$this->GetCode()] = 'VARCHAR(10)';
return $aColumns;
}
/**
* Override to specify Field class
*

View File

@@ -1,5 +1,5 @@
<?php
// Copyright (C) 2011-2012 Combodo SARL
// Copyright (C) 2011-2017 Combodo SARL
//
// This file is part of iTop.
//
@@ -19,7 +19,7 @@
/**
* Data Exchange web service
*
* @copyright Copyright (C) 2010-2012 Combodo SARL
* @copyright Copyright (C) 2010-2017 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
@@ -216,6 +216,11 @@ function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter)
function ChangeDateFormat($sProposedDate, $sFormat)
{
if ($sProposedDate == '')
{
// An empty string means 'reset'
return '';
}
// Convert to a valid MySQL datetime
$oFormat = new DateTimeFormat($sFormat);
$sRegExpr = $oFormat->ToRegExpr('/');

View File

@@ -1,5 +1,5 @@
<?php
// Copyright (C) 2010-2015 Combodo SARL
// Copyright (C) 2010-2017 Combodo SARL
//
// This file is part of iTop.
//
@@ -20,7 +20,7 @@
/**
* Data Exchange - synchronization with external applications (incoming data)
*
* @copyright Copyright (C) 2010-2015 Combodo SARL
* @copyright Copyright (C) 2010-2017 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
@@ -2049,7 +2049,8 @@ class SynchroReplica extends DBObject implements iDisplay
/**
* Get the value from the 'Extended Data' located in the synchro_data_xxx table for this replica
* Note: sExtAttCode could be a standard attcode, or 'primary_key'
* Note: sExtAttCode could be a standard attcode, or 'primary_key'
* @return mixed, or null (leave unchanged), or '' (reset)
*/
protected function GetValueFromExtData($sExtAttCode, $oSyncAtt, &$oStatLog)
{
@@ -2125,7 +2126,13 @@ class SynchroReplica extends DBObject implements iDisplay
return null;
}
}
// No null column has been found
$retValue = $oAttDef->FromImportToValue($aData, $sExtAttCode);
if (is_null($retValue))
{
// This is a reset
$retValue = '';
}
}
return $retValue;