cmdbchangeop.class.inc.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. <?php
  2. // Copyright (C) 2010-2013 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. 'indexes' => array(
  44. array('objclass', 'objkey'),
  45. )
  46. );
  47. MetaModel::Init_Params($aParams);
  48. //MetaModel::Init_InheritAttributes();
  49. 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())));
  50. MetaModel::Init_AddAttribute(new AttributeExternalField("date", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"date")));
  51. MetaModel::Init_AddAttribute(new AttributeExternalField("userinfo", array("allowed_values"=>null, "extkey_attcode"=>"change", "target_attcode"=>"userinfo")));
  52. MetaModel::Init_AddAttribute(new AttributeString("objclass", array("allowed_values"=>null, "sql"=>"objclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  53. MetaModel::Init_AddAttribute(new AttributeObjectKey("objkey", array("allowed_values"=>null, "class_attcode"=>"objclass", "sql"=>"objkey", "is_null_allowed"=>false, "depends_on"=>array())));
  54. MetaModel::Init_SetZListItems('details', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  55. MetaModel::Init_SetZListItems('list', array('change', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  56. }
  57. /**
  58. * Describe (as a text string) the modifications corresponding to this change
  59. */
  60. public function GetDescription()
  61. {
  62. return '';
  63. }
  64. /**
  65. * Safety net: in case the change is not given, let's guarantee that it will
  66. * be set to the current ongoing change (or create a new one)
  67. */
  68. protected function OnInsert()
  69. {
  70. if ($this->Get('change') <= 0)
  71. {
  72. $this->Set('change', CMDBObject::GetCurrentChange());
  73. }
  74. parent::OnInsert();
  75. }
  76. }
  77. /**
  78. * Record the creation of an object
  79. *
  80. * @package iTopORM
  81. */
  82. class CMDBChangeOpCreate extends CMDBChangeOp
  83. {
  84. public static function Init()
  85. {
  86. $aParams = array
  87. (
  88. "category" => "core/cmdb",
  89. "key_type" => "",
  90. "name_attcode" => "change",
  91. "state_attcode" => "",
  92. "reconc_keys" => array(),
  93. "db_table" => "priv_changeop_create",
  94. "db_key_field" => "id",
  95. "db_finalclass_field" => "",
  96. );
  97. MetaModel::Init_Params($aParams);
  98. MetaModel::Init_InheritAttributes();
  99. }
  100. /**
  101. * Describe (as a text string) the modifications corresponding to this change
  102. */
  103. public function GetDescription()
  104. {
  105. return Dict::S('Change:ObjectCreated');
  106. }
  107. }
  108. /**
  109. * Record the deletion of an object
  110. *
  111. * @package iTopORM
  112. */
  113. class CMDBChangeOpDelete extends CMDBChangeOp
  114. {
  115. public static function Init()
  116. {
  117. $aParams = array
  118. (
  119. "category" => "core/cmdb",
  120. "key_type" => "",
  121. "name_attcode" => "change",
  122. "state_attcode" => "",
  123. "reconc_keys" => array(),
  124. "db_table" => "priv_changeop_delete",
  125. "db_key_field" => "id",
  126. "db_finalclass_field" => "",
  127. );
  128. MetaModel::Init_Params($aParams);
  129. MetaModel::Init_InheritAttributes();
  130. // Final class of the object (objclass must be set to the root class for efficiency purposes)
  131. MetaModel::Init_AddAttribute(new AttributeString("fclass", array("allowed_values"=>null, "sql"=>"fclass", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  132. // Last friendly name of the object
  133. MetaModel::Init_AddAttribute(new AttributeString("fname", array("allowed_values"=>null, "sql"=>"fname", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  134. }
  135. /**
  136. * Describe (as a text string) the modifications corresponding to this change
  137. */
  138. public function GetDescription()
  139. {
  140. return Dict::S('Change:ObjectDeleted');
  141. }
  142. }
  143. /**
  144. * Record the modification of an attribute (abstract)
  145. *
  146. * @package iTopORM
  147. */
  148. class CMDBChangeOpSetAttribute extends CMDBChangeOp
  149. {
  150. public static function Init()
  151. {
  152. $aParams = array
  153. (
  154. "category" => "core/cmdb",
  155. "key_type" => "",
  156. "name_attcode" => "change",
  157. "state_attcode" => "",
  158. "reconc_keys" => array(),
  159. "db_table" => "priv_changeop_setatt",
  160. "db_key_field" => "id",
  161. "db_finalclass_field" => "",
  162. );
  163. MetaModel::Init_Params($aParams);
  164. MetaModel::Init_InheritAttributes();
  165. MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  166. // Display lists
  167. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  168. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  169. }
  170. }
  171. /**
  172. * Record the modification of a scalar attribute
  173. *
  174. * @package iTopORM
  175. */
  176. class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute
  177. {
  178. public static function Init()
  179. {
  180. $aParams = array
  181. (
  182. "category" => "core/cmdb",
  183. "key_type" => "",
  184. "name_attcode" => "change",
  185. "state_attcode" => "",
  186. "reconc_keys" => array(),
  187. "db_table" => "priv_changeop_setatt_scalar",
  188. "db_key_field" => "id",
  189. "db_finalclass_field" => "",
  190. );
  191. MetaModel::Init_Params($aParams);
  192. MetaModel::Init_InheritAttributes();
  193. MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  194. MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  195. // Display lists
  196. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details
  197. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list
  198. }
  199. /**
  200. * Describe (as a text string) the modifications corresponding to this change
  201. */
  202. public function GetDescription()
  203. {
  204. $sResult = '';
  205. $oTargetObjectClass = $this->Get('objclass');
  206. $oTargetObjectKey = $this->Get('objkey');
  207. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  208. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  209. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  210. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  211. {
  212. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  213. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  214. $sAttName = $oAttDef->GetLabel();
  215. $sNewValue = $this->Get('newvalue');
  216. $sOldValue = $this->Get('oldvalue');
  217. $sResult = $oAttDef->DescribeChangeAsHTML($sOldValue, $sNewValue);
  218. }
  219. return $sResult;
  220. }
  221. }
  222. /**
  223. * Record the modification of a blob
  224. *
  225. * @package iTopORM
  226. */
  227. class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute
  228. {
  229. public static function Init()
  230. {
  231. $aParams = array
  232. (
  233. "category" => "core/cmdb",
  234. "key_type" => "",
  235. "name_attcode" => "change",
  236. "state_attcode" => "",
  237. "reconc_keys" => array(),
  238. "db_table" => "priv_changeop_setatt_data",
  239. "db_key_field" => "id",
  240. "db_finalclass_field" => "",
  241. );
  242. MetaModel::Init_Params($aParams);
  243. MetaModel::Init_InheritAttributes();
  244. MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array())));
  245. // Display lists
  246. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  247. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  248. }
  249. /**
  250. * Describe (as a text string) the modifications corresponding to this change
  251. */
  252. public function GetDescription()
  253. {
  254. // Temporary, until we change the options of GetDescription() -needs a more global revision
  255. $bIsHtml = true;
  256. $sResult = '';
  257. $oTargetObjectClass = $this->Get('objclass');
  258. $oTargetObjectKey = $this->Get('objkey');
  259. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  260. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  261. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  262. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  263. {
  264. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  265. {
  266. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  267. $sAttName = $oAttDef->GetLabel();
  268. }
  269. else
  270. {
  271. // The attribute was renamed or removed from the object ?
  272. $sAttName = $this->Get('attcode');
  273. }
  274. $oPrevDoc = $this->Get('prevdata');
  275. $sDocView = $oPrevDoc->GetAsHtml();
  276. $sDocView .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_',$oPrevDoc->GetDisplayLink(get_class($this), $this->GetKey(), 'prevdata')).", \n";
  277. $sDocView .= Dict::Format('UI:DownloadDocument_', $oPrevDoc->GetDownloadLink(get_class($this), $this->GetKey(), 'prevdata'))."\n";
  278. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  279. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView);
  280. }
  281. return $sResult;
  282. }
  283. }
  284. /**
  285. * Safely record the modification of one way encrypted password
  286. */
  287. class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute
  288. {
  289. public static function Init()
  290. {
  291. $aParams = array
  292. (
  293. "category" => "core/cmdb",
  294. "key_type" => "",
  295. "name_attcode" => "change",
  296. "state_attcode" => "",
  297. "reconc_keys" => array(),
  298. "db_table" => "priv_changeop_setatt_pwd",
  299. "db_key_field" => "id",
  300. "db_finalclass_field" => "",
  301. );
  302. MetaModel::Init_Params($aParams);
  303. MetaModel::Init_InheritAttributes();
  304. MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  305. // Display lists
  306. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  307. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  308. }
  309. /**
  310. * Describe (as a text string) the modifications corresponding to this change
  311. */
  312. public function GetDescription()
  313. {
  314. // Temporary, until we change the options of GetDescription() -needs a more global revision
  315. $bIsHtml = true;
  316. $sResult = '';
  317. $oTargetObjectClass = $this->Get('objclass');
  318. $oTargetObjectKey = $this->Get('objkey');
  319. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  320. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  321. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  322. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  323. {
  324. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  325. {
  326. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  327. $sAttName = $oAttDef->GetLabel();
  328. }
  329. else
  330. {
  331. // The attribute was renamed or removed from the object ?
  332. $sAttName = $this->Get('attcode');
  333. }
  334. $sResult = Dict::Format('Change:AttName_Changed', $sAttName);
  335. }
  336. return $sResult;
  337. }
  338. }
  339. /**
  340. * Safely record the modification of an encrypted field
  341. */
  342. class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute
  343. {
  344. public static function Init()
  345. {
  346. $aParams = array
  347. (
  348. "category" => "core/cmdb",
  349. "key_type" => "",
  350. "name_attcode" => "change",
  351. "state_attcode" => "",
  352. "reconc_keys" => array(),
  353. "db_table" => "priv_changeop_setatt_encrypted",
  354. "db_key_field" => "id",
  355. "db_finalclass_field" => "",
  356. );
  357. MetaModel::Init_Params($aParams);
  358. MetaModel::Init_InheritAttributes();
  359. MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  360. // Display lists
  361. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  362. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  363. }
  364. /**
  365. * Describe (as a text string) the modifications corresponding to this change
  366. */
  367. public function GetDescription()
  368. {
  369. // Temporary, until we change the options of GetDescription() -needs a more global revision
  370. $bIsHtml = true;
  371. $sResult = '';
  372. $oTargetObjectClass = $this->Get('objclass');
  373. $oTargetObjectKey = $this->Get('objkey');
  374. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  375. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  376. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  377. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  378. {
  379. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  380. {
  381. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  382. $sAttName = $oAttDef->GetLabel();
  383. }
  384. else
  385. {
  386. // The attribute was renamed or removed from the object ?
  387. $sAttName = $this->Get('attcode');
  388. }
  389. $sPrevString = $this->Get('prevstring');
  390. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString);
  391. }
  392. return $sResult;
  393. }
  394. }
  395. /**
  396. * Record the modification of a multiline string (text)
  397. *
  398. * @package iTopORM
  399. */
  400. class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute
  401. {
  402. public static function Init()
  403. {
  404. $aParams = array
  405. (
  406. "category" => "core/cmdb",
  407. "key_type" => "",
  408. "name_attcode" => "change",
  409. "state_attcode" => "",
  410. "reconc_keys" => array(),
  411. "db_table" => "priv_changeop_setatt_text",
  412. "db_key_field" => "id",
  413. "db_finalclass_field" => "",
  414. );
  415. MetaModel::Init_Params($aParams);
  416. MetaModel::Init_InheritAttributes();
  417. MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  418. // Display lists
  419. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  420. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  421. }
  422. /**
  423. * Describe (as a text string) the modifications corresponding to this change
  424. */
  425. public function GetDescription()
  426. {
  427. // Temporary, until we change the options of GetDescription() -needs a more global revision
  428. $bIsHtml = true;
  429. $sResult = '';
  430. $oTargetObjectClass = $this->Get('objclass');
  431. $oTargetObjectKey = $this->Get('objkey');
  432. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  433. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  434. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  435. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  436. {
  437. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  438. {
  439. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  440. $sAttName = $oAttDef->GetLabel();
  441. }
  442. else
  443. {
  444. // The attribute was renamed or removed from the object ?
  445. $sAttName = $this->Get('attcode');
  446. }
  447. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  448. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  449. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  450. }
  451. return $sResult;
  452. }
  453. }
  454. /**
  455. * Record the modification of a multiline string (text)
  456. *
  457. * @package iTopORM
  458. */
  459. class CMDBChangeOpSetAttributeLongText 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_longtext",
  471. "db_key_field" => "id",
  472. "db_finalclass_field" => "",
  473. );
  474. MetaModel::Init_Params($aParams);
  475. MetaModel::Init_InheritAttributes();
  476. MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "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. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  507. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  508. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  509. }
  510. return $sResult;
  511. }
  512. }
  513. /**
  514. * Record the modification of a caselog (text)
  515. * since the caselog itself stores the history
  516. * of its entries, there is no need to duplicate
  517. * the text here
  518. *
  519. * @package iTopORM
  520. */
  521. class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute
  522. {
  523. public static function Init()
  524. {
  525. $aParams = array
  526. (
  527. "category" => "core/cmdb",
  528. "key_type" => "",
  529. "name_attcode" => "change",
  530. "state_attcode" => "",
  531. "reconc_keys" => array(),
  532. "db_table" => "priv_changeop_setatt_log",
  533. "db_key_field" => "id",
  534. "db_finalclass_field" => "",
  535. );
  536. MetaModel::Init_Params($aParams);
  537. MetaModel::Init_InheritAttributes();
  538. MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  539. // Display lists
  540. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  541. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  542. }
  543. /**
  544. * Describe (as a text string) the modifications corresponding to this change
  545. */
  546. public function GetDescription()
  547. {
  548. // Temporary, until we change the options of GetDescription() -needs a more global revision
  549. $bIsHtml = true;
  550. $sResult = '';
  551. $oTargetObjectClass = $this->Get('objclass');
  552. $oTargetObjectKey = $this->Get('objkey');
  553. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  554. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  555. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  556. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  557. {
  558. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  559. {
  560. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  561. $sAttName = $oAttDef->GetLabel();
  562. }
  563. else
  564. {
  565. // The attribute was renamed or removed from the object ?
  566. $sAttName = $this->Get('attcode');
  567. }
  568. $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName);
  569. }
  570. return $sResult;
  571. }
  572. }
  573. /**
  574. * Record an action made by a plug-in
  575. *
  576. * @package iTopORM
  577. */
  578. class CMDBChangeOpPlugin extends CMDBChangeOp
  579. {
  580. public static function Init()
  581. {
  582. $aParams = array
  583. (
  584. "category" => "core/cmdb",
  585. "key_type" => "",
  586. "name_attcode" => "change",
  587. "state_attcode" => "",
  588. "reconc_keys" => array(),
  589. "db_table" => "priv_changeop_plugin",
  590. "db_key_field" => "id",
  591. "db_finalclass_field" => "",
  592. );
  593. MetaModel::Init_Params($aParams);
  594. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  595. /* 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
  596. MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  597. MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  598. */
  599. MetaModel::Init_InheritAttributes();
  600. }
  601. /**
  602. * Describe (as a text string) the modifications corresponding to this change
  603. */
  604. public function GetDescription()
  605. {
  606. return $this->Get('description');
  607. }
  608. }
  609. /**
  610. * Record added/removed objects from within a link set
  611. *
  612. * @package iTopORM
  613. */
  614. abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute
  615. {
  616. public static function Init()
  617. {
  618. $aParams = array
  619. (
  620. "category" => "core/cmdb",
  621. "key_type" => "",
  622. "name_attcode" => "change",
  623. "state_attcode" => "",
  624. "reconc_keys" => array(),
  625. "db_table" => "priv_changeop_links",
  626. "db_key_field" => "id",
  627. "db_finalclass_field" => "",
  628. );
  629. MetaModel::Init_Params($aParams);
  630. MetaModel::Init_InheritAttributes();
  631. // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface)
  632. // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract)
  633. MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  634. MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  635. }
  636. }
  637. /**
  638. * Record added/removed objects from within a link set
  639. *
  640. * @package iTopORM
  641. */
  642. class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks
  643. {
  644. public static function Init()
  645. {
  646. $aParams = array
  647. (
  648. "category" => "core/cmdb",
  649. "key_type" => "",
  650. "name_attcode" => "change",
  651. "state_attcode" => "",
  652. "reconc_keys" => array(),
  653. "db_table" => "priv_changeop_links_addremove",
  654. "db_key_field" => "id",
  655. "db_finalclass_field" => "",
  656. );
  657. MetaModel::Init_Params($aParams);
  658. MetaModel::Init_InheritAttributes();
  659. 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())));
  660. }
  661. /**
  662. * Describe (as a text string) the modifications corresponding to this change
  663. */
  664. public function GetDescription()
  665. {
  666. $sResult = '';
  667. $oTargetObjectClass = $this->Get('objclass');
  668. $oTargetObjectKey = $this->Get('objkey');
  669. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  670. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  671. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  672. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  673. {
  674. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  675. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  676. $sAttName = $oAttDef->GetLabel();
  677. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  678. $sResult = $sAttName.' - ';
  679. switch ($this->Get('type'))
  680. {
  681. case 'added':
  682. $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc);
  683. break;
  684. case 'removed':
  685. $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc);
  686. break;
  687. }
  688. }
  689. return $sResult;
  690. }
  691. }
  692. /**
  693. * Record attribute changes from within a link set
  694. * A single record redirects to the modifications made within the same change
  695. *
  696. * @package iTopORM
  697. */
  698. class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks
  699. {
  700. public static function Init()
  701. {
  702. $aParams = array
  703. (
  704. "category" => "core/cmdb",
  705. "key_type" => "",
  706. "name_attcode" => "change",
  707. "state_attcode" => "",
  708. "reconc_keys" => array(),
  709. "db_table" => "priv_changeop_links_tune",
  710. "db_key_field" => "id",
  711. "db_finalclass_field" => "",
  712. );
  713. MetaModel::Init_Params($aParams);
  714. MetaModel::Init_InheritAttributes();
  715. MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  716. }
  717. /**
  718. * Describe (as a text string) the modifications corresponding to this change
  719. */
  720. public function GetDescription()
  721. {
  722. $sResult = '';
  723. $oTargetObjectClass = $this->Get('objclass');
  724. $oTargetObjectKey = $this->Get('objkey');
  725. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  726. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  727. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  728. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  729. {
  730. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  731. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  732. $sAttName = $oAttDef->GetLabel();
  733. $sLinkClass = $oAttDef->GetLinkedClass();
  734. $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL);
  735. // Search for changes on the corresponding link
  736. //
  737. $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute');
  738. $oSearch->AddCondition('change', $this->Get('change'), '=');
  739. $oSearch->AddCondition('objkey', $this->Get('link_id'), '=');
  740. if (count($aLinkClasses) == 1)
  741. {
  742. // Faster than the whole building of the expression below for just one value ??
  743. $oSearch->AddCondition('objclass', $sLinkClass, '=');
  744. }
  745. else
  746. {
  747. $oField = new FieldExpression('objclass', $oSearch->GetClassAlias());
  748. $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')';
  749. $sOQLCondition = $oField->Render()." IN $sListExpr";
  750. $oNewCondition = Expression::FromOQL($sOQLCondition);
  751. $oSearch->AddConditionExpression($oNewCondition);
  752. }
  753. $oSet = new DBObjectSet($oSearch);
  754. $aChanges = array();
  755. while ($oChangeOp = $oSet->Fetch())
  756. {
  757. $aChanges[] = $oChangeOp->GetDescription();
  758. }
  759. if (count($aChanges) == 0)
  760. {
  761. return '';
  762. }
  763. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  764. $sResult = $sAttName.' - ';
  765. $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc);
  766. $sResult .= ' : '.implode(', ', $aChanges);
  767. }
  768. return $sResult;
  769. }
  770. }
  771. ?>