synchro_import.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. <?php
  2. // Copyright (C) 2011 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Data Exchange web service
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. //
  25. // Known limitations
  26. // - reconciliation is made on the column primary_key
  27. //
  28. if (!defined('__DIR__')) define('__DIR__', dirname(__FILE__));
  29. require_once(__DIR__.'/../approot.inc.php');
  30. require_once(APPROOT.'/application/application.inc.php');
  31. require_once(APPROOT.'/application/webpage.class.inc.php');
  32. require_once(APPROOT.'/application/csvpage.class.inc.php');
  33. require_once(APPROOT.'/application/clipage.class.inc.php');
  34. require_once(APPROOT.'/application/startup.inc.php');
  35. class ExchangeException extends Exception
  36. {
  37. }
  38. $aPageParams = array
  39. (
  40. 'auth_user' => array
  41. (
  42. 'mandatory' => true,
  43. 'modes' => 'cli',
  44. 'default' => null,
  45. 'description' => 'login (must have enough rights to create objects of the given class)',
  46. ),
  47. 'auth_pwd' => array
  48. (
  49. 'mandatory' => true,
  50. 'modes' => 'cli',
  51. 'default' => null,
  52. 'description' => 'password',
  53. ),
  54. 'data_source_id' => array
  55. (
  56. 'mandatory' => true,
  57. 'modes' => 'http,cli',
  58. 'default' => null,
  59. 'description' => 'Synchro data source id',
  60. ),
  61. 'csvdata' => array
  62. (
  63. 'mandatory' => true,
  64. 'modes' => 'http',
  65. 'default' => null,
  66. 'description' => 'data',
  67. ),
  68. 'csvfile' => array
  69. (
  70. 'mandatory' => true,
  71. 'modes' => 'cli',
  72. 'default' => '',
  73. 'description' => 'local data file, replaces csvdata if specified',
  74. ),
  75. 'synchronize' => array
  76. (
  77. 'mandatory' => false,
  78. 'modes' => 'http,cli',
  79. 'default' => '1',
  80. 'description' => 'If set to 1, then the synchronization will be executed right after the data load',
  81. ),
  82. 'charset' => array
  83. (
  84. 'mandatory' => false,
  85. 'modes' => 'http,cli',
  86. 'default' => 'UTF-8',
  87. 'description' => 'Character set encoding of the CSV data: UTF-8, ISO-8859-1, WINDOWS-1251, WINDOWS-1252, ISO-8859-15',
  88. ),
  89. 'date_format' => array
  90. (
  91. 'mandatory' => false,
  92. 'modes' => 'http,cli',
  93. 'default' => '',
  94. 'description' => 'Input date format (used both for dates and datetimes) - Examples: %Y-%m-%d, %d/%m/%Y (Europe) - no transformation is applied if the argument is omitted',
  95. ),
  96. 'separator' => array
  97. (
  98. 'mandatory' => false,
  99. 'modes' => 'http,cli',
  100. 'default' => ';',
  101. 'description' => 'column separator in CSV data',
  102. ),
  103. 'qualifier' => array
  104. (
  105. 'mandatory' => false,
  106. 'modes' => 'http,cli',
  107. 'default' => '"',
  108. 'description' => 'test qualifier in CSV data',
  109. ),
  110. 'output' => array
  111. (
  112. 'mandatory' => false,
  113. 'modes' => 'http,cli',
  114. 'default' => 'summary',
  115. 'description' => '[retcode] to return the count of lines in error, [summary] to return a concise report, [details] to get a detailed report (each line listed)',
  116. ),
  117. /*
  118. 'reportlevel' => array
  119. (
  120. 'mandatory' => false,
  121. 'modes' => 'http,cli',
  122. 'default' => 'errors|warnings|created|changed|unchanged',
  123. 'description' => 'combination of flags to limit the detailed output',
  124. ),
  125. */
  126. 'simulate' => array
  127. (
  128. 'mandatory' => false,
  129. 'modes' => 'http,cli',
  130. 'default' => '0',
  131. 'description' => 'If set to 1, then the load will not be executed, but the expected report will be produced',
  132. ),
  133. 'comment' => array
  134. (
  135. 'mandatory' => false,
  136. 'modes' => 'http,cli',
  137. 'default' => '',
  138. 'description' => 'Comment to be added into the change log',
  139. ),
  140. 'no_stop_on_import_error' => array
  141. (
  142. 'mandatory' => false,
  143. 'modes' => 'http,cli',
  144. 'default' => '0',
  145. 'description' => 'Don\'t stop the import in case of SQL import error. By default the import will stop at the first error (and rollback all changes). If this flag is set to 1 the import will continue anyway',
  146. ),
  147. );
  148. function UsageAndExit($oP)
  149. {
  150. global $aPageParams;
  151. $bModeCLI = utils::IsModeCLI();
  152. $oP->p("USAGE:\n");
  153. foreach($aPageParams as $sParam => $aParamData)
  154. {
  155. $aModes = explode(',', $aParamData['modes']);
  156. if ($bModeCLI)
  157. {
  158. if (in_array('cli', $aModes))
  159. {
  160. $sDesc = $aParamData['description'].', '.($aParamData['mandatory'] ? 'mandatory' : 'optional, defaults to ['.$aParamData['default'].']');
  161. $oP->p("$sParam = $sDesc");
  162. }
  163. }
  164. else
  165. {
  166. if (in_array('http', $aModes))
  167. {
  168. $sDesc = $aParamData['description'].', '.($aParamData['mandatory'] ? 'mandatory' : 'optional, defaults to ['.$aParamData['default'].']');
  169. $oP->p("$sParam = $sDesc");
  170. }
  171. }
  172. }
  173. $oP->output();
  174. exit;
  175. }
  176. function ReadParam($oP, $sParam, $sSanitizationFilter = 'parameter')
  177. {
  178. global $aPageParams;
  179. assert(isset($aPageParams[$sParam]));
  180. assert(!$aPageParams[$sParam]['mandatory']);
  181. $sValue = utils::ReadParam($sParam, $aPageParams[$sParam]['default'], true /* Allow CLI */, $sSanitizationFilter);
  182. return trim($sValue);
  183. }
  184. function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter)
  185. {
  186. global $aPageParams;
  187. assert(isset($aPageParams[$sParam]));
  188. assert($aPageParams[$sParam]['mandatory']);
  189. $sValue = utils::ReadParam($sParam, null, true /* Allow CLI */, $sSanitizationFilter);
  190. if (is_null($sValue))
  191. {
  192. $oP->p("ERROR: Missing argument '$sParam'\n");
  193. UsageAndExit($oP);
  194. }
  195. return trim($sValue);
  196. }
  197. function ChangeDateFormat($sProposedDate, $sDateFormat)
  198. {
  199. // Make sure this is a valid MySQL datetime
  200. $iTime = utils::StringToTime($sProposedDate, $sDateFormat);
  201. if ($iTime !== false)
  202. {
  203. $sDate = date('Y-m-d H:i:s', $iTime);
  204. return $sDate;
  205. }
  206. else
  207. {
  208. return false;
  209. }
  210. }
  211. /////////////////////////////////
  212. // Main program
  213. if (utils::IsModeCLI())
  214. {
  215. $oP = new CLIPage(Dict::S("TitleSynchroExecution"));
  216. }
  217. else
  218. {
  219. $oP = new WebPage(Dict::S("TitleSynchroExecution"));
  220. }
  221. try
  222. {
  223. utils::UseParamFile();
  224. }
  225. catch(Exception $e)
  226. {
  227. $oP->p("Error: ".$e->GetMessage());
  228. $oP->output();
  229. exit -2;
  230. }
  231. if (utils::IsModeCLI())
  232. {
  233. // Next steps:
  234. // specific arguments: 'csvfile'
  235. //
  236. $sAuthUser = ReadMandatoryParam($oP, 'auth_user', 'raw_data');
  237. $sAuthPwd = ReadMandatoryParam($oP, 'auth_pwd', 'raw_data');
  238. $sCsvFile = ReadMandatoryParam($oP, 'csvfile', 'raw_data');
  239. if (UserRights::CheckCredentials($sAuthUser, $sAuthPwd))
  240. {
  241. UserRights::Login($sAuthUser); // Login & set the user's language
  242. }
  243. else
  244. {
  245. $oP->p("Access restricted or wrong credentials ('$sAuthUser')");
  246. $oP->output();
  247. exit -1;
  248. }
  249. if (!is_readable($sCsvFile))
  250. {
  251. $oP->p("Input file could not be found or could not be read: '$sCsvFile'");
  252. $oP->output();
  253. exit -1;
  254. }
  255. $sCSVData = file_get_contents($sCsvFile);
  256. }
  257. else
  258. {
  259. $_SESSION['login_mode'] = 'basic';
  260. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  261. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  262. $sCSVData = utils::ReadPostedParam('csvdata', '', false, 'raw_data');
  263. }
  264. try
  265. {
  266. //////////////////////////////////////////////////
  267. //
  268. // Read parameters
  269. //
  270. $iDataSourceId = ReadMandatoryParam($oP, 'data_source_id', 'raw_data');
  271. $sSynchronize = ReadParam($oP, 'synchronize');
  272. $sSep = ReadParam($oP, 'separator', 'raw_data');
  273. $sQualifier = ReadParam($oP, 'qualifier', 'raw_data');
  274. $sCharSet = ReadParam($oP, 'charset', 'raw_data');
  275. $sDateFormat = ReadParam($oP, 'date_format', 'raw_data');
  276. $sOutput = ReadParam($oP, 'output');
  277. // $sReportLevel = ReadParam($oP, 'reportlevel');
  278. $sSimulate = ReadParam($oP, 'simulate');
  279. $sComment = ReadParam($oP, 'comment', 'raw_data');
  280. $sNoStopOnImportError = ReadParam($oP, 'no_stop_on_import_error');
  281. $oLoadStartDate = new DateTime(); // Now
  282. // Note about date formatting: These MySQL settings are read-only... and in fact unused :-(
  283. // SET SESSION date_format = '%d/%m/%Y';
  284. // SET SESSION datetime_format = '%d/%m/%Y %H:%i:%s';
  285. // Therefore, we have to allow users to transform the format according to a given specification: date_format
  286. //////////////////////////////////////////////////
  287. //
  288. // Statistics
  289. //
  290. $iCountErrors = 0;
  291. $iCountCreations = 0;
  292. $iCountUpdates = 0;
  293. //////////////////////////////////////////////////
  294. //
  295. // Check parameters format/consistency
  296. //
  297. if (strlen($sCSVData) == 0)
  298. {
  299. throw new ExchangeException("Missing data - at least one line is expected");
  300. }
  301. $oDataSource = MetaModel::GetObject('SynchroDataSource', $iDataSourceId, false);
  302. if (is_null($oDataSource))
  303. {
  304. throw new ExchangeException("Unknown data source id: '$iDataSourceId'");
  305. }
  306. $sClass = $oDataSource->GetTargetClass();
  307. if (strlen($sSep) > 1)
  308. {
  309. throw new ExchangeException("Separator is limited to one character, found '$sSep'");
  310. }
  311. if (strlen($sQualifier) > 1)
  312. {
  313. throw new ExchangeException("Text qualifier is limited to one character, found '$sQualifier'");
  314. }
  315. if (!in_array($sOutput, array('retcode', 'summary', 'details')))
  316. {
  317. throw new ExchangeException("Unknown output format: '$sOutput'");
  318. }
  319. /*
  320. $aReportLevels = explode('|', $sReportLevel);
  321. foreach($aReportLevels as $sLevel)
  322. {
  323. if (!in_array($sLevel, explode('|', 'errors|warnings|created|changed|unchanged')))
  324. {
  325. throw new ExchangeException("Unknown level in reporting level: '$sLevel'");
  326. }
  327. }
  328. */
  329. if ($sSimulate == '1')
  330. {
  331. $bSimulate = true;
  332. }
  333. else
  334. {
  335. $bSimulate = false;
  336. }
  337. if ($sSynchronize == '1')
  338. {
  339. $bSynchronize = true;
  340. }
  341. else
  342. {
  343. $bSynchronize = false;
  344. }
  345. //////////////////////////////////////////////////
  346. //
  347. // Parse first line, check attributes, analyse the request
  348. //
  349. if ($sCharSet == 'UTF-8')
  350. {
  351. $sUTF8Data = $sCSVData;
  352. }
  353. else
  354. {
  355. $sUTF8Data = iconv($sCharSet, 'UTF-8//IGNORE//TRANSLIT', $sCSVData);
  356. }
  357. $oCSVParser = new CSVParser($sUTF8Data, $sSep, $sQualifier);
  358. $aInputColumns = $oCSVParser->ListFields();
  359. $iColCount = count($aInputColumns);
  360. // Check columns
  361. $aColumns = $oDataSource->GetSQLColumns();
  362. $aDateColumns = $oDataSource->GetDateSQLColumns();
  363. $aIsDateToTransform = array();
  364. $aDateToTransformReport = array();
  365. foreach($aInputColumns as $iFieldId => $sInputColumn)
  366. {
  367. if ((strlen($sDateFormat) > 0) && (array_key_exists($sInputColumn, $aDateColumns)))
  368. {
  369. $aIsDateToTransform[$iFieldId] = true;
  370. $aDateToTransformReport[] = $sInputColumn;
  371. }
  372. else
  373. {
  374. $aIsDateToTransform[$iFieldId] = false;
  375. }
  376. if ($sInputColumn == 'primary_key')
  377. {
  378. $iPrimaryKeyCol = $iFieldId;
  379. continue;
  380. }
  381. if (!array_key_exists($sInputColumn, $aColumns))
  382. {
  383. throw new ExchangeException("Unknown column '$sInputColumn' (class: '$sClass')");
  384. }
  385. }
  386. if (!isset($iPrimaryKeyCol))
  387. {
  388. throw new ExchangeException("Missing reconciliation column 'primary_key'");
  389. }
  390. //////////////////////////////////////////////////
  391. //
  392. // Go for parsing and interpretation
  393. //
  394. try
  395. {
  396. $oP->add_comment('Load--------------');
  397. $oP->add_comment('------------------');
  398. if ($bSimulate)
  399. {
  400. CMDBSource::Query('START TRANSACTION');
  401. }
  402. $aData = $oCSVParser->ToArray();
  403. $iLineCount = count($aData);
  404. $sTable = $oDataSource->GetDataTable();
  405. // Prepare insert columns
  406. $sInsertColumns = '`'.implode('`, `', $aInputColumns).'`';
  407. foreach($aData as $iRow => $aRow)
  408. {
  409. $sReconciliationCondition = "`primary_key` = ".CMDBSource::Quote($aRow[$iPrimaryKeyCol]);
  410. $sSelect = "SELECT COUNT(*) FROM `$sTable` WHERE $sReconciliationCondition";
  411. $aRes = CMDBSource::QueryToArray($sSelect);
  412. $iCount = $aRes[0]['COUNT(*)'];
  413. if ($iCount == 0)
  414. {
  415. // No record... create it
  416. //
  417. $iCountCreations++;
  418. if ($sOutput == 'details')
  419. {
  420. $oP->add("$iRow: New entry, reconciliation: '$sReconciliationCondition'\n");
  421. }
  422. $aValues = array(); // Used to build the insert query
  423. foreach ($aRow as $iCol => $value)
  424. {
  425. if (is_null($value))
  426. {
  427. $aValues[] = 'NULL';
  428. }
  429. elseif ($aIsDateToTransform[$iCol])
  430. {
  431. $sDate = ChangeDateFormat($value, $sDateFormat);
  432. if ($sDate === false)
  433. {
  434. $aValues[] = CMDBSource::Quote('');
  435. if ($sOutput == 'details')
  436. {
  437. $oP->add("$iRow: Wrong format for date field: '$value' (skipped column)\n");
  438. }
  439. }
  440. else
  441. {
  442. $aValues[] = CMDBSource::Quote($sDate);
  443. }
  444. }
  445. else
  446. {
  447. $aValues[] = CMDBSource::Quote($value);
  448. }
  449. }
  450. $sValues = implode(', ', $aValues);
  451. $sInsert = "INSERT INTO `$sTable` ($sInsertColumns) VALUES ($sValues)";
  452. try
  453. {
  454. CMDBSource::Query($sInsert);
  455. }
  456. catch(Exception $e)
  457. {
  458. if ($sNoStopOnImportError == '1')
  459. {
  460. $iCountErrors++;
  461. $oP->add("$iRow: Import error '".$e->getMessage()."' (continuing)...\n");
  462. }
  463. else // Fatal error
  464. {
  465. throw $e;
  466. }
  467. }
  468. }
  469. elseif ($iCount == 1)
  470. {
  471. // Found a match... update it
  472. //
  473. $iCountUpdates++;
  474. if ($sOutput == 'details')
  475. {
  476. $oP->add("$iRow: Update entry, reconciliation: '$sReconciliationCondition'\n");
  477. }
  478. $aValuePairs = array(); // Used to build the update query
  479. foreach ($aRow as $iCol => $value)
  480. {
  481. // Skip reconciliation column
  482. if ($iCol == $iPrimaryKeyCol) continue;
  483. $sCol = $aInputColumns[$iCol];
  484. if ($aIsDateToTransform[$iCol])
  485. {
  486. $sDate = ChangeDateFormat($aRow[$iCol], $sDateFormat);
  487. if ($sDate === false)
  488. {
  489. // Skip this column spec
  490. if ($sOutput == 'details')
  491. {
  492. $oP->add("$iRow: Wrong format for date field: '".$aRow[$iCol]."' (skipped column)\n");
  493. }
  494. }
  495. else
  496. {
  497. $aValuePairs[] = "`$sCol` = ".CMDBSource::Quote($sDate);
  498. }
  499. }
  500. else
  501. {
  502. $aValuePairs[] = "`$sCol` = ".CMDBSource::Quote($aRow[$iCol]);
  503. }
  504. }
  505. $sValuePairs = implode(', ', $aValuePairs);
  506. $sUpdateQuery = "UPDATE `$sTable` SET $sValuePairs WHERE $sReconciliationCondition";
  507. try
  508. {
  509. CMDBSource::Query($sUpdateQuery);
  510. }
  511. catch(Exception $e)
  512. {
  513. if ($sNoStopOnImportError == '1')
  514. {
  515. $iCountErrors++;
  516. $oP->add("$iRow: Import error '".$e->getMessage()."' (continuing)...\n");
  517. }
  518. else // Fatal error
  519. {
  520. throw $e;
  521. }
  522. }
  523. }
  524. else
  525. {
  526. // Too many records... ambiguity
  527. //
  528. $iCountErrors++;
  529. $oP->add("$iRow: Error - Failed to reconcile, found $iCount rows having '$sReconciliationCondition'\n");
  530. }
  531. }
  532. if (($sOutput == "summary") || ($sOutput == 'details'))
  533. {
  534. $oP->add_comment("Data Source: ".$iDataSourceId);
  535. $oP->add_comment("Synchronize: ".($bSynchronize ? '1' : '0'));
  536. $oP->add_comment("Class: ".$sClass);
  537. $oP->add_comment("Separator: ".$sSep);
  538. $oP->add_comment("Qualifier: ".$sQualifier);
  539. $oP->add_comment("Charset Encoding:".$sCharSet);
  540. if (strlen($sDateFormat) > 0)
  541. {
  542. $oP->add_comment("Date format: '$sDateFormat', applied to columns {".implode(', ', $aDateToTransformReport)."}");
  543. }
  544. else
  545. {
  546. $oP->add_comment("Date format: <none>");
  547. }
  548. $oP->add_comment("Data Size: ".strlen($sCSVData));
  549. $oP->add_comment("Data Lines: ".$iLineCount);
  550. $oP->add_comment("Columns: ".implode(', ', $aInputColumns));
  551. $oP->add_comment("Output format: ".$sOutput);
  552. // $oP->add_comment("Report level: ".$sReportLevel);
  553. $oP->add_comment("Simulate: ".($bSimulate ? '1' : '0'));
  554. $oP->add_comment("Change tracking comment: ".$sComment);
  555. $oP->add_comment("Issues (before synchro): ".$iCountErrors);
  556. // $oP->add_comment("Warnings: ".$iCountWarnings);
  557. $oP->add_comment("Created (before synchro): ".$iCountCreations);
  558. $oP->add_comment("Updated (before synchro): ".$iCountUpdates);
  559. }
  560. //////////////////////////////////////////////////
  561. //
  562. // Synchronize
  563. //
  564. if ($bSynchronize)
  565. {
  566. $oStatLog = $oDataSource->Synchronize($oLoadStartDate);
  567. $oP->add_comment('Synchronization---');
  568. $oP->add_comment('------------------');
  569. if ($sOutput == 'details')
  570. {
  571. foreach ($oStatLog->GetTraces() as $sMessage)
  572. {
  573. $oP->add_comment($sMessage);
  574. }
  575. }
  576. if ($oStatLog->Get('status') == 'error')
  577. {
  578. $oP->p("ERROR: ".$oStatLog->Get('last_error'));
  579. }
  580. $oP->add_comment("Replicas: ".$oStatLog->Get('stats_nb_replica_total'));
  581. $oP->add_comment("Replicas touched since last synchro: ".$oStatLog->Get('stats_nb_replica_seen'));
  582. $oP->add_comment("Objects deleted: ".$oStatLog->Get('stats_nb_obj_deleted'));
  583. $oP->add_comment("Objects deletion errors: ".$oStatLog->Get('stats_nb_obj_deleted_errors'));
  584. $oP->add_comment("Objects obsoleted: ".$oStatLog->Get('stats_nb_obj_obsoleted'));
  585. $oP->add_comment("Objects obsolescence errors: ".$oStatLog->Get('stats_nb_obj_obsoleted_errors'));
  586. $oP->add_comment("Objects created: ".$oStatLog->Get('stats_nb_obj_created'));
  587. $oP->add_comment("Objects creation errors: ".$oStatLog->Get('stats_nb_obj_created_errors'));
  588. $oP->add_comment("Objects updated: ".$oStatLog->Get('stats_nb_obj_updated'));
  589. $oP->add_comment("Objects update errors: ".$oStatLog->Get('stats_nb_obj_updated_errors'));
  590. $oP->add_comment("Objects reconciled (updated): ".$oStatLog->Get('stats_nb_obj_new_updated'));
  591. $oP->add_comment("Objects reconciled (unchanged): ".$oStatLog->Get('stats_nb_obj_new_unchanged'));
  592. $oP->add_comment("Objects reconciliation errors: ".$oStatLog->Get('stats_nb_replica_reconciled_errors'));
  593. $oP->add_comment("Replica disappeared, no action taken: ".$oStatLog->Get('stats_nb_replica_disappeared_no_action'));
  594. }
  595. }
  596. catch(Exception $e)
  597. {
  598. if ($bSimulate)
  599. {
  600. CMDBSource::Query('ROLLBACK');
  601. }
  602. throw $e;
  603. }
  604. if ($bSimulate)
  605. {
  606. CMDBSource::Query('ROLLBACK');
  607. }
  608. //////////////////////////////////////////////////
  609. //
  610. // Summary of settings and results
  611. //
  612. if ($sOutput == 'retcode')
  613. {
  614. $oP->add($iCountErrors);
  615. }
  616. }
  617. catch(ExchangeException $e)
  618. {
  619. $oP->add_comment($e->getMessage());
  620. }
  621. catch(SecurityException $e)
  622. {
  623. $oP->add_comment($e->getMessage());
  624. }
  625. catch(Exception $e)
  626. {
  627. $oP->add_comment((string)$e);
  628. }
  629. $oP->output();
  630. ?>