🎨 DataSynchro : remove some warnings, code formating

(cherry picked with small modifications from commit 26dcaa0ded : it was reverted on master as this branch contains a fix only version, ok to commit it on develop though)
This commit is contained in:
Pierre Goiffon
2019-05-22 17:38:58 +02:00
parent d6b194b0aa
commit b1761e04b2
2 changed files with 1429 additions and 790 deletions

View File

@@ -17,7 +17,7 @@
// along with iTop. If not, see <http://www.gnu.org/licenses/> // along with iTop. If not, see <http://www.gnu.org/licenses/>
/** /**
* Data Exchange web service * Data Exchange web service
* *
* @copyright Copyright (C) 2010-2017 Combodo SARL * @copyright Copyright (C) 2010-2017 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0 * @license http://opensource.org/licenses/AGPL-3.0
@@ -28,14 +28,17 @@
// - reconciliation is made on the column primary_key // - reconciliation is made on the column primary_key
// //
if (!defined('__DIR__')) define('__DIR__', dirname(__FILE__)); if (!defined('__DIR__'))
require_once(__DIR__.'/../approot.inc.php'); {
require_once(APPROOT.'/application/application.inc.php'); /** @noinspection DirectoryConstantCanBeUsedInspection */
require_once(APPROOT.'/application/webpage.class.inc.php'); define('__DIR__', dirname(__FILE__));
require_once(APPROOT.'/application/csvpage.class.inc.php'); }
require_once(APPROOT.'/application/clipage.class.inc.php'); require_once __DIR__.'/../approot.inc.php';
require_once APPROOT.'/application/application.inc.php';
require_once(APPROOT.'/application/startup.inc.php'); require_once APPROOT.'/application/webpage.class.inc.php';
require_once APPROOT.'/application/csvpage.class.inc.php';
require_once APPROOT.'/application/clipage.class.inc.php';
require_once APPROOT.'/application/startup.inc.php';
class ExchangeException extends Exception class ExchangeException extends Exception
{ {
@@ -127,15 +130,15 @@ $aPageParams = array
'default' => '0', 'default' => '0',
'description' => 'Limit on the count of records that can be loaded at once while performing the synchronization', 'description' => 'Limit on the count of records that can be loaded at once while performing the synchronization',
), ),
/* /*
'reportlevel' => array 'reportlevel' => array
( (
'mandatory' => false, 'mandatory' => false,
'modes' => 'http,cli', 'modes' => 'http,cli',
'default' => 'errors|warnings|created|changed|unchanged', 'default' => 'errors|warnings|created|changed|unchanged',
'description' => 'combination of flags to limit the detailed output', 'description' => 'combination of flags to limit the detailed output',
), ),
*/ */
'simulate' => array 'simulate' => array
( (
'mandatory' => false, 'mandatory' => false,
@@ -165,12 +168,12 @@ function UsageAndExit($oP)
$bModeCLI = utils::IsModeCLI(); $bModeCLI = utils::IsModeCLI();
$oP->p("USAGE:\n"); $oP->p("USAGE:\n");
foreach($aPageParams as $sParam => $aParamData) foreach ($aPageParams as $sParam => $aParamData)
{ {
$aModes = explode(',', $aParamData['modes']); $aModes = explode(',', $aParamData['modes']);
if ($bModeCLI) if ($bModeCLI)
{ {
if (in_array('cli', $aModes)) if (in_array('cli', $aModes, false))
{ {
$sDesc = $aParamData['description'].', '.($aParamData['mandatory'] ? 'mandatory' : 'optional, defaults to ['.$aParamData['default'].']'); $sDesc = $aParamData['description'].', '.($aParamData['mandatory'] ? 'mandatory' : 'optional, defaults to ['.$aParamData['default'].']');
$oP->p("$sParam = $sDesc"); $oP->p("$sParam = $sDesc");
@@ -178,7 +181,7 @@ function UsageAndExit($oP)
} }
else else
{ {
if (in_array('http', $aModes)) if (in_array('http', $aModes, false))
{ {
$sDesc = $aParamData['description'].', '.($aParamData['mandatory'] ? 'mandatory' : 'optional, defaults to ['.$aParamData['default'].']'); $sDesc = $aParamData['description'].', '.($aParamData['mandatory'] ? 'mandatory' : 'optional, defaults to ['.$aParamData['default'].']');
$oP->p("$sParam = $sDesc"); $oP->p("$sParam = $sDesc");
@@ -196,6 +199,7 @@ function ReadParam($oP, $sParam, $sSanitizationFilter = 'parameter')
assert(isset($aPageParams[$sParam])); assert(isset($aPageParams[$sParam]));
assert(!$aPageParams[$sParam]['mandatory']); assert(!$aPageParams[$sParam]['mandatory']);
$sValue = utils::ReadParam($sParam, $aPageParams[$sParam]['default'], true /* Allow CLI */, $sSanitizationFilter); $sValue = utils::ReadParam($sParam, $aPageParams[$sParam]['default'], true /* Allow CLI */, $sSanitizationFilter);
return trim($sValue); return trim($sValue);
} }
@@ -206,17 +210,18 @@ function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter)
assert($aPageParams[$sParam]['mandatory']); assert($aPageParams[$sParam]['mandatory']);
$sValue = utils::ReadParam($sParam, null, true /* Allow CLI */, $sSanitizationFilter); $sValue = utils::ReadParam($sParam, null, true /* Allow CLI */, $sSanitizationFilter);
if (is_null($sValue)) if ($sValue === null)
{ {
$oP->p("ERROR: Missing argument '$sParam'\n"); $oP->p("ERROR: Missing argument '$sParam'\n");
UsageAndExit($oP); UsageAndExit($oP);
} }
return trim($sValue); return trim($sValue);
} }
function ChangeDateFormat($sProposedDate, $sFormat, $bDateOnly) function ChangeDateFormat($sProposedDate, $sFormat, $bDateOnly)
{ {
if ($sProposedDate == '') if ($sProposedDate === '')
{ {
// An empty string means 'reset' // An empty string means 'reset'
return ''; return '';
@@ -226,22 +231,19 @@ function ChangeDateFormat($sProposedDate, $sFormat, $bDateOnly)
$sRegExpr = $oFormat->ToRegExpr('/'); $sRegExpr = $oFormat->ToRegExpr('/');
if (!preg_match($sRegExpr, $sProposedDate)) if (!preg_match($sRegExpr, $sProposedDate))
{ {
return false; return false;
} }
else
$oDate = $oFormat->Parse($sProposedDate);
if ($oDate !== null)
{ {
$oDate = $oFormat->Parse($sProposedDate); $oTargetFormat = $bDateOnly ? AttributeDate::GetInternalFormat() : AttributeDateTime::GetInternalFormat();
if ($oDate !== null) $sDate = $oDate->format($oTargetFormat);
{
$oTargetFormat = $bDateOnly ? AttributeDate::GetInternalFormat() : AttributeDateTime::GetInternalFormat(); return $sDate;
$sDate = $oDate->format($oTargetFormat);
return $sDate;
}
else
{
return false;
}
} }
return false;
} }
@@ -258,18 +260,18 @@ class CLILikeWebPage extends WebPage
if (utils::IsModeCLI()) if (utils::IsModeCLI())
{ {
$oP = new CLIPage(Dict::S("TitleSynchroExecution")); $oP = new CLIPage(Dict::S('TitleSynchroExecution'));
} }
else else
{ {
$oP = new CLILikeWebPage(Dict::S("TitleSynchroExecution")); $oP = new CLILikeWebPage(Dict::S('TitleSynchroExecution'));
} }
try try
{ {
utils::UseParamFile(); utils::UseParamFile();
} }
catch(Exception $e) catch (Exception $e)
{ {
$oP->p("Error: ".$e->GetMessage()); $oP->p("Error: ".$e->GetMessage());
$oP->output(); $oP->output();
@@ -307,10 +309,10 @@ if (utils::IsModeCLI())
else else
{ {
$_SESSION['login_mode'] = 'basic'; $_SESSION['login_mode'] = 'basic';
require_once(APPROOT.'/application/loginwebpage.class.inc.php'); require_once APPROOT.'/application/loginwebpage.class.inc.php';
LoginWebPage::DoLogin(); // Check user rights and prompt if needed LoginWebPage::DoLogin(); // Check user rights and prompt if needed
$sCSVData = utils::ReadPostedParam('csvdata', '', false, 'raw_data'); $sCSVData = utils::ReadPostedParam('csvdata', '', 'raw_data');
} }
@@ -326,7 +328,7 @@ try
$sQualifier = ReadParam($oP, 'qualifier', 'raw_data'); $sQualifier = ReadParam($oP, 'qualifier', 'raw_data');
$sCharSet = ReadParam($oP, 'charset', 'raw_data'); $sCharSet = ReadParam($oP, 'charset', 'raw_data');
$sDateTimeFormat = ReadParam($oP, 'date_format', 'raw_data'); $sDateTimeFormat = ReadParam($oP, 'date_format', 'raw_data');
if ($sDateTimeFormat == '') if ($sDateTimeFormat === '')
{ {
$sDateTimeFormat = 'Y-m-d H:i:s'; // By default use the SQL date & time format $sDateTimeFormat = 'Y-m-d H:i:s'; // By default use the SQL date & time format
} }
@@ -342,7 +344,7 @@ try
$sComment = ReadParam($oP, 'comment', 'raw_data'); $sComment = ReadParam($oP, 'comment', 'raw_data');
$sNoStopOnImportError = ReadParam($oP, 'no_stop_on_import_error'); $sNoStopOnImportError = ReadParam($oP, 'no_stop_on_import_error');
if (strtolower(trim($sSep)) == 'tab') if (strtolower(trim($sSep)) === 'tab')
{ {
$sSep = "\t"; $sSep = "\t";
} }
@@ -351,10 +353,10 @@ try
// then exec phase will need this ! // then exec phase will need this !
$oLoadStartDate = SynchroExecution::GetDataBaseCurrentDateTime(); $oLoadStartDate = SynchroExecution::GetDataBaseCurrentDateTime();
// Note about date formatting: These MySQL settings are read-only... and in fact unused :-( // Note about date formatting: These MySQL settings are read-only... and in fact unused :-(
// SET SESSION date_format = '%d/%m/%Y'; // SET SESSION date_format = '%d/%m/%Y';
// SET SESSION datetime_format = '%d/%m/%Y %H:%i:%s'; // SET SESSION datetime_format = '%d/%m/%Y %H:%i:%s';
// Therefore, we have to allow users to transform the format according to a given specification: date_format // Therefore, we have to allow users to transform the format according to a given specification: date_format
////////////////////////////////////////////////// //////////////////////////////////////////////////
@@ -369,14 +371,14 @@ try
// //
// Check parameters format/consistency // Check parameters format/consistency
// //
if (strlen($sCSVData) == 0) if (strlen($sCSVData) === 0)
{ {
throw new ExchangeException("Missing data - at least one line is expected"); throw new ExchangeException('Missing data - at least one line is expected');
} }
/** @var \SynchroDataSource $oDataSource */ /** @var \SynchroDataSource $oDataSource */
$oDataSource = MetaModel::GetObject('SynchroDataSource', $iDataSourceId, false); $oDataSource = MetaModel::GetObject('SynchroDataSource', $iDataSourceId, false);
if (is_null($oDataSource)) if ($oDataSource === null)
{ {
throw new ExchangeException("Unknown data source id: '$iDataSourceId'"); throw new ExchangeException("Unknown data source id: '$iDataSourceId'");
} }
@@ -397,18 +399,18 @@ try
throw new ExchangeException("Unknown output format: '$sOutput'"); throw new ExchangeException("Unknown output format: '$sOutput'");
} }
/* /*
$aReportLevels = explode('|', $sReportLevel); $aReportLevels = explode('|', $sReportLevel);
foreach($aReportLevels as $sLevel) foreach($aReportLevels as $sLevel)
{
if (!in_array($sLevel, explode('|', 'errors|warnings|created|changed|unchanged')))
{ {
throw new ExchangeException("Unknown level in reporting level: '$sLevel'"); if (!in_array($sLevel, explode('|', 'errors|warnings|created|changed|unchanged')))
{
throw new ExchangeException("Unknown level in reporting level: '$sLevel'");
}
} }
} */
*/
if ($sSimulate == '1') if ($sSimulate === '1')
{ {
$bSimulate = true; $bSimulate = true;
} }
@@ -417,7 +419,7 @@ try
$bSimulate = false; $bSimulate = false;
} }
if ($sSynchronize == '1') if ($sSynchronize === '1')
{ {
$bSynchronize = true; $bSynchronize = true;
} }
@@ -430,15 +432,15 @@ try
// //
// Parse first line, check attributes, analyse the request // Parse first line, check attributes, analyse the request
// //
if ($sCharSet == 'UTF-8') if ($sCharSet === 'UTF-8')
{ {
$sUTF8Data = $sCSVData; $sUTF8Data = $sCSVData;
} }
else else
{ {
$sUTF8Data = iconv($sCharSet, 'UTF-8//IGNORE//TRANSLIT', $sCSVData); $sUTF8Data = iconv($sCharSet, 'UTF-8//IGNORE//TRANSLIT', $sCSVData);
} }
$oCSVParser = new CSVParser($sUTF8Data, $sSep, $sQualifier, MetaModel::GetConfig()->Get('max_execution_time_per_loop')); $oCSVParser = new CSVParser($sUTF8Data, $sSep, $sQualifier, MetaModel::GetConfig()->Get('max_execution_time_per_loop'));
$aInputColumns = $oCSVParser->ListFields(); $aInputColumns = $oCSVParser->ListFields();
$iColCount = count($aInputColumns); $iColCount = count($aInputColumns);
@@ -447,7 +449,7 @@ try
$aColumns = $oDataSource->GetSQLColumns(); $aColumns = $oDataSource->GetSQLColumns();
$aDateColumns = array(); $aDateColumns = array();
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
{ {
if ($oAttDef instanceof AttributeDate) if ($oAttDef instanceof AttributeDate)
{ {
@@ -461,7 +463,7 @@ try
$aIsDateToTransform = array(); $aIsDateToTransform = array();
$aDateToTransformReport = array(); $aDateToTransformReport = array();
foreach($aInputColumns as $iFieldId => $sInputColumn) foreach ($aInputColumns as $iFieldId => $sInputColumn)
{ {
if (array_key_exists($sInputColumn, $aDateColumns)) if (array_key_exists($sInputColumn, $aDateColumns))
{ {
@@ -473,7 +475,7 @@ try
$aIsDateToTransform[$iFieldId] = false; $aIsDateToTransform[$iFieldId] = false;
} }
if ($sInputColumn == 'primary_key') if ($sInputColumn === 'primary_key')
{ {
$iPrimaryKeyCol = $iFieldId; $iPrimaryKeyCol = $iFieldId;
continue; continue;
@@ -494,51 +496,51 @@ try
// //
try try
{ {
if ($sOutput == 'details') if ($sOutput === 'details')
{ {
$oP->add_comment('------------------------------------------------------------'); $oP->add_comment('------------------------------------------------------------');
$oP->add_comment(' Import phase'); $oP->add_comment(' Import phase');
$oP->add_comment('------------------------------------------------------------'); $oP->add_comment('------------------------------------------------------------');
} }
if ($bSimulate) if ($bSimulate)
{ {
CMDBSource::Query('START TRANSACTION'); CMDBSource::Query('START TRANSACTION');
} }
$aData = $oCSVParser->ToArray(); $aData = $oCSVParser->ToArray();
$iLineCount = count($aData); $iLineCount = count($aData);
$sTable = $oDataSource->GetDataTable(); $sTable = $oDataSource->GetDataTable();
// Prepare insert columns // Prepare insert columns
$sInsertColumns = '`'.implode('`, `', $aInputColumns).'`'; $sInsertColumns = '`'.implode('`, `', $aInputColumns).'`';
$iPreviousTimeLimit = ini_get('max_execution_time'); $iPreviousTimeLimit = ini_get('max_execution_time');
$iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop'); $iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop');
$oMutex = new iTopMutex('synchro_import_'.$oDataSource->GetKey()); $oMutex = new iTopMutex('synchro_import_'.$oDataSource->GetKey());
$oMutex->Lock(); $oMutex->Lock();
foreach($aData as $iRow => $aRow) set_time_limit($iLoopTimeLimit);
{ foreach ($aData as $iRow => $aRow)
set_time_limit($iLoopTimeLimit); {
$sReconciliationCondition = "`primary_key` = ".CMDBSource::Quote($aRow[$iPrimaryKeyCol]); $sReconciliationCondition = '`primary_key` = '.CMDBSource::Quote($aRow[$iPrimaryKeyCol]);
$sSelect = "SELECT COUNT(*) FROM `$sTable` WHERE $sReconciliationCondition"; $sSelect = "SELECT COUNT(*) FROM `$sTable` WHERE $sReconciliationCondition";
$aRes = CMDBSource::QueryToArray($sSelect); $aRes = CMDBSource::QueryToArray($sSelect);
$iCount = $aRes[0]['COUNT(*)']; $iCount = (int)$aRes[0]['COUNT(*)'];
if ($iCount == 0) if ($iCount === 0)
{ {
// No record... create it // No record... create it
// //
$iCountCreations++; $iCountCreations++;
if ($sOutput == 'details') if ($sOutput === 'details')
{ {
$oP->add("$iRow: New entry, reconciliation: '$sReconciliationCondition'\n"); $oP->add("$iRow: New entry, reconciliation: '$sReconciliationCondition'\n");
} }
$aValues = array(); // Used to build the insert query $aValues = array(); // Used to build the insert query
foreach ($aRow as $iCol => $value) foreach ($aRow as $iCol => $value)
{ {
if (is_null($value)) if ($value === null)
{ {
$aValues[] = 'NULL'; $aValues[] = 'NULL';
} }
@@ -546,7 +548,7 @@ try
{ {
$bDateOnly = false; $bDateOnly = false;
$sFormat = $sDateTimeFormat; $sFormat = $sDateTimeFormat;
if ($aIsDateToTransform[$iCol] == 'DATE') if ($aIsDateToTransform[$iCol] === 'DATE')
{ {
$bDateOnly = true; $bDateOnly = true;
$sFormat = $sDateFormat; $sFormat = $sDateFormat;
@@ -555,7 +557,7 @@ try
if ($sDate === false) if ($sDate === false)
{ {
$aValues[] = CMDBSource::Quote(''); $aValues[] = CMDBSource::Quote('');
if ($sOutput == 'details') if ($sOutput === 'details')
{ {
$oP->add("$iRow: Wrong format for {$aIsDateToTransform[$iCol]} column $iCol: '$value' does not match the expected format: '$sFormat' (column skipped)\n"); $oP->add("$iRow: Wrong format for {$aIsDateToTransform[$iCol]} column $iCol: '$value' does not match the expected format: '$sFormat' (column skipped)\n");
} }
@@ -576,9 +578,9 @@ try
{ {
CMDBSource::Query($sInsert); CMDBSource::Query($sInsert);
} }
catch(Exception $e) catch (Exception $e)
{ {
if ($sNoStopOnImportError == '1') if ($sNoStopOnImportError === '1')
{ {
$iCountErrors++; $iCountErrors++;
$oP->add("$iRow: Import error '".$e->getMessage()."' (continuing)...\n"); $oP->add("$iRow: Import error '".$e->getMessage()."' (continuing)...\n");
@@ -589,28 +591,30 @@ try
} }
} }
} }
elseif ($iCount == 1) elseif ($iCount === 1)
{ {
// Found a match... update it // Found a match... update it
// //
$iCountUpdates++; $iCountUpdates++;
if ($sOutput == 'details') if ($sOutput === 'details')
{ {
$oP->add("$iRow: Update entry, reconciliation: '$sReconciliationCondition'\n"); $oP->add("$iRow: Update entry, reconciliation: '$sReconciliationCondition'\n");
} }
$aValuePairs = array(); // Used to build the update query $aValuePairs = array(); // Used to build the update query
foreach ($aRow as $iCol => $value) foreach ($aRow as $iCol => $value)
{ {
// Skip reconciliation column // Skip reconciliation column
if ($iCol == $iPrimaryKeyCol) continue; if ($iCol === $iPrimaryKeyCol)
{
continue;
}
$sCol = $aInputColumns[$iCol]; $sCol = $aInputColumns[$iCol];
if ($aIsDateToTransform[$iCol] !== false) if ($aIsDateToTransform[$iCol] !== false)
{ {
$bDateOnly = false; $bDateOnly = false;
$sFormat = $sDateTimeFormat; $sFormat = $sDateTimeFormat;
if ($aIsDateToTransform[$iCol] == 'DATE') if ($aIsDateToTransform[$iCol] === 'DATE')
{ {
$bDateOnly = true; $bDateOnly = true;
$sFormat = $sDateFormat; $sFormat = $sDateFormat;
@@ -618,7 +622,7 @@ try
$sDate = ChangeDateFormat($value, $sFormat, $bDateOnly); $sDate = ChangeDateFormat($value, $sFormat, $bDateOnly);
if ($sDate === false) if ($sDate === false)
{ {
if ($sOutput == 'details') if ($sOutput === 'details')
{ {
$oP->add("$iRow: Wrong format for {$aIsDateToTransform[$iCol]} column $iCol: '$value' does not match the expected format: '$sFormat' (column skipped)\n"); $oP->add("$iRow: Wrong format for {$aIsDateToTransform[$iCol]} column $iCol: '$value' does not match the expected format: '$sFormat' (column skipped)\n");
} }
@@ -639,9 +643,9 @@ try
{ {
CMDBSource::Query($sUpdateQuery); CMDBSource::Query($sUpdateQuery);
} }
catch(Exception $e) catch (Exception $e)
{ {
if ($sNoStopOnImportError == '1') if ($sNoStopOnImportError === '1')
{ {
$iCountErrors++; $iCountErrors++;
$oP->add("$iRow: Import error '".$e->getMessage()."' (continuing)...\n"); $oP->add("$iRow: Import error '".$e->getMessage()."' (continuing)...\n");
@@ -662,29 +666,29 @@ try
} }
$oMutex->Unlock(); $oMutex->Unlock();
set_time_limit($iPreviousTimeLimit); set_time_limit($iPreviousTimeLimit);
if (($sOutput == "summary") || ($sOutput == 'details')) if (($sOutput === 'summary') || ($sOutput === 'details'))
{ {
$oP->add_comment('------------------------------------------------------------'); $oP->add_comment('------------------------------------------------------------');
$oP->add_comment(' Import phase summary'); $oP->add_comment(' Import phase summary');
$oP->add_comment('------------------------------------------------------------'); $oP->add_comment('------------------------------------------------------------');
$oP->add_comment("Data Source: ".$iDataSourceId); $oP->add_comment('Data Source: '.$iDataSourceId);
$oP->add_comment("Synchronize: ".($bSynchronize ? '1' : '0')); $oP->add_comment('Synchronize: '.($bSynchronize ? '1' : '0'));
$oP->add_comment("Class: ".$sClass); $oP->add_comment('Class: '.$sClass);
$oP->add_comment("Separator: ".$sSep); $oP->add_comment('Separator: '.$sSep);
$oP->add_comment("Qualifier: ".$sQualifier); $oP->add_comment('Qualifier: '.$sQualifier);
$oP->add_comment("Charset Encoding:".$sCharSet); $oP->add_comment('Charset Encoding:'.$sCharSet);
if (strlen($sDateTimeFormat) > 0) if (strlen($sDateTimeFormat) > 0)
{ {
$aDateTimeColumns = array(); $aDateTimeColumns = array();
$aDateColumns = array(); $aDateColumns = array();
foreach($aIsDateToTransform as $iCol => $sType) foreach ($aIsDateToTransform as $iCol => $sType)
{ {
if ($sType !== false) if ($sType !== false)
{ {
$sCol = $aInputColumns[$iCol]; $sCol = $aInputColumns[$iCol];
if ($sType == 'DATE') if ($sType === 'DATE')
{ {
$aDateColumns[] = $sCol; $aDateColumns[] = $sCol;
} }
@@ -694,7 +698,8 @@ try
} }
} }
} }
$sFormatedDateTimeColumns = (count($aDateTimeColumns) > 0) ? ', applied to columns ['.implode(', ', $aDateTimeColumns).']' : ''; $sFormatedDateTimeColumns = (count($aDateTimeColumns) > 0) ? ', applied to columns ['.implode(', ',
$aDateTimeColumns).']' : '';
$sFormatedDateColumns = (count($aDateColumns) > 0) ? ', applied to columns ['.implode(', ', $aDateColumns).']' : ''; $sFormatedDateColumns = (count($aDateColumns) > 0) ? ', applied to columns ['.implode(', ', $aDateColumns).']' : '';
$oP->add_comment("Date and time format: '$sDateTimeFormat' $sFormatedDateTimeColumns"); $oP->add_comment("Date and time format: '$sDateTimeFormat' $sFormatedDateTimeColumns");
$oP->add_comment("Date only format: '$sDateFormat' $sFormatedDateColumns"); $oP->add_comment("Date only format: '$sDateFormat' $sFormatedDateColumns");
@@ -702,19 +707,19 @@ try
else else
{ {
// shall never get there // shall never get there
$oP->add_comment("Date format: <none>"); $oP->add_comment('Date format: <none>');
} }
$oP->add_comment("Data Size: ".strlen($sCSVData)); $oP->add_comment('Data Size: '.strlen($sCSVData));
$oP->add_comment("Data Lines: ".$iLineCount); $oP->add_comment('Data Lines: '.$iLineCount);
$oP->add_comment("Columns: ".implode(', ', $aInputColumns)); $oP->add_comment('Columns: '.implode(', ', $aInputColumns));
$oP->add_comment("Output format: ".$sOutput); $oP->add_comment('Output format: '.$sOutput);
// $oP->add_comment("Report level: ".$sReportLevel); // $oP->add_comment("Report level: ".$sReportLevel);
$oP->add_comment("Simulate: ".($bSimulate ? '1' : '0')); $oP->add_comment('Simulate: '.($bSimulate ? '1' : '0'));
$oP->add_comment("Change tracking comment: ".$sComment); $oP->add_comment('Change tracking comment: '.$sComment);
$oP->add_comment("Issues (before synchro): ".$iCountErrors); $oP->add_comment('Issues (before synchro): '.$iCountErrors);
// $oP->add_comment("Warnings: ".$iCountWarnings); // $oP->add_comment("Warnings: ".$iCountWarnings);
$oP->add_comment("Created (before synchro): ".$iCountCreations); $oP->add_comment('Created (before synchro): '.$iCountCreations);
$oP->add_comment("Updated (before synchro): ".$iCountUpdates); $oP->add_comment('Updated (before synchro): '.$iCountUpdates);
} }
////////////////////////////////////////////////// //////////////////////////////////////////////////
@@ -725,7 +730,7 @@ try
{ {
$oSynchroExec = new SynchroExecution($oDataSource, $oLoadStartDate); $oSynchroExec = new SynchroExecution($oDataSource, $oLoadStartDate);
$oStatLog = $oSynchroExec->Process(); $oStatLog = $oSynchroExec->Process();
if ($sOutput == 'details') if ($sOutput === 'details')
{ {
$oP->add_comment('------------------------------------------------------------'); $oP->add_comment('------------------------------------------------------------');
$oP->add_comment(' Synchronization phase'); $oP->add_comment(' Synchronization phase');
@@ -736,35 +741,35 @@ try
$iCount++; $iCount++;
$oP->add_comment($sMessage); $oP->add_comment($sMessage);
} }
if ($iCount == 0) if ($iCount === 0)
{ {
$oP->add_comment(' No traces. (To activate the traces set "synchro_trace" => true in the configuration file)'); $oP->add_comment(' No traces. (To activate the traces set "synchro_trace" => true in the configuration file)');
} }
} }
if ($oStatLog->Get('status') == 'error') if ($oStatLog->Get('status') === 'error')
{ {
$oP->p("ERROR: ".$oStatLog->Get('last_error')); $oP->p('ERROR: '.$oStatLog->Get('last_error'));
} }
$oP->add_comment('------------------------------------------------------------'); $oP->add_comment('------------------------------------------------------------');
$oP->add_comment(' Synchronization phase summary'); $oP->add_comment(' Synchronization phase summary');
$oP->add_comment('------------------------------------------------------------'); $oP->add_comment('------------------------------------------------------------');
$oP->add_comment("Replicas: ".$oStatLog->Get('stats_nb_replica_total')); $oP->add_comment('Replicas: '.$oStatLog->Get('stats_nb_replica_total'));
$oP->add_comment("Replicas touched since last synchro: ".$oStatLog->Get('stats_nb_replica_seen')); $oP->add_comment('Replicas touched since last synchro: '.$oStatLog->Get('stats_nb_replica_seen'));
$oP->add_comment("Objects deleted: ".$oStatLog->Get('stats_nb_obj_deleted')); $oP->add_comment('Objects deleted: '.$oStatLog->Get('stats_nb_obj_deleted'));
$oP->add_comment("Objects deletion errors: ".$oStatLog->Get('stats_nb_obj_deleted_errors')); $oP->add_comment('Objects deletion errors: '.$oStatLog->Get('stats_nb_obj_deleted_errors'));
$oP->add_comment("Objects obsoleted: ".$oStatLog->Get('stats_nb_obj_obsoleted')); $oP->add_comment('Objects obsoleted: '.$oStatLog->Get('stats_nb_obj_obsoleted'));
$oP->add_comment("Objects obsolescence errors: ".$oStatLog->Get('stats_nb_obj_obsoleted_errors')); $oP->add_comment('Objects obsolescence errors: '.$oStatLog->Get('stats_nb_obj_obsoleted_errors'));
$oP->add_comment("Objects created: ".$oStatLog->Get('stats_nb_obj_created')." (".$oStatLog->Get('stats_nb_obj_created_warnings')." warnings)"); $oP->add_comment('Objects created: '.$oStatLog->Get('stats_nb_obj_created').' ('.$oStatLog->Get('stats_nb_obj_created_warnings').' warnings)');
$oP->add_comment("Objects creation errors: ".$oStatLog->Get('stats_nb_obj_created_errors')); $oP->add_comment('Objects creation errors: '.$oStatLog->Get('stats_nb_obj_created_errors'));
$oP->add_comment("Objects updated: ".$oStatLog->Get('stats_nb_obj_updated')." (".$oStatLog->Get('stats_nb_obj_updated_warnings')." warnings)"); $oP->add_comment('Objects updated: '.$oStatLog->Get('stats_nb_obj_updated').' ('.$oStatLog->Get('stats_nb_obj_updated_warnings')." warnings)");
$oP->add_comment("Objects update errors: ".$oStatLog->Get('stats_nb_obj_updated_errors')); $oP->add_comment('Objects update errors: '.$oStatLog->Get('stats_nb_obj_updated_errors'));
$oP->add_comment("Objects reconciled (updated): ".$oStatLog->Get('stats_nb_obj_new_updated')." (".$oStatLog->Get('stats_nb_obj_new_updated_warnings')." warnings)"); $oP->add_comment('Objects reconciled (updated): '.$oStatLog->Get('stats_nb_obj_new_updated').' ('.$oStatLog->Get('stats_nb_obj_new_updated_warnings').' warnings)');
$oP->add_comment("Objects reconciled (unchanged): ".$oStatLog->Get('stats_nb_obj_new_unchanged')." (".$oStatLog->Get('stats_nb_obj_new_updated_warnings')." warnings)"); $oP->add_comment('Objects reconciled (unchanged): '.$oStatLog->Get('stats_nb_obj_new_unchanged').' ('.$oStatLog->Get('stats_nb_obj_new_updated_warnings').' warnings)');
$oP->add_comment("Objects reconciliation errors: ".$oStatLog->Get('stats_nb_replica_reconciled_errors')); $oP->add_comment('Objects reconciliation errors: '.$oStatLog->Get('stats_nb_replica_reconciled_errors'));
$oP->add_comment("Replica disappeared, no action taken: ".$oStatLog->Get('stats_nb_replica_disappeared_no_action')); $oP->add_comment('Replica disappeared, no action taken: '.$oStatLog->Get('stats_nb_replica_disappeared_no_action'));
} }
} }
catch(Exception $e) catch (Exception $e)
{ {
if ($bSimulate) if ($bSimulate)
{ {
@@ -781,23 +786,18 @@ try
// //
// Summary of settings and results // Summary of settings and results
// //
if ($sOutput == 'retcode') if ($sOutput === 'retcode')
{ {
$oP->add($iCountErrors); $oP->add($iCountErrors);
} }
} }
catch(ExchangeException $e) catch (ExchangeException $e)
{ {
$oP->add_comment($e->getMessage()); $oP->add_comment($e->getMessage());
} }
catch(SecurityException $e) catch (Exception $e)
{ {
$oP->add_comment($e->getMessage()); $oP->add_comment((string)$e);
}
catch(Exception $e)
{
$oP->add_comment((string)$e);
} }
$oP->output(); $oP->output();
?>

File diff suppressed because it is too large Load Diff