cmdbchangeop.class.inc.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  262. $sAttName = $oAttDef->GetLabel();
  263. $oPrevDoc = $this->Get('prevdata');
  264. $sDocView = $oPrevDoc->GetAsHtml();
  265. $sDocView .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_',$oPrevDoc->GetDisplayLink(get_class($this), $this->GetKey(), 'prevdata')).", \n";
  266. $sDocView .= Dict::Format('UI:DownloadDocument_', $oPrevDoc->GetDownloadLink(get_class($this), $this->GetKey(), 'prevdata'))."\n";
  267. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  268. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView);
  269. }
  270. return $sResult;
  271. }
  272. }
  273. /**
  274. * Safely record the modification of one way encrypted password
  275. */
  276. class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute
  277. {
  278. public static function Init()
  279. {
  280. $aParams = array
  281. (
  282. "category" => "core/cmdb",
  283. "key_type" => "",
  284. "name_attcode" => "change",
  285. "state_attcode" => "",
  286. "reconc_keys" => array(),
  287. "db_table" => "priv_changeop_setatt_pwd",
  288. "db_key_field" => "id",
  289. "db_finalclass_field" => "",
  290. );
  291. MetaModel::Init_Params($aParams);
  292. MetaModel::Init_InheritAttributes();
  293. MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  294. // Display lists
  295. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  296. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  297. }
  298. /**
  299. * Describe (as a text string) the modifications corresponding to this change
  300. */
  301. public function GetDescription()
  302. {
  303. // Temporary, until we change the options of GetDescription() -needs a more global revision
  304. $bIsHtml = true;
  305. $sResult = '';
  306. $oTargetObjectClass = $this->Get('objclass');
  307. $oTargetObjectKey = $this->Get('objkey');
  308. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  309. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  310. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  311. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  312. {
  313. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  314. $sAttName = $oAttDef->GetLabel();
  315. $sResult = Dict::Format('Change:AttName_Changed', $sAttName);
  316. }
  317. return $sResult;
  318. }
  319. }
  320. /**
  321. * Safely record the modification of an encrypted field
  322. */
  323. class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute
  324. {
  325. public static function Init()
  326. {
  327. $aParams = array
  328. (
  329. "category" => "core/cmdb",
  330. "key_type" => "",
  331. "name_attcode" => "change",
  332. "state_attcode" => "",
  333. "reconc_keys" => array(),
  334. "db_table" => "priv_changeop_setatt_encrypted",
  335. "db_key_field" => "id",
  336. "db_finalclass_field" => "",
  337. );
  338. MetaModel::Init_Params($aParams);
  339. MetaModel::Init_InheritAttributes();
  340. MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  341. // Display lists
  342. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  343. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  344. }
  345. /**
  346. * Describe (as a text string) the modifications corresponding to this change
  347. */
  348. public function GetDescription()
  349. {
  350. // Temporary, until we change the options of GetDescription() -needs a more global revision
  351. $bIsHtml = true;
  352. $sResult = '';
  353. $oTargetObjectClass = $this->Get('objclass');
  354. $oTargetObjectKey = $this->Get('objkey');
  355. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  356. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  357. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  358. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  359. {
  360. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  361. $sAttName = $oAttDef->GetLabel();
  362. $sPrevString = $this->Get('prevstring');
  363. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString);
  364. }
  365. return $sResult;
  366. }
  367. }
  368. /**
  369. * Record the modification of a multiline string (text)
  370. *
  371. * @package iTopORM
  372. */
  373. class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute
  374. {
  375. public static function Init()
  376. {
  377. $aParams = array
  378. (
  379. "category" => "core/cmdb",
  380. "key_type" => "",
  381. "name_attcode" => "change",
  382. "state_attcode" => "",
  383. "reconc_keys" => array(),
  384. "db_table" => "priv_changeop_setatt_text",
  385. "db_key_field" => "id",
  386. "db_finalclass_field" => "",
  387. );
  388. MetaModel::Init_Params($aParams);
  389. MetaModel::Init_InheritAttributes();
  390. MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  391. // Display lists
  392. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  393. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  394. }
  395. /**
  396. * Describe (as a text string) the modifications corresponding to this change
  397. */
  398. public function GetDescription()
  399. {
  400. // Temporary, until we change the options of GetDescription() -needs a more global revision
  401. $bIsHtml = true;
  402. $sResult = '';
  403. $oTargetObjectClass = $this->Get('objclass');
  404. $oTargetObjectKey = $this->Get('objkey');
  405. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  406. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  407. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  408. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  409. {
  410. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  411. $sAttName = $oAttDef->GetLabel();
  412. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  413. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  414. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  415. }
  416. return $sResult;
  417. }
  418. }
  419. /**
  420. * Record the modification of a caselog (text)
  421. * since the caselog itself stores the history
  422. * of its entries, there is no need to duplicate
  423. * the text here
  424. *
  425. * @package iTopORM
  426. */
  427. class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute
  428. {
  429. public static function Init()
  430. {
  431. $aParams = array
  432. (
  433. "category" => "core/cmdb",
  434. "key_type" => "",
  435. "name_attcode" => "change",
  436. "state_attcode" => "",
  437. "reconc_keys" => array(),
  438. "db_table" => "priv_changeop_setatt_log",
  439. "db_key_field" => "id",
  440. "db_finalclass_field" => "",
  441. );
  442. MetaModel::Init_Params($aParams);
  443. MetaModel::Init_InheritAttributes();
  444. MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  445. // Display lists
  446. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  447. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  448. }
  449. /**
  450. * Describe (as a text string) the modifications corresponding to this change
  451. */
  452. public function GetDescription()
  453. {
  454. // Temporary, until we change the options of GetDescription() -needs a more global revision
  455. $bIsHtml = true;
  456. $sResult = '';
  457. $oTargetObjectClass = $this->Get('objclass');
  458. $oTargetObjectKey = $this->Get('objkey');
  459. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  460. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  461. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  462. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  463. {
  464. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  465. $sAttName = $oAttDef->GetLabel();
  466. $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName);
  467. }
  468. return $sResult;
  469. }
  470. }
  471. /**
  472. * Record an action made by a plug-in
  473. *
  474. * @package iTopORM
  475. */
  476. class CMDBChangeOpPlugin extends CMDBChangeOp
  477. {
  478. public static function Init()
  479. {
  480. $aParams = array
  481. (
  482. "category" => "core/cmdb",
  483. "key_type" => "",
  484. "name_attcode" => "change",
  485. "state_attcode" => "",
  486. "reconc_keys" => array(),
  487. "db_table" => "priv_changeop_plugin",
  488. "db_key_field" => "id",
  489. "db_finalclass_field" => "",
  490. );
  491. MetaModel::Init_Params($aParams);
  492. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  493. /* 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
  494. MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  495. MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  496. */
  497. MetaModel::Init_InheritAttributes();
  498. }
  499. /**
  500. * Describe (as a text string) the modifications corresponding to this change
  501. */
  502. public function GetDescription()
  503. {
  504. return $this->Get('description');
  505. }
  506. }
  507. /**
  508. * Record added/removed objects from within a link set
  509. *
  510. * @package iTopORM
  511. */
  512. abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute
  513. {
  514. public static function Init()
  515. {
  516. $aParams = array
  517. (
  518. "category" => "core/cmdb",
  519. "key_type" => "",
  520. "name_attcode" => "change",
  521. "state_attcode" => "",
  522. "reconc_keys" => array(),
  523. "db_table" => "priv_changeop_links",
  524. "db_key_field" => "id",
  525. "db_finalclass_field" => "",
  526. );
  527. MetaModel::Init_Params($aParams);
  528. MetaModel::Init_InheritAttributes();
  529. // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface)
  530. // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract)
  531. MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  532. MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  533. }
  534. }
  535. /**
  536. * Record added/removed objects from within a link set
  537. *
  538. * @package iTopORM
  539. */
  540. class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks
  541. {
  542. public static function Init()
  543. {
  544. $aParams = array
  545. (
  546. "category" => "core/cmdb",
  547. "key_type" => "",
  548. "name_attcode" => "change",
  549. "state_attcode" => "",
  550. "reconc_keys" => array(),
  551. "db_table" => "priv_changeop_links_addremove",
  552. "db_key_field" => "id",
  553. "db_finalclass_field" => "",
  554. );
  555. MetaModel::Init_Params($aParams);
  556. MetaModel::Init_InheritAttributes();
  557. 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())));
  558. }
  559. /**
  560. * Describe (as a text string) the modifications corresponding to this change
  561. */
  562. public function GetDescription()
  563. {
  564. $sResult = '';
  565. $oTargetObjectClass = $this->Get('objclass');
  566. $oTargetObjectKey = $this->Get('objkey');
  567. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  568. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  569. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  570. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  571. {
  572. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  573. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  574. $sAttName = $oAttDef->GetLabel();
  575. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  576. $sResult = $sAttName.' - ';
  577. switch ($this->Get('type'))
  578. {
  579. case 'added':
  580. $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc);
  581. break;
  582. case 'removed':
  583. $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc);
  584. break;
  585. }
  586. }
  587. return $sResult;
  588. }
  589. }
  590. /**
  591. * Record attribute changes from within a link set
  592. * A single record redirects to the modifications made within the same change
  593. *
  594. * @package iTopORM
  595. */
  596. class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks
  597. {
  598. public static function Init()
  599. {
  600. $aParams = array
  601. (
  602. "category" => "core/cmdb",
  603. "key_type" => "",
  604. "name_attcode" => "change",
  605. "state_attcode" => "",
  606. "reconc_keys" => array(),
  607. "db_table" => "priv_changeop_links_tune",
  608. "db_key_field" => "id",
  609. "db_finalclass_field" => "",
  610. );
  611. MetaModel::Init_Params($aParams);
  612. MetaModel::Init_InheritAttributes();
  613. MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  614. }
  615. /**
  616. * Describe (as a text string) the modifications corresponding to this change
  617. */
  618. public function GetDescription()
  619. {
  620. $sResult = '';
  621. $oTargetObjectClass = $this->Get('objclass');
  622. $oTargetObjectKey = $this->Get('objkey');
  623. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  624. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  625. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  626. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  627. {
  628. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  629. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  630. $sAttName = $oAttDef->GetLabel();
  631. $sLinkClass = $oAttDef->GetLinkedClass();
  632. // Search for changes on the corresponding link
  633. //
  634. $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute');
  635. $oSearch->AddCondition('change', $this->Get('change'), '=');
  636. $oSearch->AddCondition('objclass', $sLinkClass, '=');
  637. $oSearch->AddCondition('objkey', $this->Get('link_id'), '=');
  638. $oSet = new DBObjectSet($oSearch);
  639. $aChanges = array();
  640. while ($oChangeOp = $oSet->Fetch())
  641. {
  642. $aChanges[] = $oChangeOp->GetDescription();
  643. }
  644. if (count($aChanges) == 0)
  645. {
  646. return '';
  647. }
  648. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  649. $sResult = $sAttName.' - ';
  650. $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc);
  651. $sResult .= ' : '.implode(', ', $aChanges);
  652. }
  653. return $sResult;
  654. }
  655. }
  656. ?>