瀏覽代碼

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

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4596 a333f486-631f-4898-b8df-5754b55c2be0
romainq 8 年之前
父節點
當前提交
5405f8c258
共有 3 個文件被更改,包括 39 次插入8 次删除
  1. 22 3
      core/attributedef.class.inc.php
  2. 7 2
      synchro/synchro_import.php
  3. 10 3
      synchro/synchrodatasource.class.inc.php

+ 22 - 3
core/attributedef.class.inc.php

@@ -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
 	 *

+ 7 - 2
synchro/synchro_import.php

@@ -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('/');

+ 10 - 3
synchro/synchrodatasource.class.inc.php

@@ -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;