cmdbchangeop.class.inc.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Persistent classes (internal) : cmdbChangeOp and derived
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. /**
  25. * Various atomic change operations, to be tracked
  26. *
  27. * @package iTopORM
  28. */
  29. class CMDBChangeOp extends DBObject
  30. {
  31. public static function Init()
  32. {
  33. $aParams = array
  34. (
  35. "category" => "core/cmdb",
  36. "key_type" => "autoincrement",
  37. "name_attcode" => "change",
  38. "state_attcode" => "",
  39. "reconc_keys" => array(),
  40. "db_table" => "priv_changeop",
  41. "db_key_field" => "id",
  42. "db_finalclass_field" => "optype",
  43. );
  44. MetaModel::Init_Params($aParams);
  45. //MetaModel::Init_InheritAttributes();
  46. MetaModel::Init_AddAttribute(new AttributeExternalKey("change", array("allowed_values"=>null, "sql"=>"changeid", "targetclass"=>"CMDBChange", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  47. MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date")));
  48. MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo")));
  49. MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  50. MetaModel::Init_AddAttribute(new AttributeString("objkey", array("allowed_values"=>null, "sql"=>"objkey", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  51. MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  52. MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  53. }
  54. /**
  55. * Describe (as a text string) the modifications corresponding to this change
  56. */
  57. public function GetDescription()
  58. {
  59. return '';
  60. }
  61. /**
  62. * Safety net: in case the change is not given, let's guarantee that it will
  63. * be set to the current ongoing change (or create a new one)
  64. */
  65. protected function OnInsert()
  66. {
  67. if ($this->Get('change') <= 0)
  68. {
  69. $this->Set('change', CMDBObject::GetCurrentChange());
  70. }
  71. parent::OnInsert();
  72. }
  73. }
  74. /**
  75. * Record the creation of an object
  76. *
  77. * @package iTopORM
  78. */
  79. class CMDBChangeOpCreate extends CMDBChangeOp
  80. {
  81. public static function Init()
  82. {
  83. $aParams = array
  84. (
  85. "category" => "core/cmdb",
  86. "key_type" => "",
  87. "name_attcode" => "change",
  88. "state_attcode" => "",
  89. "reconc_keys" => array(),
  90. "db_table" => "priv_changeop_create",
  91. "db_key_field" => "id",
  92. "db_finalclass_field" => "",
  93. );
  94. MetaModel::Init_Params($aParams);
  95. MetaModel::Init_InheritAttributes();
  96. }
  97. /**
  98. * Describe (as a text string) the modifications corresponding to this change
  99. */
  100. public function GetDescription()
  101. {
  102. return Dict::S('Change:ObjectCreated');
  103. }
  104. }
  105. /**
  106. * Record the deletion of an object
  107. *
  108. * @package iTopORM
  109. */
  110. class CMDBChangeOpDelete extends CMDBChangeOp
  111. {
  112. public static function Init()
  113. {
  114. $aParams = array
  115. (
  116. "category" => "core/cmdb",
  117. "key_type" => "",
  118. "name_attcode" => "change",
  119. "state_attcode" => "",
  120. "reconc_keys" => array(),
  121. "db_table" => "priv_changeop_delete",
  122. "db_key_field" => "id",
  123. "db_finalclass_field" => "",
  124. );
  125. MetaModel::Init_Params($aParams);
  126. MetaModel::Init_InheritAttributes();
  127. // Final class of the object (objclass must be set to the root class for efficiency purposes)
  128. MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  129. // Last friendly name of the object
  130. MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  131. }
  132. /**
  133. * Describe (as a text string) the modifications corresponding to this change
  134. */
  135. public function GetDescription()
  136. {
  137. return Dict::S('Change:ObjectDeleted');
  138. }
  139. }
  140. /**
  141. * Record the modification of an attribute (abstract)
  142. *
  143. * @package iTopORM
  144. */
  145. class CMDBChangeOpSetAttribute extends CMDBChangeOp
  146. {
  147. public static function Init()
  148. {
  149. $aParams = array
  150. (
  151. "category" => "core/cmdb",
  152. "key_type" => "",
  153. "name_attcode" => "change",
  154. "state_attcode" => "",
  155. "reconc_keys" => array(),
  156. "db_table" => "priv_changeop_setatt",
  157. "db_key_field" => "id",
  158. "db_finalclass_field" => "",
  159. );
  160. MetaModel::Init_Params($aParams);
  161. MetaModel::Init_InheritAttributes();
  162. MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  163. // Display lists
  164. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  165. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  166. }
  167. }
  168. /**
  169. * Record the modification of a scalar attribute
  170. *
  171. * @package iTopORM
  172. */
  173. class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute
  174. {
  175. public static function Init()
  176. {
  177. $aParams = array
  178. (
  179. "category" => "core/cmdb",
  180. "key_type" => "",
  181. "name_attcode" => "change",
  182. "state_attcode" => "",
  183. "reconc_keys" => array(),
  184. "db_table" => "priv_changeop_setatt_scalar",
  185. "db_key_field" => "id",
  186. "db_finalclass_field" => "",
  187. );
  188. MetaModel::Init_Params($aParams);
  189. MetaModel::Init_InheritAttributes();
  190. MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  191. MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  192. // Display lists
  193. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details
  194. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list
  195. }
  196. /**
  197. * Describe (as a text string) the modifications corresponding to this change
  198. */
  199. public function GetDescription()
  200. {
  201. $sResult = '';
  202. $oTargetObjectClass = $this->Get('objclass');
  203. $oTargetObjectKey = $this->Get('objkey');
  204. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  205. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  206. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  207. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  208. {
  209. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  210. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  211. $sAttName = $oAttDef->GetLabel();
  212. $sNewValue = $this->Get('newvalue');
  213. $sOldValue = $this->Get('oldvalue');
  214. $sResult = $oAttDef->GetAsHTMLForHistory($sOldValue, $sNewValue);
  215. }
  216. return $sResult;
  217. }
  218. }
  219. /**
  220. * Record the modification of a blob
  221. *
  222. * @package iTopORM
  223. */
  224. class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute
  225. {
  226. public static function Init()
  227. {
  228. $aParams = array
  229. (
  230. "category" => "core/cmdb",
  231. "key_type" => "",
  232. "name_attcode" => "change",
  233. "state_attcode" => "",
  234. "reconc_keys" => array(),
  235. "db_table" => "priv_changeop_setatt_data",
  236. "db_key_field" => "id",
  237. "db_finalclass_field" => "",
  238. );
  239. MetaModel::Init_Params($aParams);
  240. MetaModel::Init_InheritAttributes();
  241. MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array())));
  242. // Display lists
  243. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  244. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  245. }
  246. /**
  247. * Describe (as a text string) the modifications corresponding to this change
  248. */
  249. public function GetDescription()
  250. {
  251. // Temporary, until we change the options of GetDescription() -needs a more global revision
  252. $bIsHtml = true;
  253. $sResult = '';
  254. $oTargetObjectClass = $this->Get('objclass');
  255. $oTargetObjectKey = $this->Get('objkey');
  256. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  257. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  258. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  259. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  260. {
  261. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  262. {
  263. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  264. $sAttName = $oAttDef->GetLabel();
  265. }
  266. else
  267. {
  268. // The attribute was renamed or removed from the object ?
  269. $sAttName = $this->Get('attcode');
  270. }
  271. $oPrevDoc = $this->Get('prevdata');
  272. $sDocView = $oPrevDoc->GetAsHtml();
  273. $sDocView .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_',$oPrevDoc->GetDisplayLink(get_class($this), $this->GetKey(), 'prevdata')).", \n";
  274. $sDocView .= Dict::Format('UI:DownloadDocument_', $oPrevDoc->GetDownloadLink(get_class($this), $this->GetKey(), 'prevdata'))."\n";
  275. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  276. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView);
  277. }
  278. return $sResult;
  279. }
  280. }
  281. /**
  282. * Safely record the modification of one way encrypted password
  283. */
  284. class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute
  285. {
  286. public static function Init()
  287. {
  288. $aParams = array
  289. (
  290. "category" => "core/cmdb",
  291. "key_type" => "",
  292. "name_attcode" => "change",
  293. "state_attcode" => "",
  294. "reconc_keys" => array(),
  295. "db_table" => "priv_changeop_setatt_pwd",
  296. "db_key_field" => "id",
  297. "db_finalclass_field" => "",
  298. );
  299. MetaModel::Init_Params($aParams);
  300. MetaModel::Init_InheritAttributes();
  301. MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  302. // Display lists
  303. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  304. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  305. }
  306. /**
  307. * Describe (as a text string) the modifications corresponding to this change
  308. */
  309. public function GetDescription()
  310. {
  311. // Temporary, until we change the options of GetDescription() -needs a more global revision
  312. $bIsHtml = true;
  313. $sResult = '';
  314. $oTargetObjectClass = $this->Get('objclass');
  315. $oTargetObjectKey = $this->Get('objkey');
  316. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  317. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  318. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  319. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  320. {
  321. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  322. {
  323. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  324. $sAttName = $oAttDef->GetLabel();
  325. }
  326. else
  327. {
  328. // The attribute was renamed or removed from the object ?
  329. $sAttName = $this->Get('attcode');
  330. }
  331. $sResult = Dict::Format('Change:AttName_Changed', $sAttName);
  332. }
  333. return $sResult;
  334. }
  335. }
  336. /**
  337. * Safely record the modification of an encrypted field
  338. */
  339. class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute
  340. {
  341. public static function Init()
  342. {
  343. $aParams = array
  344. (
  345. "category" => "core/cmdb",
  346. "key_type" => "",
  347. "name_attcode" => "change",
  348. "state_attcode" => "",
  349. "reconc_keys" => array(),
  350. "db_table" => "priv_changeop_setatt_encrypted",
  351. "db_key_field" => "id",
  352. "db_finalclass_field" => "",
  353. );
  354. MetaModel::Init_Params($aParams);
  355. MetaModel::Init_InheritAttributes();
  356. MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  357. // Display lists
  358. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  359. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  360. }
  361. /**
  362. * Describe (as a text string) the modifications corresponding to this change
  363. */
  364. public function GetDescription()
  365. {
  366. // Temporary, until we change the options of GetDescription() -needs a more global revision
  367. $bIsHtml = true;
  368. $sResult = '';
  369. $oTargetObjectClass = $this->Get('objclass');
  370. $oTargetObjectKey = $this->Get('objkey');
  371. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  372. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  373. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  374. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  375. {
  376. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  377. {
  378. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  379. $sAttName = $oAttDef->GetLabel();
  380. }
  381. else
  382. {
  383. // The attribute was renamed or removed from the object ?
  384. $sAttName = $this->Get('attcode');
  385. }
  386. $sPrevString = $this->Get('prevstring');
  387. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString);
  388. }
  389. return $sResult;
  390. }
  391. }
  392. /**
  393. * Record the modification of a multiline string (text)
  394. *
  395. * @package iTopORM
  396. */
  397. class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute
  398. {
  399. public static function Init()
  400. {
  401. $aParams = array
  402. (
  403. "category" => "core/cmdb",
  404. "key_type" => "",
  405. "name_attcode" => "change",
  406. "state_attcode" => "",
  407. "reconc_keys" => array(),
  408. "db_table" => "priv_changeop_setatt_text",
  409. "db_key_field" => "id",
  410. "db_finalclass_field" => "",
  411. );
  412. MetaModel::Init_Params($aParams);
  413. MetaModel::Init_InheritAttributes();
  414. MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  415. // Display lists
  416. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  417. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  418. }
  419. /**
  420. * Describe (as a text string) the modifications corresponding to this change
  421. */
  422. public function GetDescription()
  423. {
  424. // Temporary, until we change the options of GetDescription() -needs a more global revision
  425. $bIsHtml = true;
  426. $sResult = '';
  427. $oTargetObjectClass = $this->Get('objclass');
  428. $oTargetObjectKey = $this->Get('objkey');
  429. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  430. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  431. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  432. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  433. {
  434. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  435. {
  436. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  437. $sAttName = $oAttDef->GetLabel();
  438. }
  439. else
  440. {
  441. // The attribute was renamed or removed from the object ?
  442. $sAttName = $this->Get('attcode');
  443. }
  444. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  445. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  446. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  447. }
  448. return $sResult;
  449. }
  450. }
  451. /**
  452. * Record the modification of a caselog (text)
  453. * since the caselog itself stores the history
  454. * of its entries, there is no need to duplicate
  455. * the text here
  456. *
  457. * @package iTopORM
  458. */
  459. class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute
  460. {
  461. public static function Init()
  462. {
  463. $aParams = array
  464. (
  465. "category" => "core/cmdb",
  466. "key_type" => "",
  467. "name_attcode" => "change",
  468. "state_attcode" => "",
  469. "reconc_keys" => array(),
  470. "db_table" => "priv_changeop_setatt_log",
  471. "db_key_field" => "id",
  472. "db_finalclass_field" => "",
  473. );
  474. MetaModel::Init_Params($aParams);
  475. MetaModel::Init_InheritAttributes();
  476. MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  477. // Display lists
  478. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  479. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  480. }
  481. /**
  482. * Describe (as a text string) the modifications corresponding to this change
  483. */
  484. public function GetDescription()
  485. {
  486. // Temporary, until we change the options of GetDescription() -needs a more global revision
  487. $bIsHtml = true;
  488. $sResult = '';
  489. $oTargetObjectClass = $this->Get('objclass');
  490. $oTargetObjectKey = $this->Get('objkey');
  491. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  492. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  493. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  494. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  495. {
  496. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  497. {
  498. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  499. $sAttName = $oAttDef->GetLabel();
  500. }
  501. else
  502. {
  503. // The attribute was renamed or removed from the object ?
  504. $sAttName = $this->Get('attcode');
  505. }
  506. $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName);
  507. }
  508. return $sResult;
  509. }
  510. }
  511. /**
  512. * Record an action made by a plug-in
  513. *
  514. * @package iTopORM
  515. */
  516. class CMDBChangeOpPlugin extends CMDBChangeOp
  517. {
  518. public static function Init()
  519. {
  520. $aParams = array
  521. (
  522. "category" => "core/cmdb",
  523. "key_type" => "",
  524. "name_attcode" => "change",
  525. "state_attcode" => "",
  526. "reconc_keys" => array(),
  527. "db_table" => "priv_changeop_plugin",
  528. "db_key_field" => "id",
  529. "db_finalclass_field" => "",
  530. );
  531. MetaModel::Init_Params($aParams);
  532. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  533. /* May be used later when implementing an extension mechanism that will allow the plug-ins to store some extra information and still degrades gracefully when the plug-in is desinstalled
  534. MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  535. MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  536. */
  537. MetaModel::Init_InheritAttributes();
  538. }
  539. /**
  540. * Describe (as a text string) the modifications corresponding to this change
  541. */
  542. public function GetDescription()
  543. {
  544. return $this->Get('description');
  545. }
  546. }
  547. /**
  548. * Record added/removed objects from within a link set
  549. *
  550. * @package iTopORM
  551. */
  552. abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute
  553. {
  554. public static function Init()
  555. {
  556. $aParams = array
  557. (
  558. "category" => "core/cmdb",
  559. "key_type" => "",
  560. "name_attcode" => "change",
  561. "state_attcode" => "",
  562. "reconc_keys" => array(),
  563. "db_table" => "priv_changeop_links",
  564. "db_key_field" => "id",
  565. "db_finalclass_field" => "",
  566. );
  567. MetaModel::Init_Params($aParams);
  568. MetaModel::Init_InheritAttributes();
  569. // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface)
  570. // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract)
  571. MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  572. MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  573. }
  574. }
  575. /**
  576. * Record added/removed objects from within a link set
  577. *
  578. * @package iTopORM
  579. */
  580. class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks
  581. {
  582. public static function Init()
  583. {
  584. $aParams = array
  585. (
  586. "category" => "core/cmdb",
  587. "key_type" => "",
  588. "name_attcode" => "change",
  589. "state_attcode" => "",
  590. "reconc_keys" => array(),
  591. "db_table" => "priv_changeop_links_addremove",
  592. "db_key_field" => "id",
  593. "db_finalclass_field" => "",
  594. );
  595. MetaModel::Init_Params($aParams);
  596. MetaModel::Init_InheritAttributes();
  597. MetaModel::Init_AddAttribute(new AttributeEnum("type", array("allowed_values"=>new ValueSetEnum('added,removed'), "sql"=>"type", "default_value"=>"added", "is_null_allowed"=>false, "depends_on"=>array())));
  598. }
  599. /**
  600. * Describe (as a text string) the modifications corresponding to this change
  601. */
  602. public function GetDescription()
  603. {
  604. $sResult = '';
  605. $oTargetObjectClass = $this->Get('objclass');
  606. $oTargetObjectKey = $this->Get('objkey');
  607. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  608. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  609. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  610. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  611. {
  612. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  613. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  614. $sAttName = $oAttDef->GetLabel();
  615. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  616. $sResult = $sAttName.' - ';
  617. switch ($this->Get('type'))
  618. {
  619. case 'added':
  620. $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc);
  621. break;
  622. case 'removed':
  623. $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc);
  624. break;
  625. }
  626. }
  627. return $sResult;
  628. }
  629. }
  630. /**
  631. * Record attribute changes from within a link set
  632. * A single record redirects to the modifications made within the same change
  633. *
  634. * @package iTopORM
  635. */
  636. class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks
  637. {
  638. public static function Init()
  639. {
  640. $aParams = array
  641. (
  642. "category" => "core/cmdb",
  643. "key_type" => "",
  644. "name_attcode" => "change",
  645. "state_attcode" => "",
  646. "reconc_keys" => array(),
  647. "db_table" => "priv_changeop_links_tune",
  648. "db_key_field" => "id",
  649. "db_finalclass_field" => "",
  650. );
  651. MetaModel::Init_Params($aParams);
  652. MetaModel::Init_InheritAttributes();
  653. MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  654. }
  655. /**
  656. * Describe (as a text string) the modifications corresponding to this change
  657. */
  658. public function GetDescription()
  659. {
  660. $sResult = '';
  661. $oTargetObjectClass = $this->Get('objclass');
  662. $oTargetObjectKey = $this->Get('objkey');
  663. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  664. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  665. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  666. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  667. {
  668. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  669. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  670. $sAttName = $oAttDef->GetLabel();
  671. $sLinkClass = $oAttDef->GetLinkedClass();
  672. $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL);
  673. // Search for changes on the corresponding link
  674. //
  675. $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute');
  676. $oSearch->AddCondition('change', $this->Get('change'), '=');
  677. $oSearch->AddCondition('objkey', $this->Get('link_id'), '=');
  678. if (count($aLinkClasses) == 1)
  679. {
  680. // Faster than the whole building of the expression below for just one value ??
  681. $oSearch->AddCondition('objclass', $sLinkClass, '=');
  682. }
  683. else
  684. {
  685. $oField = new FieldExpression('objclass', $oSearch->GetClassAlias());
  686. $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')';
  687. $sOQLCondition = $oField->Render()." IN $sListExpr";
  688. $oNewCondition = Expression::FromOQL($sOQLCondition);
  689. $oSearch->AddConditionExpression($oNewCondition);
  690. }
  691. $oSet = new DBObjectSet($oSearch);
  692. $aChanges = array();
  693. while ($oChangeOp = $oSet->Fetch())
  694. {
  695. $aChanges[] = $oChangeOp->GetDescription();
  696. }
  697. if (count($aChanges) == 0)
  698. {
  699. return '';
  700. }
  701. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  702. $sResult = $sAttName.' - ';
  703. $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc);
  704. $sResult .= ' : '.implode(', ', $aChanges);
  705. }
  706. return $sResult;
  707. }
  708. }
  709. ?>