From 399662ef99223b0ab4d21466b4db10eb0068e187 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Tue, 28 Mar 2017 14:56:52 +0000 Subject: [PATCH] N.701 (continuation of [r4596] which introduced regressions on the handling of date fields) SVN:trunk[4626] --- synchro/synchro_import.php | 34 +++++++++++++++++++------ synchro/synchrodatasource.class.inc.php | 2 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/synchro/synchro_import.php b/synchro/synchro_import.php index d4cedc680..8b242785d 100644 --- a/synchro/synchro_import.php +++ b/synchro/synchro_import.php @@ -214,7 +214,7 @@ function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter) return trim($sValue); } -function ChangeDateFormat($sProposedDate, $sFormat) +function ChangeDateFormat($sProposedDate, $sFormat, $bDateOnly) { if ($sProposedDate == '') { @@ -233,7 +233,8 @@ function ChangeDateFormat($sProposedDate, $sFormat) $oDate = $oFormat->Parse($sProposedDate); if ($oDate !== null) { - $sDate = $oDate->format(AttributeDateTime::GetInternalFormat()); + $oTargetFormat = $bDateOnly ? AttributeDate::GetInternalFormat() : AttributeDateTime::GetInternalFormat(); + $sDate = $oDate->format($oTargetFormat); return $sDate; } else @@ -444,7 +445,20 @@ try // Check columns $aColumns = $oDataSource->GetSQLColumns(); - $aDateColumns = $oDataSource->GetDateSQLColumns(); + + $aDateColumns = array(); + foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) + { + if ($oAttDef instanceof AttributeDate) + { + $aDateColumns[$sAttCode] = 'DATE'; + } + elseif ($oAttDef instanceof AttributeDateTime) + { + $aDateColumns[$sAttCode] = 'DATETIME'; + } + } + $aIsDateToTransform = array(); $aDateToTransformReport = array(); foreach($aInputColumns as $iFieldId => $sInputColumn) @@ -530,12 +544,14 @@ try } elseif ($aIsDateToTransform[$iCol] !== false) { + $bDateOnly = false; $sFormat = $sDateTimeFormat; if ($aIsDateToTransform[$iCol] == 'DATE') { + $bDateOnly = true; $sFormat = $sDateFormat; } - $sDate = ChangeDateFormat($value, $sFormat); + $sDate = ChangeDateFormat($value, $sFormat, $bDateOnly); if ($sDate === false) { $aValues[] = CMDBSource::Quote(''); @@ -592,12 +608,14 @@ try $sCol = $aInputColumns[$iCol]; if ($aIsDateToTransform[$iCol] !== false) { + $bDateOnly = false; $sFormat = $sDateTimeFormat; if ($aIsDateToTransform[$iCol] == 'DATE') { + $bDateOnly = true; $sFormat = $sDateFormat; } - $sDate = ChangeDateFormat($value, $sFormat); + $sDate = ChangeDateFormat($value, $sFormat, $bDateOnly); if ($sDate === false) { if ($sOutput == 'details') @@ -661,12 +679,12 @@ try { $aDateTimeColumns = array(); $aDateColumns = array(); - foreach($aIsDateToTransform as $iCol => $sSQLDef) + foreach($aIsDateToTransform as $iCol => $sType) { - if ($sSQLDef !== false) + if ($sType !== false) { $sCol = $aInputColumns[$iCol]; - if ($sSQLDef == 'DATE') + if ($sType == 'DATE') { $aDateColumns[] = $sCol; } diff --git a/synchro/synchrodatasource.class.inc.php b/synchro/synchrodatasource.class.inc.php index 17b9b63ce..b4aa9b7d3 100644 --- a/synchro/synchrodatasource.class.inc.php +++ b/synchro/synchrodatasource.class.inc.php @@ -1165,7 +1165,7 @@ EOF } /** - * Get the list of Date and Datetime SQL columns + * DEPRECATED - Get the list of Date and Datetime SQL columns */ public function GetDateSQLColumns() {