synchrodatasource.class.inc.php 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  1. <?php
  2. // Copyright (C) 2010 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 - synchronization with external applications (incoming data)
  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. class SynchroExceptionNotStarted extends CoreException
  25. {
  26. }
  27. class SynchroDataSource extends cmdbAbstractObject
  28. {
  29. public static function Init()
  30. {
  31. $aParams = array
  32. (
  33. "category" => "core/cmdb,view_in_gui",
  34. "key_type" => "autoincrement",
  35. "name_attcode" => array('name'),
  36. "state_attcode" => "",
  37. "reconc_keys" => array(),
  38. "db_table" => "priv_sync_datasource",
  39. "db_key_field" => "id",
  40. "db_finalclass_field" => "realclass",
  41. "display_template" => "",
  42. "icon" => "../images/synchro.png",
  43. );
  44. MetaModel::Init_Params($aParams);
  45. //MetaModel::Init_InheritAttributes();
  46. MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  47. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  48. MetaModel::Init_AddAttribute(new AttributeEnum("status", array("allowed_values"=>new ValueSetEnum('implementation,production,obsolete'), "sql"=>"status", "default_value"=>"implementation", "is_null_allowed"=>false, "depends_on"=>array())));
  49. MetaModel::Init_AddAttribute(new AttributeExternalKey("user_id", array("targetclass"=>"User", "jointype"=>null, "allowed_values"=>null, "sql"=>"user_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  50. MetaModel::Init_AddAttribute(new AttributeClass("scope_class", array("class_category"=>"bizmodel,addon/authentication", "more_values"=>"", "sql"=>"scope_class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  51. // Declared here for a future usage, but ignored so far
  52. MetaModel::Init_AddAttribute(new AttributeString("scope_restriction", array("allowed_values"=>null, "sql"=>"scope_restriction", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  53. //MetaModel::Init_AddAttribute(new AttributeDateTime("last_synchro_date", array("allowed_values"=>null, "sql"=>"last_synchro_date", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  54. // Format: seconds (int)
  55. MetaModel::Init_AddAttribute(new AttributeDuration("full_load_periodicity", array("allowed_values"=>null, "sql"=>"full_load_periodicity", "default_value"=>86400, "is_null_allowed"=>true, "depends_on"=>array())));
  56. // MetaModel::Init_AddAttribute(new AttributeString("reconciliation_list", array("allowed_values"=>null, "sql"=>"reconciliation_list", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  57. MetaModel::Init_AddAttribute(new AttributeEnum("reconciliation_policy", array("allowed_values"=>new ValueSetEnum('use_primary_key,use_attributes'), "sql"=>"reconciliation_policy", "default_value"=>"use_attributes", "is_null_allowed"=>false, "depends_on"=>array())));
  58. MetaModel::Init_AddAttribute(new AttributeEnum("action_on_zero", array("allowed_values"=>new ValueSetEnum('create,error'), "sql"=>"action_on_zero", "default_value"=>"create", "is_null_allowed"=>false, "depends_on"=>array())));
  59. MetaModel::Init_AddAttribute(new AttributeEnum("action_on_one", array("allowed_values"=>new ValueSetEnum('update,error'), "sql"=>"action_on_one", "default_value"=>"update", "is_null_allowed"=>false, "depends_on"=>array())));
  60. MetaModel::Init_AddAttribute(new AttributeEnum("action_on_multiple", array("allowed_values"=>new ValueSetEnum('take_first,create,error'), "sql"=>"action_on_multiple", "default_value"=>"error", "is_null_allowed"=>false, "depends_on"=>array())));
  61. MetaModel::Init_AddAttribute(new AttributeEnum("delete_policy", array("allowed_values"=>new ValueSetEnum('ignore,delete,update,update_then_delete'), "sql"=>"delete_policy", "default_value"=>"ignore", "is_null_allowed"=>false, "depends_on"=>array())));
  62. MetaModel::Init_AddAttribute(new AttributeString("delete_policy_update", array("allowed_values"=>null, "sql"=>"delete_policy_update", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  63. // Format: seconds (unsigned int)
  64. MetaModel::Init_AddAttribute(new AttributeDuration("delete_policy_retention", array("allowed_values"=>null, "sql"=>"delete_policy_retention", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  65. MetaModel::Init_AddAttribute(new AttributeLinkedSet("attribute_list", array("linked_class"=>"SynchroAttribute", "ext_key_to_me"=>"sync_source_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
  66. // Not used yet !
  67. MetaModel::Init_AddAttribute(new AttributeEnum("user_delete_policy", array("allowed_values"=>new ValueSetEnum('never,depends,always'), "sql"=>"user_delete_policy", "default_value"=>"always", "is_null_allowed"=>true, "depends_on"=>array())));
  68. MetaModel::Init_AddAttribute(new AttributeURL("url_icon", array("allowed_values"=>null, "sql"=>"url_icon", "default_value"=>null, "is_null_allowed"=>true, "target"=> '_top', "depends_on"=>array())));
  69. // The field below is not a real URL since it can contain placeholders like $replica->primary_key$ which are not syntactically allowed in a real URL
  70. MetaModel::Init_AddAttribute(new AttributeString("url_application", array("allowed_values"=>null, "sql"=>"url_application", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  71. // Display lists
  72. MetaModel::Init_SetZListItems('details', array('name', 'description', 'url_icon', 'url_application', 'scope_class', /*'scope_restriction', */'status', 'user_id', 'full_load_periodicity', 'reconciliation_policy', 'action_on_zero', 'action_on_one', 'action_on_multiple', 'delete_policy', 'delete_policy_update', 'delete_policy_retention' /*'attribute_list'*/)); // Attributes to be displayed for the complete details
  73. MetaModel::Init_SetZListItems('list', array('scope_class', 'status', 'user_id', 'full_load_periodicity')); // Attributes to be displayed for a list
  74. // Search criteria
  75. MetaModel::Init_SetZListItems('standard_search', array('name', 'status', 'scope_class', 'user_id')); // Criteria of the std search form
  76. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  77. }
  78. public function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
  79. {
  80. if (!$this->IsNew())
  81. {
  82. $oPage->SetCurrentTab(Dict::S('Core:SynchroAttributes'));
  83. $oAttributeSet = $this->Get('attribute_list');
  84. $aAttributes = array();
  85. while($oAttribute = $oAttributeSet->Fetch())
  86. {
  87. $aAttributes[$oAttribute->Get('attcode')] = $oAttribute;
  88. }
  89. // Columns of the form
  90. $aAttribs = array();
  91. foreach(array('attcode', 'reconciliation', 'update', 'update_policy', 'reconciliation_attcode') as $s )
  92. {
  93. $aAttribs[$s] = array( 'label' => Dict::S("Core:SynchroAtt:$s"), "description" => Dict::S("Core:SynchroAtt:$s+"));
  94. }
  95. // Rows of the form
  96. $aValues = array();
  97. foreach(MetaModel::ListAttributeDefs($this->GetTargetClass()) as $sAttCode=>$oAttDef)
  98. {
  99. if ($oAttDef->IsScalar() && $oAttDef->IsWritable())
  100. {
  101. if (isset($aAttributes[$sAttCode]))
  102. {
  103. $oAttribute = $aAttributes[$sAttCode];
  104. }
  105. else
  106. {
  107. if ($oAttDef->IsExternalKey())
  108. {
  109. $oAttribute = new SynchroAttExtKey();
  110. $oAttribute->Set('reconciliation_attcode', ''); // Blank means by pkey
  111. }
  112. else
  113. {
  114. $oAttribute = new SynchroAttribute();
  115. }
  116. $oAttribute->Set('sync_source_id', $this->GetKey());
  117. $oAttribute->Set('attcode', $sAttCode);
  118. $oAttribute->Set('reconcile', MetaModel::IsReconcKey($this->GetTargetClass(), $sAttCode) ? 1 : 0);
  119. $oAttribute->Set('update', 1);
  120. $oAttribute->Set('update_policy', 'master_locked');
  121. }
  122. if (!$bEditMode)
  123. {
  124. // Read-only mode
  125. $aRow['reconciliation'] = $oAttribute->Get('reconcile') == 1 ? Dict::S('Core:SynchroReconcile:Yes') : Dict::S('Core:SynchroReconcile:No');
  126. $aRow['update'] = $oAttribute->Get('update') == 1 ? Dict::S('Core:SynchroUpdate:Yes') : Dict::S('Core:SynchroUpdate:No');
  127. $aRow['attcode'] = MetaModel::GetLabel($this->GetTargetClass(), $oAttribute->Get('attcode'));
  128. $aRow['update_policy'] = $oAttribute->GetAsHTML('update_policy');
  129. if ($oAttDef->IsExternalKey())
  130. {
  131. $aRow['reconciliation_attcode'] = $oAttribute->GetAsHTML('reconciliation_attcode');
  132. }
  133. else
  134. {
  135. $aRow['reconciliation_attcode'] = '&nbsp;';
  136. }
  137. }
  138. else
  139. {
  140. // Edit mode
  141. $sAttCode = $oAttribute->Get('attcode');
  142. $sChecked = $oAttribute->Get('reconcile') == 1 ? 'checked' : '';
  143. $aRow['reconciliation'] = "<input type=\"checkbox\" name=\"reconciliation[$sAttCode]\" $sChecked/>";
  144. $sChecked = $oAttribute->Get('update') == 1 ? 'checked' : '';
  145. $aRow['update'] = "<input type=\"checkbox\" name=\"update[$sAttCode]\" $sChecked/>";
  146. $aRow['attcode'] = MetaModel::GetLabel($this->GetTargetClass(), $oAttribute->Get('attcode'));
  147. $oUpdateAttDef = MetaModel::GetAttributeDef(get_class($oAttribute), 'update_policy');
  148. $aRow['update_policy'] = cmdbAbstractObject::GetFormElementForField($oPage, get_class($oAttribute), 'update_policy', $oUpdateAttDef, $oAttribute->Get('update_policy'), '', 'update_policy_'.$sAttCode, "[$sAttCode]");
  149. if ($oAttDef->IsExternalKey())
  150. {
  151. $aRow['reconciliation_attcode'] = $oAttribute->GetReconciliationFormElement($oAttDef->GetTargetClass(), "attr_reconciliation_attcode[$sAttCode]");
  152. }
  153. else
  154. {
  155. $aRow['reconciliation_attcode'] = '&nbsp;';
  156. }
  157. }
  158. $aValues[] = $aRow;
  159. }
  160. }
  161. $oPage->p(Dict::Format('Class:SynchroDataSource:DataTable', $this->GetDataTable()));
  162. $oPage->Table($aAttribs, $aValues);
  163. $this->DisplayStatusTab($oPage);
  164. }
  165. parent::DisplayBareRelations($oPage, $bEditMode);
  166. }
  167. /**
  168. * Displays the status (SynchroLog) of the datasource in a graphical manner
  169. * @param $oPage WebPage
  170. * @return void
  171. */
  172. protected function DisplayStatusTab(WebPage $oPage)
  173. {
  174. $oPage->SetCurrentTab(Dict::S('Core:SynchroStatus'));
  175. $sSelectSynchroLog = 'SELECT SynchroLog WHERE sync_source_id = :source_id';
  176. $oSetSynchroLog = new CMDBObjectSet(DBObjectSearch::FromOQL($sSelectSynchroLog), array('start_date' => false) /* order by*/, array('source_id' => $this->GetKey()));
  177. if ($oSetSynchroLog->Count() > 0)
  178. {
  179. $oLastLog = $oSetSynchroLog->Fetch();
  180. $sStartDate = $oLastLog->Get('start_date');
  181. $oLastLog->Get('stats_nb_replica_seen');
  182. $iLastLog = 0;
  183. $iDSid = $this->GetKey();
  184. if ($oLastLog->Get('status') == 'running')
  185. {
  186. // Still running !
  187. $oPage->p('<h2>'.Dict::Format('Core:Synchro:SynchroRunningStartedOn_Date', $sStartDate).'</h2>');
  188. }
  189. else
  190. {
  191. $sEndDate = $oLastLog->Get('end_date');
  192. $iLastLog = $oLastLog->GetKey();
  193. $oPage->p('<h2>'.Dict::Format('Core:Synchro:SynchroEndedOn_Date', $sEndDate).'</h2>');
  194. }
  195. $oPage->add('<table class="synoptics"><tr><td style="color:#333;vertical-align:top">');
  196. // List all the log entries for the user to select
  197. $oPage->add('<h2 style="line-height:55px;">'.Dict::S('Core:Synchro:History').'</h2>');
  198. $oSetSynchroLog->Rewind();
  199. $oPage->add('<select size="25" onChange="UpdateSynoptics(this.value);">');
  200. $sSelected = ' selected'; // First log is selected by default
  201. $sScript = "var aSynchroLog = {\n";
  202. while($oLog = $oSetSynchroLog->Fetch())
  203. {
  204. $sLogTitle = Dict::Format('Core:SynchroLogTitle', $oLog->Get('status'), $oLog->Get('start_date'));
  205. $oPage->add('<option value="'.$oLog->GetKey().'"'.$sSelected.'>'.$sLogTitle.'</option>');
  206. $sSelected = ''; // only the first log is selected by default
  207. $aData = $this->ProcessLog($oLog);
  208. $sScript .= '"'.$oLog->GetKey().'": '.json_encode($aData).",\n";
  209. }
  210. $sScript .= "end: 'Done'";
  211. $sScript .= "};\n";
  212. $sScript .= <<<EOF
  213. var sLastLog = '$iLastLog';
  214. function UpdateSynoptics(id)
  215. {
  216. var aValues = aSynchroLog[id];
  217. for (var sKey in aValues)
  218. {
  219. $('#c_'+sKey).html(aValues[sKey]);
  220. var fOpacity = (aValues[sKey] == 0) ? 0.3 : 1;
  221. $('#'+sKey).fadeTo("slow", fOpacity);
  222. }
  223. //alert('id = '+id+', lastLog='+sLastLog+', id==sLastLog: '+(id==sLastLog)+' obj_updated_errors: '+aValues['obj_updated_errors']);
  224. if ( (id == sLastLog) && (aValues['obj_new_errors'] > 0) )
  225. {
  226. $('#new_errors_link').show();
  227. }
  228. else
  229. {
  230. $('#new_errors_link').hide();
  231. }
  232. if ( (id == sLastLog) && (aValues['obj_updated_errors'] > 0) )
  233. {
  234. $('#updated_errors_link').show();
  235. }
  236. else
  237. {
  238. $('#updated_errors_link').hide();
  239. }
  240. if ( (id == sLastLog) && (aValues['obj_disappeared_errors'] > 0) )
  241. {
  242. $('#disappeared_errors_link').show();
  243. }
  244. else
  245. {
  246. $('#disappeared_errors_link').hide();
  247. }
  248. }
  249. EOF
  250. ;
  251. $oPage->add_script($sScript);
  252. $oPage->add('</select>');
  253. $oPage->add('</td><td style="vertical-align:top;">');
  254. // Now build the big "synoptics" view
  255. $aData = $this->ProcessLog($oLastLog);
  256. $sNbReplica = $this->GetIcon()."&nbsp;".Dict::Format('Core:Synchro:Nb_Replica', "<span id=\"c_nb_replica_total\">{$aData['nb_replica_total']}</span>");
  257. $sNbObjects = MetaModel::GetClassIcon($this->GetTargetClass())."&nbsp;".Dict::Format('Core:Synchro:Nb_Class:Objects', $this->GetTargetClass(), "<span id=\"c_nb_obj_total\">{$aData['nb_obj_total']}</span>");
  258. $oPage->add(
  259. <<<EOF
  260. <table class="synoptics">
  261. <tr class="synoptics_header">
  262. <td>$sNbReplica</td><td>&nbsp;</td><td>$sNbObjects</td>
  263. </tr>
  264. <tr>
  265. EOF
  266. );
  267. $sBaseOQL = "SELECT SynchroReplica WHERE sync_source_id=".$this->GetKey()." AND status_last_error!=''";
  268. $oPage->add($this->HtmlBox('repl_ignored', $aData, '#999').'<td colspan="2">&nbsp;</td>');
  269. $oPage->add("</tr>\n<tr>");
  270. $oPage->add($this->HtmlBox('repl_disappeared', $aData, '#630', 'rowspan="4"').'<td rowspan="4" class="arrow">=&gt;</td>'.$this->HtmlBox('obj_disappeared_no_action', $aData, '#333'));
  271. $oPage->add("</tr>\n<tr>");
  272. $oPage->add($this->HtmlBox('obj_deleted', $aData, '#000'));
  273. $oPage->add("</tr>\n<tr>");
  274. $oPage->add($this->HtmlBox('obj_obsoleted', $aData, '#630'));
  275. $oPage->add("</tr>\n<tr>");
  276. $sOQL = urlencode($sBaseOQL." AND status='obsolete'");
  277. $oPage->add($this->HtmlBox('obj_disappeared_errors', $aData, '#C00', '', " <a style=\"color:#fff\" href=\"../synchro/replica.php?operation=oql&datasource=$iDSid&oql=$sOQL\" id=\"disappeared_errors_link\">Show</a>"));
  278. $oPage->add("</tr>\n<tr>");
  279. $oPage->add($this->HtmlBox('repl_existing', $aData, '#093', 'rowspan="3"').'<td rowspan="3" class="arrow">=&gt;</td>'.$this->HtmlBox('obj_unchanged', $aData, '#393'));
  280. $oPage->add("</tr>\n<tr>");
  281. $oPage->add($this->HtmlBox('obj_updated', $aData, '#3C3'));
  282. $oPage->add("</tr>\n<tr>");
  283. $sOQL = urlencode($sBaseOQL." AND status='modified'");
  284. $oPage->add($this->HtmlBox('obj_updated_errors', $aData, '#C00', '', " <a style=\"color:#fff\" href=\"../synchro/replica.php?operation=oql&datasource=$iDSid&oql=$sOQL\" id=\"updated_errors_link\">Show</a>"));
  285. $oPage->add("</tr>\n<tr>");
  286. $oPage->add($this->HtmlBox('repl_new', $aData, '#339', 'rowspan="4"').'<td rowspan="4" class="arrow">=&gt;</td>'.$this->HtmlBox('obj_new_unchanged', $aData, '#393'));
  287. $oPage->add("</tr>\n<tr>");
  288. $oPage->add($this->HtmlBox('obj_new_updated', $aData, '#3C3'));
  289. $oPage->add("</tr>\n<tr>");
  290. $oPage->add($this->HtmlBox('obj_created', $aData, '#339'));
  291. $oPage->add("</tr>\n<tr>");
  292. $sOQL = urlencode($sBaseOQL." AND status='new'");
  293. $oPage->add($this->HtmlBox('obj_new_errors', $aData, '#C00', '', " <a style=\"color:#fff\" href=\"../synchro/replica.php?operation=oql&datasource=$iDSid&oql=$sOQL\" id=\"new_errors_link\">Show</a>"));
  294. $oPage->add("</tr>\n</table>\n");
  295. $oPage->add('</td></tr></table>');
  296. $oPage->add_ready_script("UpdateSynoptics('$iLastLog')");
  297. }
  298. else
  299. {
  300. $oPage->p('<h2>'.Dict::S('Core:Synchro:NeverRun').'</h2>');
  301. }
  302. }
  303. protected function HtmlBox($sId, $aData, $sColor, $sHTMLAttribs = '', $sErrorLink = '')
  304. {
  305. $iCount = $aData[$sId];
  306. $sCount = "<span id=\"c_{$sId}\">$iCount</span>";
  307. $sLabel = Dict::Format('Core:Synchro:label_'.$sId, $sCount);
  308. $sOpacity = ($iCount==0) ? "opacity:0.3;" : "";
  309. return "<td id=\"$sId\" style=\"background-color:$sColor;$sOpacity;\" {$sHTMLAttribs}>{$sLabel}{$sErrorLink}</td>";
  310. }
  311. protected function ProcessLog($oLastLog)
  312. {
  313. $aData = array(
  314. 'obj_deleted' => $oLastLog->Get('stats_nb_obj_deleted'),
  315. 'obj_obsoleted' => $oLastLog->Get('stats_nb_obj_obsoleted'),
  316. 'obj_disappeared_errors' => $oLastLog->Get('stats_nb_obj_obsoleted_errors') + $oLastLog->Get('stats_nb_obj_deleted_errors'),
  317. 'obj_disappeared_no_action' => $oLastLog->Get('stats_nb_replica_disappeared_no_action'),
  318. 'obj_updated' => $oLastLog->Get('stats_nb_obj_updated'),
  319. 'obj_updated_errors' => $oLastLog->Get('stats_nb_obj_updated_errors'),
  320. 'obj_new_updated' => $oLastLog->Get('stats_nb_obj_new_updated'),
  321. 'obj_new_unchanged' => $oLastLog->Get('stats_nb_obj_new_unchanged'),
  322. 'obj_created' => $oLastLog->Get('stats_nb_obj_created'),
  323. 'obj_created_errors' => $oLastLog->Get('stats_nb_obj_created_errors'),
  324. );
  325. $iReconciledErrors = $oLastLog->Get('stats_nb_replica_reconciled_errors');
  326. $iDisappeared = $aData['obj_disappeared_errors'] + $aData['obj_obsoleted'] + $aData['obj_deleted'] + $aData['obj_disappeared_no_action'];
  327. $aData['repl_disappeared'] = $iDisappeared;
  328. $iNewErrors = $aData['obj_created_errors'] + $oLastLog->Get('stats_nb_replica_reconciled_errors');
  329. $aData['obj_new_errors'] = $iNewErrors;
  330. $iNew = $aData['obj_created'] + $iNewErrors + $aData['obj_new_updated'] + $aData['obj_new_unchanged'];
  331. $aData['repl_new'] = $iNew;
  332. $iExisting = $oLastLog->Get('stats_nb_replica_seen') - $iNew;
  333. $aData['repl_existing'] = $iExisting;
  334. $aData['obj_unchanged'] = $iExisting - $aData['obj_updated'] - $aData['obj_updated_errors'];
  335. $iIgnored = $oLastLog->Get('stats_nb_replica_total') - $iNew - $iExisting - $iDisappeared;
  336. $aData['repl_ignored'] = $iIgnored;
  337. $aData['nb_obj_total'] = $iNew + $iExisting + $iDisappeared;
  338. $aData['nb_replica_total'] = $aData['nb_obj_total'] + $iIgnored;
  339. return $aData;
  340. }
  341. public function GetIcon($bImgTag = true, $sMoreStyles = '')
  342. {
  343. if ($this->Get('url_icon') == '') return MetaModel::GetClassIcon(get_class($this), $bImgTag);
  344. if ($bImgTag)
  345. {
  346. return "<img src=\"".$this->Get('url_icon')."\" style=\"vertical-align:middle;$sMoreStyles\"/>";
  347. }
  348. return $this->Get('url_icon');
  349. }
  350. /**
  351. * Get the actual hyperlink to the remote application for the given replica and dest object
  352. */
  353. public function GetApplicationUrl(DBObject $oDestObj, SynchroReplica $oReplica)
  354. {
  355. if ($this->Get('url_application') == '') return '';
  356. $aSearches = array();
  357. $aReplacements = array();
  358. foreach(MetaModel::ListAttributeDefs($this->GetTargetClass()) as $sAttCode=>$oAttDef)
  359. {
  360. if ($oAttDef->IsScalar())
  361. {
  362. $aSearches[] = '$this->'.$sAttCode.'$';
  363. $aReplacements[] = $oDestObj->Get($sAttCode);
  364. }
  365. }
  366. $aData = $oReplica->LoadExtendedDataFromTable($this->GetDataTable());
  367. foreach($aData as $sColumn => $value)
  368. {
  369. $aSearches[] = '$replica->'.$sColumn.'$';
  370. $aReplacements[] = $value;
  371. }
  372. return str_replace($aSearches, $aReplacements, $this->Get('url_application'));
  373. }
  374. public function GetAttributeFlags($sAttCode)
  375. {
  376. if (($sAttCode == 'scope_class') && (!$this->IsNew()))
  377. {
  378. return OPT_ATT_READONLY;
  379. }
  380. return parent::GetAttributeFlags($sAttCode);
  381. }
  382. public function UpdateObject($sFormPrefix = '')
  383. {
  384. parent::UpdateObject($sFormPrefix);
  385. // And now read the other post parameters...
  386. $oAttributeSet = $this->Get('attribute_list');
  387. $aAttributes = array();
  388. while($oAttribute = $oAttributeSet->Fetch())
  389. {
  390. $aAttributes[$oAttribute->Get('attcode')] = $oAttribute;
  391. }
  392. $aReconcile = utils::ReadPostedParam('reconciliation', array());
  393. $aUpdate = utils::ReadPostedParam('update', array());
  394. $aUpdatePolicy = utils::ReadPostedParam('attr_update_policy', array());
  395. $aReconciliation = utils::ReadPostedParam('attr_reconciliation_attcode', array());
  396. // update_policy cannot be empty, so there is one entry per attribute, use this to iterate
  397. // through all the writable attributes
  398. foreach($aUpdatePolicy as $sAttCode => $sValue)
  399. {
  400. if(!isset($aAttributes[$sAttCode]))
  401. {
  402. $oAttDef = MetaModel::GetAttributeDef($this->GetTargetClass(), $sAttCode);
  403. if ($oAttDef->IsExternalKey())
  404. {
  405. $oAttribute = new SynchroAttExtKey();
  406. $oAttribute->Set('reconciliation_attcode', ''); // Blank means by pkey
  407. }
  408. else
  409. {
  410. $oAttribute = new SynchroAttribute();
  411. }
  412. $oAttribute->Set('sync_source_id', $this->GetKey());
  413. $oAttribute->Set('attcode', $sAttCode);
  414. }
  415. else
  416. {
  417. $oAttribute = $aAttributes[$sAttCode];
  418. }
  419. $bReconcile = 0;
  420. if (isset($aReconcile[$sAttCode]))
  421. {
  422. $bReconcile = $aReconcile[$sAttCode] == 'on' ? 1 : 0;
  423. }
  424. $bUpdate = 0 ; // Default / initial value
  425. if (isset($aUpdate[$sAttCode]))
  426. {
  427. $bUpdate = $aUpdate[$sAttCode] == 'on' ? 1 : 0;
  428. }
  429. $oAttribute->Set('reconcile', $bReconcile);
  430. $oAttribute->Set('update', $bUpdate);
  431. $oAttribute->Set('update_policy', $sValue);
  432. if ($oAttribute instanceof SynchroAttExtKey)
  433. {
  434. $oAttribute->Set('reconciliation_attcode', $aReconciliation[$sAttCode]);
  435. }
  436. $oAttributeSet->AddObject($oAttribute);
  437. }
  438. $this->Set('attribute_list', $oAttributeSet);
  439. }
  440. /*
  441. * Overload the standard behavior
  442. */
  443. public function ComputeValues()
  444. {
  445. parent::ComputeValues();
  446. if ($this->IsNew())
  447. {
  448. // When inserting a new datasource object, also create the SynchroAttribute objects
  449. // for each field of the target class
  450. // Create all the SynchroAttribute records
  451. $oAttributeSet = $this->Get('attribute_list');
  452. if ($oAttributeSet->Count() == 0)
  453. {
  454. foreach(MetaModel::ListAttributeDefs($this->GetTargetClass()) as $sAttCode=>$oAttDef)
  455. {
  456. if ($oAttDef->IsScalar() && $oAttDef->IsWritable())
  457. {
  458. $oAttDef = MetaModel::GetAttributeDef($this->GetTargetClass(), $sAttCode);
  459. if ($oAttDef->IsExternalKey())
  460. {
  461. $oAttribute = new SynchroAttExtKey();
  462. $oAttribute->Set('reconciliation_attcode', ''); // Blank means by pkey
  463. }
  464. else
  465. {
  466. $oAttribute = new SynchroAttribute();
  467. }
  468. $oAttribute->Set('sync_source_id', $this->GetKey());
  469. $oAttribute->Set('attcode', $sAttCode);
  470. $oAttribute->Set('reconcile', MetaModel::IsReconcKey($this->GetTargetClass(), $sAttCode) ? 1 : 0);
  471. $oAttribute->Set('update', 1);
  472. $oAttribute->Set('update_policy', 'master_locked');
  473. $oAttributeSet->AddObject($oAttribute);
  474. }
  475. }
  476. $this->Set('attribute_list', $oAttributeSet);
  477. }
  478. }
  479. }
  480. public function DoCheckToWrite()
  481. {
  482. parent::DoCheckToWrite();
  483. // Check that there is at least one reconciliation key defined
  484. if ($this->Get('reconciliation_policy') == 'use_attributes')
  485. {
  486. $oSet = $this->Get('attribute_list');
  487. $oSynchroAttributeList = $oSet->ToArray();
  488. $bReconciliationKey = false;
  489. foreach($oSynchroAttributeList as $oSynchroAttribute)
  490. {
  491. if ($oSynchroAttribute->Get('reconcile') == 1)
  492. {
  493. $bReconciliationKey = true; // At least one key is defined
  494. }
  495. }
  496. if (!$bReconciliationKey)
  497. {
  498. $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:AtLeastOneReconciliationKeyMustBeSpecified');
  499. }
  500. }
  501. // If 'update_then_delete' is specified there must be a delete_retention_period
  502. if (($this->Get('delete_policy') == 'update_then_delete') && ($this->Get('delete_policy_retention') == 0))
  503. {
  504. $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:DeleteRetentionDurationMustBeSpecified');
  505. }
  506. // If update is specified, then something to update must be defined
  507. if ((($this->Get('delete_policy') == 'update_then_delete') || ($this->Get('delete_policy') == 'update'))
  508. && ($this->Get('delete_policy_update') == ''))
  509. {
  510. $this->m_aCheckIssues[] = Dict::Format('Class:SynchroDataSource/Error:DeletePolicyUpdateMustBeSpecified');
  511. }
  512. }
  513. public function GetTargetClass()
  514. {
  515. return $this->Get('scope_class');
  516. }
  517. public function GetDataTable()
  518. {
  519. $sName = strtolower($this->GetTargetClass());
  520. $sName = str_replace('\'"&@|\\/ ', '_', $sName); // Remove forbidden characters from the table name
  521. $sName .= '_'.$this->GetKey(); // Add a suffix for unicity
  522. $sTable = MetaModel::GetConfig()->GetDBSubName()."synchro_data_$sName"; // Add the prefix if any
  523. return $sTable;
  524. }
  525. /**
  526. * When the new datasource has been created, let's create the synchro_data table
  527. * that will hold the data records and the correspoding triggers which will maintain
  528. * both tables in sync
  529. */
  530. protected function AfterInsert()
  531. {
  532. parent::AfterInsert();
  533. $sTable = $this->GetDataTable();
  534. $aColumns = $this->GetSQLColumns();
  535. $aFieldDefs = array();
  536. // Allow '0', otherwise mysql will render an error when the id is not given
  537. // (the trigger is expected to set the value, but it is not executed soon enough)
  538. $aFieldDefs[] = "id INTEGER(11) NOT NULL DEFAULT 0 ";
  539. $aFieldDefs[] = "`primary_key` VARCHAR(255) NULL DEFAULT NULL";
  540. foreach($aColumns as $sColumn => $ColSpec)
  541. {
  542. $aFieldDefs[] = "`$sColumn` $ColSpec NULL DEFAULT NULL";
  543. }
  544. $aFieldDefs[] = "INDEX (id)";
  545. $aFieldDefs[] = "INDEX (primary_key)";
  546. $sFieldDefs = implode(', ', $aFieldDefs);
  547. $sCreateTable = "CREATE TABLE `$sTable` ($sFieldDefs) ENGINE = innodb;";
  548. CMDBSource::Query($sCreateTable);
  549. $sTriggerInsert = "CREATE TRIGGER `{$sTable}_bi` BEFORE INSERT ON $sTable";
  550. $sTriggerInsert .= " FOR EACH ROW";
  551. $sTriggerInsert .= " BEGIN";
  552. $sTriggerInsert .= " INSERT INTO priv_sync_replica (sync_source_id, status_last_seen, `status`) VALUES ({$this->GetKey()}, NOW(), 'new');";
  553. $sTriggerInsert .= " SET NEW.id = LAST_INSERT_ID();";
  554. $sTriggerInsert .= " END;";
  555. CMDBSource::Query($sTriggerInsert);
  556. $aModified = array();
  557. foreach($aColumns as $sColumn => $ColSpec)
  558. {
  559. // <=> is a null-safe 'EQUALS' operator (there is no equivalent for "DIFFERS FROM")
  560. $aModified[] = "NOT(NEW.`$sColumn` <=> OLD.`$sColumn`)";
  561. }
  562. $sIsModified = '('.implode(') OR (', $aModified).')';
  563. // Update the replica
  564. //
  565. // status is forced to "new" if the replica was obsoleted directly from the state "new" (dest_id = null)
  566. // otherwise, if status was either 'obsolete' or 'synchronized' it is turned into 'modified' or 'synchronized' depending on the changes
  567. // otherwise, the status is left as is
  568. $sTriggerUpdate = "CREATE TRIGGER `{$sTable}_bu` BEFORE UPDATE ON $sTable";
  569. $sTriggerUpdate .= " FOR EACH ROW";
  570. $sTriggerUpdate .= " BEGIN";
  571. $sTriggerUpdate .= " IF @itopuser is null THEN";
  572. $sTriggerUpdate .= " UPDATE priv_sync_replica SET status_last_seen = NOW(), `status` = IF(`status` = 'obsolete', IF(`dest_id` IS NULL, 'new', 'modified'), IF(`status` IN ('synchronized') AND ($sIsModified), 'modified', `status`)) WHERE sync_source_id = {$this->GetKey()} AND id = OLD.id;";
  573. $sTriggerUpdate .= " SET NEW.id = OLD.id;"; // make sure this id won't change
  574. $sTriggerUpdate .= " END IF;";
  575. $sTriggerUpdate .= " END;";
  576. CMDBSource::Query($sTriggerUpdate);
  577. $sTriggerInsert = "CREATE TRIGGER `{$sTable}_ad` AFTER DELETE ON $sTable";
  578. $sTriggerInsert .= " FOR EACH ROW";
  579. $sTriggerInsert .= " BEGIN";
  580. $sTriggerInsert .= " DELETE FROM priv_sync_replica WHERE id = OLD.id;";
  581. $sTriggerInsert .= " END;";
  582. CMDBSource::Query($sTriggerInsert);
  583. }
  584. protected function AfterDelete()
  585. {
  586. parent::AfterDelete();
  587. $sTable = $this->GetDataTable();
  588. $sDropTable = "DROP TABLE `$sTable`";
  589. CMDBSource::Query($sDropTable);
  590. // TO DO - check that triggers get dropped with the table
  591. }
  592. /**
  593. * Perform a synchronization between the data stored in the replicas (&synchro_data_xxx_xx table)
  594. * and the iTop objects. If the lastFullLoadStartDate is NOT specified then the full_load_periodicity
  595. * is used to determine which records are obsolete.
  596. * @param Hash $aTraces Debugs/Trace information, one or more entries per replica
  597. * @param DateTime $oLastFullLoadStartDate Date of the last full load (start date/time), if known
  598. * @return void
  599. */
  600. public function Synchronize($oLastFullLoadStartDate = null)
  601. {
  602. // Create a change used for logging all the modifications/creations happening during the synchro
  603. $oMyChange = MetaModel::NewObject("CMDBChange");
  604. $oMyChange->Set("date", time());
  605. $sUserString = CMDBChange::GetCurrentUserName();
  606. $oMyChange->Set("userinfo", $sUserString.' '.Dict::S('Core:SyncDataExchangeComment'));
  607. $iChangeId = $oMyChange->DBInsert();
  608. // Start logging this execution (stats + protection against reentrance)
  609. //
  610. $oStatLog = new SynchroLog();
  611. $oStatLog->Set('sync_source_id', $this->GetKey());
  612. $oStatLog->Set('start_date', time());
  613. $oStatLog->Set('status', 'running');
  614. $oStatLog->Set('stats_nb_replica_seen', 0);
  615. $oStatLog->Set('stats_nb_replica_total', 0);
  616. $oStatLog->Set('stats_nb_obj_deleted', 0);
  617. $oStatLog->Set('stats_nb_obj_deleted_errors', 0);
  618. $oStatLog->Set('stats_nb_obj_obsoleted', 0);
  619. $oStatLog->Set('stats_nb_obj_obsoleted_errors', 0);
  620. $oStatLog->Set('stats_nb_obj_created', 0);
  621. $oStatLog->Set('stats_nb_obj_created_errors', 0);
  622. $oStatLog->Set('stats_nb_obj_updated', 0);
  623. $oStatLog->Set('stats_nb_obj_updated_errors', 0);
  624. // $oStatLog->Set('stats_nb_replica_reconciled', 0);
  625. $oStatLog->Set('stats_nb_replica_reconciled_errors', 0);
  626. $oStatLog->Set('stats_nb_replica_disappeared_no_action', 0);
  627. $oStatLog->Set('stats_nb_obj_new_updated', 0);
  628. $oStatLog->Set('stats_nb_obj_new_unchanged',0);
  629. $sSelectTotal = "SELECT SynchroReplica WHERE sync_source_id = :source_id";
  630. $oSetTotal = new DBObjectSet(DBObjectSearch::FromOQL($sSelectTotal), array() /* order by*/, array('source_id' => $this->GetKey()));
  631. $oStatLog->Set('stats_nb_replica_total', $oSetTotal->Count());
  632. $oStatLog->DBInsertTracked($oMyChange);
  633. try
  634. {
  635. $this->DoSynchronize($oLastFullLoadStartDate, $oMyChange, $oStatLog);
  636. $oStatLog->Set('end_date', time());
  637. $oStatLog->Set('status', 'completed');
  638. $oStatLog->DBUpdateTracked($oMyChange);
  639. }
  640. catch (SynchroExceptionNotStarted $e)
  641. {
  642. // Set information for reporting... but delete the object in DB
  643. $oStatLog->Set('end_date', time());
  644. $oStatLog->Set('status', 'error');
  645. $oStatLog->Set('last_error', $e->getMessage());
  646. $oStatLog->DBDeleteTracked($oMyChange);
  647. }
  648. catch (Exception $e)
  649. {
  650. $oStatLog->Set('end_date', time());
  651. $oStatLog->Set('status', 'error');
  652. $oStatLog->Set('last_error', $e->getMessage());
  653. $oStatLog->DBUpdateTracked($oMyChange);
  654. }
  655. return $oStatLog;
  656. }
  657. protected function DoSynchronize($oLastFullLoadStartDate, $oMyChange, &$oStatLog)
  658. {
  659. if ($this->Get('status') == 'obsolete')
  660. {
  661. throw new SynchroExceptionNotStarted(Dict::S('Core:SyncDataSourceObsolete'));
  662. }
  663. if (!UserRights::IsAdministrator() && $this->Get('user_id') != UserRights::GetUserId())
  664. {
  665. throw new SynchroExceptionNotStarted(Dict::S('Core:SyncDataSourceAccessRestriction'));
  666. }
  667. // Get the list of SQL columns
  668. $sClass = $this->GetTargetClass();
  669. $aAttCodesExpected = array();
  670. $aAttCodesToReconcile = array();
  671. $aAttCodesToUpdate = array();
  672. $sSelectAtt = "SELECT SynchroAttribute WHERE sync_source_id = :source_id AND (update = 1 OR reconcile = 1)";
  673. $oSetAtt = new DBObjectSet(DBObjectSearch::FromOQL($sSelectAtt), array() /* order by*/, array('source_id' => $this->GetKey()) /* aArgs */);
  674. while ($oSyncAtt = $oSetAtt->Fetch())
  675. {
  676. if ($oSyncAtt->Get('update'))
  677. {
  678. $aAttCodesToUpdate[$oSyncAtt->Get('attcode')] = $oSyncAtt;
  679. }
  680. if ($oSyncAtt->Get('reconcile'))
  681. {
  682. $aAttCodesToReconcile[$oSyncAtt->Get('attcode')] = $oSyncAtt;
  683. }
  684. $aAttCodesExpected[$oSyncAtt->Get('attcode')] = $oSyncAtt;
  685. }
  686. $aColumns = $this->GetSQLColumns(array_keys($aAttCodesExpected));
  687. $aExtDataFields = array_keys($aColumns);
  688. $aExtDataFields[] = 'primary_key';
  689. $aExtDataSpec = array(
  690. 'table' => $this->GetDataTable(),
  691. 'join_key' => 'id',
  692. 'fields' => $aExtDataFields
  693. );
  694. // Get the list of attributes, determine reconciliation keys and update targets
  695. //
  696. if ($this->Get('reconciliation_policy') == 'use_attributes')
  697. {
  698. $aReconciliationKeys = $aAttCodesToReconcile;
  699. }
  700. elseif ($this->Get('reconciliation_policy') == 'use_primary_key')
  701. {
  702. // Override the settings made at the attribute level !
  703. $aReconciliationKeys = array("primary_key" => null);
  704. }
  705. $oStatLog->AddTrace("Update of: {".implode(', ', array_keys($aAttCodesToUpdate))."}");
  706. $oStatLog->AddTrace("Reconciliation on: {".implode(', ', array_keys($aReconciliationKeys))."}");
  707. if (count($aAttCodesToUpdate) == 0)
  708. {
  709. $oStatLog->AddTrace("No attribute to update");
  710. throw new SynchroExceptionNotStarted('There is no attribute to update');
  711. }
  712. if (count($aReconciliationKeys) == 0)
  713. {
  714. $oStatLog->AddTrace("No attribute for reconciliation");
  715. throw new SynchroExceptionNotStarted('No attribute for reconciliation');
  716. }
  717. $aAttributes = array();
  718. foreach($aAttCodesToUpdate as $sAttCode => $oSyncAtt)
  719. {
  720. $oAttDef = MetaModel::GetAttributeDef($this->GetTargetClass(), $sAttCode);
  721. if ($oAttDef->IsWritable() && $oAttDef->IsScalar())
  722. {
  723. $aAttributes[$sAttCode] = $oSyncAtt;
  724. }
  725. }
  726. $sDeletePolicy = $this->Get('delete_policy');
  727. // Count the replicas
  728. $sSelectAll = "SELECT SynchroReplica WHERE sync_source_id = :source_id";
  729. $oSetAll = new DBObjectSet(DBObjectSearch::FromOQL($sSelectAll), array() /* order by*/, array('source_id' => $this->GetKey()));
  730. $iCountAllReplicas = $oSetAll->Count();
  731. $oStatLog->Set('stats_nb_replica_total', $iCountAllReplicas);
  732. // Get all the replicas that were not seen in the last import and mark them as obsolete
  733. if ($oLastFullLoadStartDate == null)
  734. {
  735. // No previous import known, use the full_load_periodicity value... and the current date
  736. $oLastFullLoadStartDate = new DateTime(); // Now
  737. $iLoadPeriodicity = $this->Get('full_load_periodicity'); // Duration in seconds
  738. if ($iLoadPeriodicity > 0)
  739. {
  740. $sInterval = "-$iLoadPeriodicity seconds";
  741. $oLastFullLoadStartDate->Modify($sInterval);
  742. }
  743. }
  744. $sLimitDate = $oLastFullLoadStartDate->Format('Y-m-d H:i:s');
  745. $oStatLog->AddTrace("Limit Date: $sLimitDate");
  746. $sSelectToObsolete = "SELECT SynchroReplica WHERE sync_source_id = :source_id AND status IN ('new', 'synchronized', 'modified', 'orphan') AND status_last_seen < :last_import";
  747. $oSetToObsolete = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToObsolete), array() /* order by*/, array('source_id' => $this->GetKey(), 'last_import' => $sLimitDate));
  748. if (($iCountAllReplicas > 10) && ($iCountAllReplicas == $oSetToObsolete->Count()))
  749. {
  750. throw new SynchroExceptionNotStarted(Dict::S('Core:SyncTooManyMissingReplicas'));
  751. }
  752. while($oReplica = $oSetToObsolete->Fetch())
  753. {
  754. switch ($sDeletePolicy)
  755. {
  756. case 'update':
  757. case 'update_then_delete':
  758. $oStatLog->AddTrace("Destination object to be updated", $oReplica);
  759. $aToUpdate = array();
  760. $aToUpdate = explode(';', $this->Get('delete_policy_update')); //ex: 'status:obsolete;description:stopped',
  761. foreach($aToUpdate as $sUpdateSpec)
  762. {
  763. $aUpdateSpec = explode(':', $sUpdateSpec);
  764. if (count($aUpdateSpec) == 2)
  765. {
  766. $sAttCode = $aUpdateSpec[0];
  767. $sValue = $aUpdateSpec[1];
  768. $aToUpdate[$sAttCode] = $sValue;
  769. }
  770. }
  771. $oReplica->UpdateDestObject($aToUpdate, $oMyChange, $oStatLog);
  772. $oReplica->Set('status', 'obsolete');
  773. $oReplica->Set('info_last_synchro', date('Y-m-d H:i:s'));
  774. $oReplica->DBUpdateTracked($oMyChange);
  775. break;
  776. case 'delete':
  777. default:
  778. $oStatLog->AddTrace("Destination object to be DELETED", $oReplica);
  779. $oReplica->DeleteDestObject($oMyChange, $oStatLog);
  780. }
  781. }
  782. //Count "seen" objects
  783. $sSelectSeen = "SELECT SynchroReplica WHERE sync_source_id = :source_id AND status IN ('new', 'synchronized', 'modified', 'orphan') AND status_last_seen >= :last_import";
  784. $oSetSeen = new DBObjectSet(DBObjectSearch::FromOQL($sSelectSeen), array() /* order by*/, array('source_id' => $this->GetKey(), 'last_import' => $sLimitDate));
  785. $oStatLog->Set('stats_nb_replica_seen', $oSetSeen->Count());
  786. // Get all the replicas that are 'new' or modified
  787. //
  788. $sSelectToSync = "SELECT SynchroReplica WHERE (status = 'new' OR status = 'modified') AND sync_source_id = :source_id";
  789. $oSetToSync = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToSync), array() /* order by*/, array('source_id' => $this->GetKey()) /* aArgs */, $aExtDataSpec, 0 /* limitCount */, 0 /* limitStart */);
  790. while($oReplica = $oSetToSync->Fetch())
  791. {
  792. $oReplica->Synchro($this, $aReconciliationKeys, $aAttributes, $oMyChange, $oStatLog);
  793. }
  794. // Get all the replicas that are to be deleted
  795. //
  796. if ($sDeletePolicy == 'update_then_delete')
  797. {
  798. $oDeletionDate = $oLastFullLoadStartDate;
  799. $iDeleteRetention = $this->Get('delete_policy_retention'); // Duration in seconds
  800. if ($iDeleteRetention > 0)
  801. {
  802. $sInterval = "-$iDeleteRetention seconds";
  803. $oDeletionDate->Modify($sInterval);
  804. }
  805. $sDeletionDate = $oDeletionDate->Format('Y-m-d H:i:s');
  806. $oStatLog->AddTrace("Deletion date: $sDeletionDate");
  807. $sSelectToDelete = "SELECT SynchroReplica WHERE sync_source_id = :source_id AND status IN ('obsolete') AND status_last_seen < :last_import";
  808. $oSetToDelete = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToDelete), array() /* order by*/, array('source_id' => $this->GetKey(), 'last_import' => $sDeletionDate));
  809. while($oReplica = $oSetToDelete->Fetch())
  810. {
  811. $oStatLog->AddTrace("Destination object to be DELETED", $oReplica);
  812. $oReplica->DeleteDestObject($oMyChange, $oStatLog);
  813. }
  814. }
  815. }
  816. /**
  817. * Get the list of SQL columns corresponding to a particular list of attribute codes
  818. * Defaults to the whole list of columns for the current class
  819. */
  820. public function GetSQLColumns($aAttributeCodes = null)
  821. {
  822. $aColumns = array();
  823. $sClass = $this->GetTargetClass();
  824. if (is_null($aAttributeCodes))
  825. {
  826. $aAttributeCodes = array();
  827. foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
  828. {
  829. if ($sAttCode == 'finalclass') continue;
  830. $aAttributeCodes[] = $sAttCode;
  831. }
  832. }
  833. foreach($aAttributeCodes as $sAttCode)
  834. {
  835. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  836. if ($oAttDef->IsExternalKey())
  837. {
  838. // The pkey might be used as well as any other key column
  839. $aColumns[$sAttCode] = 'VARCHAR (255)';
  840. }
  841. else
  842. {
  843. foreach($oAttDef->GetImportColumns() as $sField => $sDBFieldType)
  844. {
  845. $aColumns[$sField] = $sDBFieldType;
  846. }
  847. }
  848. }
  849. return $aColumns;
  850. }
  851. public function IsRunning()
  852. {
  853. $sOQL = "SELECT SynchroLog WHERE sync_source_id = :source_id AND status='running'";
  854. $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array('start_date' => false) /* order by*/, array('source_id' => $this->GetKey()) /* aArgs */, array(), 1 /* limitCount */, 0 /* limitStart */);
  855. if ($oSet->Count() < 1)
  856. {
  857. $bRet = false;
  858. }
  859. else
  860. {
  861. $bRet = true;
  862. }
  863. return $bRet;
  864. }
  865. public function GetLatestLog()
  866. {
  867. $oLog = null;
  868. $sOQL = "SELECT SynchroLog WHERE sync_source_id = :source_id";
  869. $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array('start_date' => false) /* order by*/, array('source_id' => $this->GetKey()) /* aArgs */, array(), 1 /* limitCount */, 0 /* limitStart */);
  870. if ($oSet->Count() >= 1)
  871. {
  872. $oLog = $oSet->Fetch();
  873. }
  874. return $oLog;
  875. }
  876. // TO DO: remove if still unused
  877. /**
  878. * Retrieve from the log, the date of the last completed import
  879. * @return DateTime
  880. */
  881. public function GetLastCompletedImportDate()
  882. {
  883. $date = null;
  884. $sOQL = "SELECT SynchroLog WHERE sync_source_id = :source_id AND status='completed'";
  885. $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array('end_date' => false) /* order by*/, array('source_id' => $this->GetKey()) /* aArgs */, array(), 0 /* limitCount */, 0 /* limitStart */);
  886. if ($oSet->Count() >= 1)
  887. {
  888. $oLog = $oSet->Fetch();
  889. $date = $oLog->Get('end_date');
  890. }
  891. else
  892. {
  893. // TO DO: remove trace
  894. echo "<p>No completed log found</p>\n";
  895. }
  896. return $date;
  897. }
  898. }
  899. class SynchroAttribute extends cmdbAbstractObject
  900. {
  901. public static function Init()
  902. {
  903. $aParams = array
  904. (
  905. "category" => "core/cmdb,view_in_gui",
  906. "key_type" => "autoincrement",
  907. "name_attcode" => "",
  908. "state_attcode" => "",
  909. "reconc_keys" => array(),
  910. "db_table" => "priv_sync_att",
  911. "db_key_field" => "id",
  912. "db_finalclass_field" => "",
  913. "display_template" => "",
  914. );
  915. MetaModel::Init_Params($aParams);
  916. MetaModel::Init_InheritAttributes();
  917. MetaModel::Init_AddAttribute(new AttributeExternalKey("sync_source_id", array("targetclass"=>"SynchroDataSource", "jointype"=> "", "allowed_values"=>null, "sql"=>"sync_source_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  918. MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  919. MetaModel::Init_AddAttribute(new AttributeBoolean("update", array("allowed_values"=>null, "sql"=>"update", "default_value"=>true, "is_null_allowed"=>false, "depends_on"=>array())));
  920. MetaModel::Init_AddAttribute(new AttributeBoolean("reconcile", array("allowed_values"=>null, "sql"=>"reconcile", "default_value"=>false, "is_null_allowed"=>false, "depends_on"=>array())));
  921. MetaModel::Init_AddAttribute(new AttributeEnum("update_policy", array("allowed_values"=>new ValueSetEnum('master_locked,master_unlocked,write_if_empty'), "sql"=>"update_policy", "default_value"=>"master_locked", "is_null_allowed"=>false, "depends_on"=>array())));
  922. // Display lists
  923. MetaModel::Init_SetZListItems('details', array('sync_source_id', 'attcode', 'update', 'reconcile', 'update_policy')); // Attributes to be displayed for the complete details
  924. MetaModel::Init_SetZListItems('list', array('sync_source_id', 'attcode', 'update', 'reconcile', 'update_policy')); // Attributes to be displayed for a list
  925. // Search criteria
  926. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  927. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  928. }
  929. }
  930. class SynchroAttExtKey extends SynchroAttribute
  931. {
  932. public static function Init()
  933. {
  934. $aParams = array
  935. (
  936. "category" => "core/cmdb,view_in_gui",
  937. "key_type" => "autoincrement",
  938. "name_attcode" => "",
  939. "state_attcode" => "",
  940. "reconc_keys" => array(),
  941. "db_table" => "priv_sync_att_extkey",
  942. "db_key_field" => "id",
  943. "db_finalclass_field" => "",
  944. "display_template" => "",
  945. );
  946. MetaModel::Init_Params($aParams);
  947. MetaModel::Init_InheritAttributes();
  948. MetaModel::Init_AddAttribute(new AttributeString("reconciliation_attcode", array("allowed_values"=>null, "sql"=>"reconciliation_attcode", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  949. // Display lists
  950. MetaModel::Init_SetZListItems('details', array('sync_source_id', 'attcode', 'update', 'reconcile', 'update_policy', 'reconciliation_attcode')); // Attributes to be displayed for the complete details
  951. MetaModel::Init_SetZListItems('list', array('sync_source_id', 'attcode', 'update', 'reconcile', 'update_policy')); // Attributes to be displayed for a list
  952. // Search criteria
  953. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  954. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  955. }
  956. public function GetReconciliationFormElement($sTargetClass, $sFieldName)
  957. {
  958. $sHtml = "<select name=\"$sFieldName\">\n";
  959. $sSelected = (''== $this->Get('reconciliation_attcode')) ? ' selected' : '';
  960. $sHtml .= "<option value=\"\" $sSelected>".Dict::S('Core:SynchroAttExtKey:ReconciliationById')."</option>\n";
  961. foreach(MetaModel::ListAttributeDefs($sTargetClass) as $sAttCode => $oAttDef)
  962. {
  963. if ($oAttDef->IsScalar())
  964. {
  965. $sSelected = ($sAttCode == $this->Get('reconciliation_attcode')) ? ' selected' : '';
  966. $sHtml .= "<option value=\"$sAttCode\" $sSelected>".MetaModel::GetLabel($sTargetClass, $sAttCode)."</option>\n";
  967. }
  968. }
  969. $sHtml .= "</select>\n";
  970. return $sHtml;
  971. }
  972. }
  973. class SynchroAttLinkSet extends SynchroAttribute
  974. {
  975. public static function Init()
  976. {
  977. $aParams = array
  978. (
  979. "category" => "core/cmdb,view_in_gui",
  980. "key_type" => "autoincrement",
  981. "name_attcode" => "",
  982. "state_attcode" => "",
  983. "reconc_keys" => array(),
  984. "db_table" => "priv_sync_att_linkset",
  985. "db_key_field" => "id",
  986. "db_finalclass_field" => "",
  987. "display_template" => "",
  988. );
  989. MetaModel::Init_Params($aParams);
  990. MetaModel::Init_InheritAttributes();
  991. MetaModel::Init_AddAttribute(new AttributeString("row_separator", array("allowed_values"=>null, "sql"=>"row_separator", "default_value"=>'|', "is_null_allowed"=>true, "depends_on"=>array())));
  992. MetaModel::Init_AddAttribute(new AttributeString("attribute_separator", array("allowed_values"=>null, "sql"=>"attribute_separator", "default_value"=>';', "is_null_allowed"=>true, "depends_on"=>array())));
  993. // Display lists
  994. MetaModel::Init_SetZListItems('details', array('sync_source_id', 'attcode', 'update', 'reconcile', 'update_policy', 'row_separator', 'attribute_separator')); // Attributes to be displayed for the complete details
  995. MetaModel::Init_SetZListItems('list', array('sync_source_id', 'attcode', 'update', 'reconcile', 'update_policy')); // Attributes to be displayed for a list
  996. // Search criteria
  997. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  998. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  999. }
  1000. }
  1001. //class SynchroLog extends Event
  1002. class SynchroLog extends DBObject
  1003. {
  1004. public static function Init()
  1005. {
  1006. $aParams = array
  1007. (
  1008. "category" => "core/cmdb,view_in_gui",
  1009. "key_type" => "autoincrement",
  1010. "name_attcode" => "",
  1011. "state_attcode" => "",
  1012. "reconc_keys" => array(),
  1013. "db_table" => "priv_sync_log",
  1014. "db_key_field" => "id",
  1015. "db_finalclass_field" => "",
  1016. "display_template" => "",
  1017. );
  1018. MetaModel::Init_Params($aParams);
  1019. MetaModel::Init_InheritAttributes();
  1020. // MetaModel::Init_AddAttribute(new AttributeString("userinfo", array("allowed_values"=>null, "sql"=>"userinfo", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  1021. MetaModel::Init_AddAttribute(new AttributeExternalKey("sync_source_id", array("targetclass"=>"SynchroDataSource", "jointype"=> "", "allowed_values"=>null, "sql"=>"sync_source_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  1022. MetaModel::Init_AddAttribute(new AttributeDateTime("start_date", array("allowed_values"=>null, "sql"=>"start_date", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  1023. MetaModel::Init_AddAttribute(new AttributeDateTime("end_date", array("allowed_values"=>null, "sql"=>"end_date", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  1024. MetaModel::Init_AddAttribute(new AttributeEnum("status", array("allowed_values"=>new ValueSetEnum('running,completed,error'), "sql"=>"status", "default_value"=>"running", "is_null_allowed"=>false, "depends_on"=>array())));
  1025. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_replica_seen", array("allowed_values"=>null, "sql"=>"stats_nb_replica_seen", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1026. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_replica_total", array("allowed_values"=>null, "sql"=>"stats_nb_replica_total", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1027. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_deleted", array("allowed_values"=>null, "sql"=>"stats_nb_obj_deleted", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1028. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_deleted_errors", array("allowed_values"=>null, "sql"=>"stats_deleted_errors", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1029. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_obsoleted", array("allowed_values"=>null, "sql"=>"stats_nb_obj_obsoleted", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1030. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_obsoleted_errors", array("allowed_values"=>null, "sql"=>"stats_nb_obj_obsoleted_errors", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1031. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_created", array("allowed_values"=>null, "sql"=>"stats_nb_obj_created", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1032. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_created_errors", array("allowed_values"=>null, "sql"=>"stats_nb_obj_created_errors", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1033. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_updated", array("allowed_values"=>null, "sql"=>"stats_nb_obj_updated", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1034. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_updated_errors", array("allowed_values"=>null, "sql"=>"stats_nb_obj_updated_errors", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1035. // MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_replica_reconciled", array("allowed_values"=>null, "sql"=>"stats_nb_replica_reconciled", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1036. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_replica_reconciled_errors", array("allowed_values"=>null, "sql"=>"stats_nb_replica_reconciled_errors", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1037. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_replica_disappeared_no_action", array("allowed_values"=>null, "sql"=>"stats_nb_replica_disappeared_no_action", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1038. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_new_updated", array("allowed_values"=>null, "sql"=>"stats_nb_obj_new_updated", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1039. MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_new_unchanged", array("allowed_values"=>null, "sql"=>"stats_nb_obj_new_unchanged", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  1040. MetaModel::Init_AddAttribute(new AttributeString("last_error", array("allowed_values"=>null, "sql"=>"last_error", "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array())));
  1041. MetaModel::Init_AddAttribute(new AttributeLongText("traces", array("allowed_values"=>null, "sql"=>"traces", "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array())));
  1042. // Display lists
  1043. MetaModel::Init_SetZListItems('details', array('sync_source_id', 'start_date', 'end_date', 'status', 'stats_nb_replica_total', 'stats_nb_replica_seen', 'stats_nb_obj_created', /*'stats_nb_replica_reconciled',*/ 'stats_nb_obj_updated', 'stats_nb_obj_obsoleted', 'stats_nb_obj_deleted',
  1044. 'stats_nb_obj_created_errors', 'stats_nb_replica_reconciled_errors', 'stats_nb_replica_disappeared_no_action', 'stats_nb_obj_updated_errors', 'stats_nb_obj_obsoleted_errors', 'stats_nb_obj_deleted_errors', 'stats_nb_obj_new_unchanged', 'stats_nb_obj_new_updated', 'traces')); // Attributes to be displayed for the complete details
  1045. MetaModel::Init_SetZListItems('list', array('sync_source_id', 'start_date', 'end_date', 'status', 'stats_nb_replica_seen')); // Attributes to be displayed for a list
  1046. // Search criteria
  1047. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  1048. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  1049. }
  1050. /**
  1051. * Increments a statistics counter
  1052. */
  1053. function Inc($sCode)
  1054. {
  1055. $this->Set($sCode, 1+$this->Get($sCode));
  1056. }
  1057. /**
  1058. * Implement traces management
  1059. */
  1060. protected $m_aTraces = array();
  1061. public function AddTrace($sMsg, $oReplica = null)
  1062. {
  1063. if (MetaModel::GetConfig()->Get('synchro_trace') == 'none')
  1064. {
  1065. return;
  1066. }
  1067. if ($oReplica)
  1068. {
  1069. $sDestClass = $oReplica->Get('dest_class');
  1070. if (!empty($sDestClass))
  1071. {
  1072. $sPrefix = $oReplica->GetKey().','.$sDestClass.'::'.$oReplica->Get('dest_id').',';
  1073. }
  1074. else
  1075. {
  1076. $sPrefix = $oReplica->GetKey().',,';
  1077. }
  1078. }
  1079. else
  1080. {
  1081. $sPrefix = ',,';
  1082. }
  1083. $this->m_aTraces[] = $sPrefix.$sMsg;
  1084. }
  1085. public function GetTraces()
  1086. {
  1087. return $this->m_aTraces;
  1088. }
  1089. protected function TraceToText()
  1090. {
  1091. if (MetaModel::GetConfig()->Get('synchro_trace') != 'save')
  1092. {
  1093. // none, or display only
  1094. return;
  1095. }
  1096. $oAttDef = MetaModel::GetAttributeDef(get_class($this), 'traces');
  1097. $iMaxSize = $oAttDef->GetMaxSize();
  1098. $sTrace = implode("\n", $this->m_aTraces);
  1099. if (strlen($sTrace) >= $iMaxSize)
  1100. {
  1101. $sTrace = substr($sTrace, 0, $iMaxSize - 255)."...\nTruncated (size: ".strlen($sTrace).')';
  1102. }
  1103. $this->Set('traces', $sTrace);
  1104. }
  1105. protected function OnInsert()
  1106. {
  1107. $this->TraceToText();
  1108. parent::OnInsert();
  1109. }
  1110. protected function OnUpdate()
  1111. {
  1112. $this->TraceToText();
  1113. parent::OnUpdate();
  1114. }
  1115. }
  1116. class SynchroReplica extends DBObject implements iDisplay
  1117. {
  1118. static $aSearches = array(); // Cache of OQL queries used for reconciliation (per data source)
  1119. public static function Init()
  1120. {
  1121. $aParams = array
  1122. (
  1123. "category" => "core/cmdb,view_in_gui",
  1124. "key_type" => "autoincrement",
  1125. "name_attcode" => "",
  1126. "state_attcode" => "",
  1127. "reconc_keys" => array(),
  1128. "db_table" => "priv_sync_replica",
  1129. "db_key_field" => "id",
  1130. "db_finalclass_field" => "",
  1131. "display_template" => "",
  1132. );
  1133. MetaModel::Init_Params($aParams);
  1134. MetaModel::Init_InheritAttributes();
  1135. MetaModel::Init_AddAttribute(new AttributeExternalKey("sync_source_id", array("targetclass"=>"SynchroDataSource", "jointype"=> "", "allowed_values"=>null, "sql"=>"sync_source_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  1136. MetaModel::Init_AddAttribute(new AttributeExternalField("base_class", array("allowed_values"=>null, "extkey_attcode"=> 'sync_source_id', "target_attcode"=>"scope_class")));
  1137. MetaModel::Init_AddAttribute(new AttributeInteger("dest_id", array("allowed_values"=>null, "sql"=>"dest_id", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  1138. MetaModel::Init_AddAttribute(new AttributeClass("dest_class", array("class_category"=>"", "more_values"=>"", "sql"=>"dest_class", "default_value"=>'Organization', "is_null_allowed"=>true, "depends_on"=>array())));
  1139. MetaModel::Init_AddAttribute(new AttributeDateTime("status_last_seen", array("allowed_values"=>null, "sql"=>"status_last_seen", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  1140. MetaModel::Init_AddAttribute(new AttributeEnum("status", array("allowed_values"=>new ValueSetEnum('new,synchronized,modified,orphan,obsolete'), "sql"=>"status", "default_value"=>"new", "is_null_allowed"=>false, "depends_on"=>array())));
  1141. MetaModel::Init_AddAttribute(new AttributeBoolean("status_dest_creator", array("allowed_values"=>null, "sql"=>"status_dest_creator", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  1142. MetaModel::Init_AddAttribute(new AttributeString("status_last_error", array("allowed_values"=>null, "sql"=>"status_last_error", "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array())));
  1143. MetaModel::Init_AddAttribute(new AttributeDateTime("info_creation_date", array("allowed_values"=>null, "sql"=>"info_creation_date", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  1144. MetaModel::Init_AddAttribute(new AttributeDateTime("info_last_modified", array("allowed_values"=>null, "sql"=>"info_last_modified", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  1145. MetaModel::Init_AddAttribute(new AttributeDateTime("info_last_synchro", array("allowed_values"=>null, "sql"=>"info_last_synchro", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  1146. // Display lists
  1147. MetaModel::Init_SetZListItems('details', array('sync_source_id', 'dest_id', 'dest_class', 'status_last_seen', 'status', 'status_dest_creator', 'status_last_error', 'info_creation_date', 'info_last_modified', 'info_last_synchro')); // Attributes to be displayed for the complete details
  1148. MetaModel::Init_SetZListItems('list', array('sync_source_id', 'dest_id', 'dest_class', 'status_last_seen', 'status', 'status_dest_creator', 'status_last_error')); // Attributes to be displayed for a list
  1149. // Search criteria
  1150. MetaModel::Init_SetZListItems('standard_search', array('sync_source_id', 'status_last_seen', 'status', 'status_dest_creator', 'dest_class', 'dest_id', 'status_last_error')); // Criteria of the std search form
  1151. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  1152. }
  1153. public function DBInsert()
  1154. {
  1155. throw new CoreException('A synchronization replica must be created only by the mean of triggers');
  1156. }
  1157. // Overload the deletion -> the replica has been created by the mean of a trigger,
  1158. // it will be deleted by the mean of a trigger too
  1159. public function DBDelete()
  1160. {
  1161. $oDataSource = MetaModel::GetObject('SynchroDataSource', $this->Get('sync_source_id'));
  1162. $sTable = $oDataSource->GetDataTable();
  1163. $sSQL = "DELETE FROM `$sTable` WHERE id = '{$this->GetKey()}'";
  1164. CMDBSource::Query($sSQL);
  1165. $this->m_bIsInDB = false;
  1166. $this->m_iKey = null;
  1167. }
  1168. public function SetLastError($sMessage, $oException = null)
  1169. {
  1170. if ($oException)
  1171. {
  1172. $sText = $sMessage.$oException->getMessage();
  1173. }
  1174. else
  1175. {
  1176. $sText = $sMessage;
  1177. }
  1178. if (strlen($sText) > 255)
  1179. {
  1180. $sText = substr($sText, 0, 200).'...('.strlen($sText).' chars)...';
  1181. }
  1182. $this->Set('status_last_error', $sText);
  1183. }
  1184. public function Synchro($oDataSource, $aReconciliationKeys, $aAttributes, $oChange, &$oStatLog)
  1185. {
  1186. switch($this->Get('status'))
  1187. {
  1188. case 'new':
  1189. $this->Set('status_dest_creator', false);
  1190. // If needed, construct the query used for the reconciliation
  1191. if (!isset(self::$aSearches[$oDataSource->GetKey()]))
  1192. {
  1193. $aCriterias = array();
  1194. foreach($aReconciliationKeys as $sFilterCode => $oSyncAtt)
  1195. {
  1196. $aCriterias[] = ($sFilterCode == 'primary_key' ? 'id' : $sFilterCode).' = :'.$sFilterCode;
  1197. }
  1198. $sOQL = "SELECT ".$oDataSource->GetTargetClass()." WHERE ".implode(' AND ', $aCriterias);
  1199. self::$aSearches[$oDataSource->GetKey()] = DBObjectSearch::FromOQL($sOQL);
  1200. }
  1201. // Get the criterias for the search
  1202. $aFilterValues = array();
  1203. foreach($aReconciliationKeys as $sFilterCode => $oSyncAtt)
  1204. {
  1205. $value = $this->GetValueFromExtData($sFilterCode, $oSyncAtt, $oStatLog);
  1206. if (!is_null($value))
  1207. {
  1208. $aFilterValues[$sFilterCode] = $value;
  1209. }
  1210. else
  1211. {
  1212. // Reconciliation could not be performed - log and EXIT
  1213. $oStatLog->AddTrace("Could not reconcile on null value: ".$sFilterCode, $this);
  1214. $this->SetLastError('Could not reconcile on null value: '.$sFilterCode);
  1215. $oStatLog->Inc('stats_nb_replica_reconciled_errors');
  1216. return;
  1217. }
  1218. }
  1219. $oDestSet = new DBObjectSet(self::$aSearches[$oDataSource->GetKey()], array(), $aFilterValues);
  1220. $iCount = $oDestSet->Count();
  1221. $aConditions = array();
  1222. foreach($aFilterValues as $sCode => $sValue)
  1223. {
  1224. $aConditions[] = $sCode.'='.$sValue;
  1225. }
  1226. $sConditionDesc = implode(' AND ', $aConditions);
  1227. // How many objects match the reconciliation criterias
  1228. switch($iCount)
  1229. {
  1230. case 0:
  1231. $oStatLog->AddTrace("Nothing found on: $sConditionDesc", $this);
  1232. if ($oDataSource->Get('action_on_zero') == 'create')
  1233. {
  1234. $this->CreateObjectFromReplica($oDataSource->GetTargetClass(), $aAttributes, $oChange, $oStatLog);
  1235. }
  1236. else // assumed to be 'error'
  1237. {
  1238. $oStatLog->AddTrace("Failed to reconcile (no match)", $this);
  1239. $this->SetLastError('Could not find a match for reconciliation');
  1240. $oStatLog->Inc('stats_nb_replica_reconciled_errors');
  1241. }
  1242. break;
  1243. case 1:
  1244. $oStatLog->AddTrace("Found 1 object on: $sConditionDesc", $this);
  1245. if ($oDataSource->Get('action_on_one') == 'update')
  1246. {
  1247. $oDestObj = $oDestSet->Fetch();
  1248. $this->UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, $oStatLog, 'stats_nb_obj_new', 'stats_nb_replica_reconciled_errors');
  1249. $this->Set('dest_id', $oDestObj->GetKey());
  1250. $this->Set('dest_class', get_class($oDestObj));
  1251. }
  1252. else
  1253. {
  1254. // assumed to be 'error'
  1255. $oStatLog->AddTrace("Failed to reconcile (1 match)", $this);
  1256. $this->SetLastError('Found a match while expecting several');
  1257. $oStatLog->Inc('stats_nb_replica_reconciled_errors');
  1258. }
  1259. break;
  1260. default:
  1261. $oStatLog->AddTrace("Found $iCount objects on: $sConditionDesc", $this);
  1262. if ($oDataSource->Get('action_on_multiple') == 'error')
  1263. {
  1264. $oStatLog->AddTrace("Failed to reconcile (N>1 matches)", $this);
  1265. $this->SetLastError($iCount.' destination objects match the reconciliation criterias: '.$sConditionDesc);
  1266. $oStatLog->Inc('stats_nb_replica_reconciled_errors');
  1267. }
  1268. elseif ($oDataSource->Get('action_on_multiple') == 'create')
  1269. {
  1270. $this->CreateObjectFromReplica($oDataSource->GetTargetClass(), $aAttributes, $oChange, $oStatLog);
  1271. }
  1272. else
  1273. {
  1274. // assumed to be 'take_first'
  1275. $oDestObj = $oDestSet->Fetch();
  1276. $this->UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, $oStatLog, 'stats_nb_obj_new', 'stats_nb_replica_reconciled_errors');
  1277. $this->Set('dest_id', $oDestObj->GetKey());
  1278. $this->Set('dest_class', get_class($oDestObj));
  1279. }
  1280. }
  1281. break;
  1282. case 'modified':
  1283. $oDestObj = MetaModel::GetObject($oDataSource->GetTargetClass(), $this->Get('dest_id'));
  1284. if ($oDestObj == null)
  1285. {
  1286. $this->Set('status', 'orphan'); // The destination object has been deleted !
  1287. $this->SetLastError('Destination object deleted unexpectedly');
  1288. $oStatLog->Inc('stats_nb_obj_updated_errors');
  1289. }
  1290. else
  1291. {
  1292. $this->UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, $oStatLog, 'stats_nb_obj', 'stats_nb_obj_updated_errors');
  1293. }
  1294. break;
  1295. default: // Do nothing in all other cases
  1296. }
  1297. $this->DBUpdateTracked($oChange);
  1298. }
  1299. /**
  1300. * Updates the destination object with the Extended data found in the synchro_data_XXXX table
  1301. */
  1302. protected function UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, &$oStatLog, $sStatsCode, $sStatsCodeError)
  1303. {
  1304. $aValueTrace = array();
  1305. foreach($aAttributes as $sAttCode => $oSyncAtt)
  1306. {
  1307. $value = $this->GetValueFromExtData($sAttCode, $oSyncAtt, $oStatLog);
  1308. if (!is_null($value))
  1309. {
  1310. $oDestObj->Set($sAttCode, $value);
  1311. $aValueTrace[] = "$sAttCode: $value";
  1312. }
  1313. }
  1314. try
  1315. {
  1316. // Really modified ?
  1317. if ($oDestObj->IsModified())
  1318. {
  1319. $oDestObj->DBUpdateTracked($oChange);
  1320. $oStatLog->AddTrace('Updated object - Values: {'.implode(', ', $aValueTrace).'}', $this);
  1321. $oStatLog->Inc($sStatsCode.'_updated');
  1322. $this->Set('info_last_modified', date('Y-m-d H:i:s'));
  1323. }
  1324. else
  1325. {
  1326. $oStatLog->AddTrace('Unchanged object', $this);
  1327. $oStatLog->Inc($sStatsCode.'_unchanged');
  1328. }
  1329. $this->Set('status_last_error', '');
  1330. $this->Set('status', 'synchronized');
  1331. }
  1332. catch(Exception $e)
  1333. {
  1334. $oStatLog->AddTrace("Failed to update destination object: {$e->getMessage()}", $this);
  1335. $this->SetLastError('Unable to update destination object: ', $e);
  1336. $oStatLog->Inc($sStatsCodeError);
  1337. }
  1338. }
  1339. /**
  1340. * Creates the destination object populating it with the Extended data found in the synchro_data_XXXX table
  1341. */
  1342. protected function CreateObjectFromReplica($sClass, $aAttributes, $oChange, &$oStatLog)
  1343. {
  1344. $oDestObj = MetaModel::NewObject($sClass);
  1345. try
  1346. {
  1347. $aValueTrace = array();
  1348. foreach($aAttributes as $sAttCode => $oSyncAtt)
  1349. {
  1350. $value = $this->GetValueFromExtData($sAttCode, $oSyncAtt, $oStatLog);
  1351. if (!is_null($value))
  1352. {
  1353. $oDestObj->Set($sAttCode, $value);
  1354. $aValueTrace[] = "$sAttCode: $value";
  1355. }
  1356. }
  1357. $iNew = $oDestObj->DBInsertTracked($oChange);
  1358. $this->Set('dest_id', $oDestObj->GetKey());
  1359. $this->Set('dest_class', get_class($oDestObj));
  1360. $this->Set('status_dest_creator', true);
  1361. $this->Set('status_last_error', '');
  1362. $this->Set('status', 'synchronized');
  1363. $this->Set('info_creation_date', date('Y-m-d H:i:s'));
  1364. $oStatLog->AddTrace("Created (".implode(', ', $aValueTrace).")", $this);
  1365. $oStatLog->Inc('stats_nb_obj_created');
  1366. }
  1367. catch(Exception $e)
  1368. {
  1369. $oStatLog->AddTrace("Failed to create $sClass ({$e->getMessage()})", $this);
  1370. $this->SetLastError('Unable to create destination object: ', $e);
  1371. $oStatLog->Inc('stats_nb_obj_created_errors');
  1372. }
  1373. }
  1374. /**
  1375. * Update the destination object with given values
  1376. */
  1377. public function UpdateDestObject($aValues, $oChange, &$oStatLog)
  1378. {
  1379. try
  1380. {
  1381. if ($this->Get('dest_class') == '')
  1382. {
  1383. $this->SetLastError('No destination object to update');
  1384. $oStatLog->Inc('stats_nb_obj_obsoleted_errors');
  1385. }
  1386. else
  1387. {
  1388. $oDestObj = MetaModel::GetObject($this->Get('dest_class'), $this->Get('dest_id'));
  1389. foreach($aValues as $sAttCode => $value)
  1390. {
  1391. $oDestObj->Set($sAttCode, $value);
  1392. }
  1393. $this->Set('info_last_modified', date('Y-m-d H:i:s'));
  1394. $oDestObj->DBUpdateTracked($oChange);
  1395. $oStatLog->AddTrace("Replica marked as obsolete", $this);
  1396. $oStatLog->Inc('stats_nb_obj_obsoleted');
  1397. }
  1398. }
  1399. catch(Exception $e)
  1400. {
  1401. $this->SetLastError('Unable to update the destination object: ', $e);
  1402. $oStatLog->Inc('stats_nb_obj_obsoleted_errors');
  1403. }
  1404. }
  1405. /**
  1406. * Delete the destination object
  1407. */
  1408. public function DeleteDestObject($oChange, &$oStatLog)
  1409. {
  1410. if($this->Get('status_dest_creator'))
  1411. {
  1412. try
  1413. {
  1414. $oDestObj = MetaModel::GetObject($this->Get('dest_class'), $this->Get('dest_id'));
  1415. $oDestObj->DBDeleteTracked($oChange);
  1416. $this->DBDeleteTracked($oChange);
  1417. $oStatLog->Inc('stats_nb_obj_deleted');
  1418. }
  1419. catch(Exception $e)
  1420. {
  1421. $this->SetLastError('Unable to delete the destination object: ', $e);
  1422. $this->Set('status', 'obsolete');
  1423. $this->DBUpdateTracked($oChange);
  1424. $oStatLog->Inc('stats_nb_obj_deleted_errors');
  1425. }
  1426. }
  1427. else
  1428. {
  1429. $this->DBDeleteTracked($oChange);
  1430. $oStatLog->Inc('stats_nb_replica_disappeared_no_action');
  1431. }
  1432. }
  1433. /**
  1434. * Get the value from the 'Extended Data' located in the synchro_data_xxx table for this replica
  1435. */
  1436. protected function GetValueFromExtData($sAttCode, $oSyncAtt, &$oStatLog)
  1437. {
  1438. // $aData should contain attributes defined either for reconciliation or create/update
  1439. $aData = $this->GetExtendedData();
  1440. $sClass = $this->Get('base_class');
  1441. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1442. if (!is_null($oSyncAtt) && ($oSyncAtt instanceof SynchroAttExtKey))
  1443. {
  1444. $rawValue = $aData[$sAttCode];
  1445. if (is_null($rawValue))
  1446. {
  1447. // Null means "ignore" this attribute
  1448. return null;
  1449. }
  1450. $sReconcAttCode = $oSyncAtt->Get('reconciliation_attcode');
  1451. if (!empty($sReconcAttCode))
  1452. {
  1453. $sRemoteClass = $oAttDef->GetTargetClass();
  1454. $oObj = MetaModel::GetObjectByColumn($sRemoteClass, $sReconcAttCode, $rawValue, false);
  1455. if ($oObj)
  1456. {
  1457. $retValue = $oObj->GetKey();
  1458. }
  1459. else
  1460. {
  1461. // Note: differs from null (in which case the value would be left unchanged)
  1462. $oStatLog->AddTrace("Could not find [unique] object for '$sAttCode': searched on $sReconcAttCode = '$rawValue'", $this);
  1463. $retValue = 0;
  1464. }
  1465. }
  1466. else
  1467. {
  1468. $retValue = $rawValue;
  1469. }
  1470. }
  1471. else
  1472. {
  1473. $aColumns = $oAttDef->GetImportColumns();
  1474. foreach($aColumns as $sColumn => $sFormat)
  1475. {
  1476. // In any case, a null column means "ignore this attribute"
  1477. //
  1478. if (is_null($aData[$sColumn]))
  1479. {
  1480. return null;
  1481. }
  1482. }
  1483. $retValue = $oAttDef->FromImportToValue($aData, $sAttCode);
  1484. }
  1485. return $retValue;
  1486. }
  1487. /**
  1488. * Maps the given context parameter name to the appropriate filter/search code for this class
  1489. * @param string $sContextParam Name of the context parameter, i.e. 'org_id'
  1490. * @return string Filter code, i.e. 'customer_id'
  1491. */
  1492. public static function MapContextParam($sContextParam)
  1493. {
  1494. if ($sContextParam == 'menu')
  1495. {
  1496. return null;
  1497. }
  1498. else
  1499. {
  1500. return $sContextParam;
  1501. }
  1502. }
  1503. /**
  1504. * This function returns a 'hilight' CSS class, used to hilight a given row in a table
  1505. * There are currently (i.e defined in the CSS) 4 possible values HILIGHT_CLASS_CRITICAL,
  1506. * HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  1507. * To Be overridden by derived classes
  1508. * @param void
  1509. * @return String The desired higlight class for the object/row
  1510. */
  1511. public function GetHilightClass()
  1512. {
  1513. // Possible return values are:
  1514. // HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
  1515. return HILIGHT_CLASS_NONE; // Not hilighted by default
  1516. }
  1517. public static function GetUIPage()
  1518. {
  1519. return '../synchro/replica.php';
  1520. }
  1521. function DisplayDetails(WebPage $oPage, $bEditMode = false)
  1522. {
  1523. // Object's details
  1524. //$this->DisplayBareHeader($oPage, $bEditMode);
  1525. $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
  1526. $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
  1527. $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
  1528. $this->DisplayBareProperties($oPage, $bEditMode);
  1529. }
  1530. function DisplayBareProperties(WebPage $oPage, $bEditMode = false)
  1531. {
  1532. if ($bEditMode) return; // Not editable
  1533. $oPage->add('<table style="vertical-align:top"><tr style="vertical-align:top"><td>');
  1534. $aDetails = array();
  1535. $sClass = get_class($this);
  1536. $oPage->add('<fieldset>');
  1537. $oPage->add('<legend>'.Dict::S('Core:SynchroReplica:PrivateDetails').'</legend>');
  1538. $aZList = MetaModel::FlattenZlist(MetaModel::GetZListItems($sClass, 'details'));
  1539. foreach( $aZList as $sAttCode)
  1540. {
  1541. $sDisplayValue = $this->GetAsHTML($sAttCode);
  1542. $aDetails[] = array('label' => '<span title="'.MetaModel::GetDescription($sClass, $sAttCode).'">'.MetaModel::GetLabel($sClass, $sAttCode).'</span>', 'value' => $sDisplayValue);
  1543. }
  1544. $oPage->Details($aDetails);
  1545. $oPage->add('</fieldset>');
  1546. $oPage->add('</td><td>');
  1547. $oPage->add('<fieldset>');
  1548. $oPage->add('<legend>'.Dict::S('Core:SynchroReplica:PublicData').'</legend>');
  1549. $oSource = MetaModel::GetObject('SynchroDataSource', $this->Get('sync_source_id'));
  1550. $sSQLTable = $oSource->GetDataTable();
  1551. $aData = $this->LoadExtendedDataFromTable($sSQLTable);
  1552. $aHeaders = array('attcode' => array('label' => 'Attribute Code', 'description' => ''),
  1553. 'data' => array('label' => 'Value', 'description' => ''));
  1554. $aRows = array();
  1555. foreach($aData as $sKey => $value)
  1556. {
  1557. $aRows[] = array('attcode' => $sKey, 'data' => $value);
  1558. }
  1559. $oPage->Table($aHeaders, $aRows);
  1560. $oPage->add('</fieldset>');
  1561. $oPage->add('</td></tr></table>');
  1562. }
  1563. public function LoadExtendedDataFromTable($sSQLTable)
  1564. {
  1565. $sSQL = "SELECT * FROM $sSQLTable WHERE id=".$this->GetKey();
  1566. $rQuery = CMDBSource::Query($sSQL);
  1567. return CMDBSource::FetchArray($rQuery);
  1568. }
  1569. }
  1570. // TO DO: finalize.... admins only ? which options ? troubleshoot WebPageMenuNode::__construct(.... sEnableClass...) ?
  1571. //if (UserRights::IsAdministrator())
  1572. {
  1573. $oAdminMenu = new MenuGroup('AdminTools', 80 /* fRank */);
  1574. new OQLMenuNode('DataSources', 'SELECT SynchroDataSource', $oAdminMenu->GetIndex(), 12 /* fRank */, true, 'SynchroDataSource', UR_ACTION_MODIFY, UR_ALLOWED_YES);
  1575. // new OQLMenuNode('Replicas', 'SELECT SynchroReplica', $oAdminMenu->GetIndex(), 12 /* fRank */, true, 'SynchroReplica', UR_ACTION_MODIFY, UR_ALLOWED_YES);
  1576. // new WebPageMenuNode('Test:RunSynchro', '../synchro/synchro_exec.php', $oAdminMenu->GetIndex(), 13 /* fRank */, 'SynchroDataSource');
  1577. }
  1578. ?>