cmdbchangeop.class.inc.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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 multiline string (text)
  453. *
  454. * @package iTopORM
  455. */
  456. class CMDBChangeOpSetAttributeLongText extends CMDBChangeOpSetAttribute
  457. {
  458. public static function Init()
  459. {
  460. $aParams = array
  461. (
  462. "category" => "core/cmdb",
  463. "key_type" => "",
  464. "name_attcode" => "change",
  465. "state_attcode" => "",
  466. "reconc_keys" => array(),
  467. "db_table" => "priv_changeop_setatt_longtext",
  468. "db_key_field" => "id",
  469. "db_finalclass_field" => "",
  470. );
  471. MetaModel::Init_Params($aParams);
  472. MetaModel::Init_InheritAttributes();
  473. MetaModel::Init_AddAttribute(new AttributeLongText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  474. // Display lists
  475. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  476. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  477. }
  478. /**
  479. * Describe (as a text string) the modifications corresponding to this change
  480. */
  481. public function GetDescription()
  482. {
  483. // Temporary, until we change the options of GetDescription() -needs a more global revision
  484. $bIsHtml = true;
  485. $sResult = '';
  486. $oTargetObjectClass = $this->Get('objclass');
  487. $oTargetObjectKey = $this->Get('objkey');
  488. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  489. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  490. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  491. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  492. {
  493. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  494. {
  495. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  496. $sAttName = $oAttDef->GetLabel();
  497. }
  498. else
  499. {
  500. // The attribute was renamed or removed from the object ?
  501. $sAttName = $this->Get('attcode');
  502. }
  503. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  504. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  505. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  506. }
  507. return $sResult;
  508. }
  509. }
  510. /**
  511. * Record the modification of a caselog (text)
  512. * since the caselog itself stores the history
  513. * of its entries, there is no need to duplicate
  514. * the text here
  515. *
  516. * @package iTopORM
  517. */
  518. class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute
  519. {
  520. public static function Init()
  521. {
  522. $aParams = array
  523. (
  524. "category" => "core/cmdb",
  525. "key_type" => "",
  526. "name_attcode" => "change",
  527. "state_attcode" => "",
  528. "reconc_keys" => array(),
  529. "db_table" => "priv_changeop_setatt_log",
  530. "db_key_field" => "id",
  531. "db_finalclass_field" => "",
  532. );
  533. MetaModel::Init_Params($aParams);
  534. MetaModel::Init_InheritAttributes();
  535. MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  536. // Display lists
  537. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  538. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  539. }
  540. /**
  541. * Describe (as a text string) the modifications corresponding to this change
  542. */
  543. public function GetDescription()
  544. {
  545. // Temporary, until we change the options of GetDescription() -needs a more global revision
  546. $bIsHtml = true;
  547. $sResult = '';
  548. $oTargetObjectClass = $this->Get('objclass');
  549. $oTargetObjectKey = $this->Get('objkey');
  550. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  551. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  552. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  553. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  554. {
  555. if (MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode')))
  556. {
  557. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  558. $sAttName = $oAttDef->GetLabel();
  559. }
  560. else
  561. {
  562. // The attribute was renamed or removed from the object ?
  563. $sAttName = $this->Get('attcode');
  564. }
  565. $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName);
  566. }
  567. return $sResult;
  568. }
  569. }
  570. /**
  571. * Record an action made by a plug-in
  572. *
  573. * @package iTopORM
  574. */
  575. class CMDBChangeOpPlugin extends CMDBChangeOp
  576. {
  577. public static function Init()
  578. {
  579. $aParams = array
  580. (
  581. "category" => "core/cmdb",
  582. "key_type" => "",
  583. "name_attcode" => "change",
  584. "state_attcode" => "",
  585. "reconc_keys" => array(),
  586. "db_table" => "priv_changeop_plugin",
  587. "db_key_field" => "id",
  588. "db_finalclass_field" => "",
  589. );
  590. MetaModel::Init_Params($aParams);
  591. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  592. /* 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
  593. MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  594. MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  595. */
  596. MetaModel::Init_InheritAttributes();
  597. }
  598. /**
  599. * Describe (as a text string) the modifications corresponding to this change
  600. */
  601. public function GetDescription()
  602. {
  603. return $this->Get('description');
  604. }
  605. }
  606. /**
  607. * Record added/removed objects from within a link set
  608. *
  609. * @package iTopORM
  610. */
  611. abstract class CMDBChangeOpSetAttributeLinks extends CMDBChangeOpSetAttribute
  612. {
  613. public static function Init()
  614. {
  615. $aParams = array
  616. (
  617. "category" => "core/cmdb",
  618. "key_type" => "",
  619. "name_attcode" => "change",
  620. "state_attcode" => "",
  621. "reconc_keys" => array(),
  622. "db_table" => "priv_changeop_links",
  623. "db_key_field" => "id",
  624. "db_finalclass_field" => "",
  625. );
  626. MetaModel::Init_Params($aParams);
  627. MetaModel::Init_InheritAttributes();
  628. // Note: item class/id points to the link class itself in case of a direct link set (e.g. Server::interface_list => Interface)
  629. // item class/id points to the remote class in case of a indirect link set (e.g. Server::contract_list => Contract)
  630. MetaModel::Init_AddAttribute(new AttributeString("item_class", array("allowed_values"=>null, "sql"=>"item_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  631. MetaModel::Init_AddAttribute(new AttributeInteger("item_id", array("allowed_values"=>null, "sql"=>"item_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  632. }
  633. }
  634. /**
  635. * Record added/removed objects from within a link set
  636. *
  637. * @package iTopORM
  638. */
  639. class CMDBChangeOpSetAttributeLinksAddRemove extends CMDBChangeOpSetAttributeLinks
  640. {
  641. public static function Init()
  642. {
  643. $aParams = array
  644. (
  645. "category" => "core/cmdb",
  646. "key_type" => "",
  647. "name_attcode" => "change",
  648. "state_attcode" => "",
  649. "reconc_keys" => array(),
  650. "db_table" => "priv_changeop_links_addremove",
  651. "db_key_field" => "id",
  652. "db_finalclass_field" => "",
  653. );
  654. MetaModel::Init_Params($aParams);
  655. MetaModel::Init_InheritAttributes();
  656. 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())));
  657. }
  658. /**
  659. * Describe (as a text string) the modifications corresponding to this change
  660. */
  661. public function GetDescription()
  662. {
  663. $sResult = '';
  664. $oTargetObjectClass = $this->Get('objclass');
  665. $oTargetObjectKey = $this->Get('objkey');
  666. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  667. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  668. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  669. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  670. {
  671. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  672. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  673. $sAttName = $oAttDef->GetLabel();
  674. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  675. $sResult = $sAttName.' - ';
  676. switch ($this->Get('type'))
  677. {
  678. case 'added':
  679. $sResult .= Dict::Format('Change:LinkSet:Added', $sItemDesc);
  680. break;
  681. case 'removed':
  682. $sResult .= Dict::Format('Change:LinkSet:Removed', $sItemDesc);
  683. break;
  684. }
  685. }
  686. return $sResult;
  687. }
  688. }
  689. /**
  690. * Record attribute changes from within a link set
  691. * A single record redirects to the modifications made within the same change
  692. *
  693. * @package iTopORM
  694. */
  695. class CMDBChangeOpSetAttributeLinksTune extends CMDBChangeOpSetAttributeLinks
  696. {
  697. public static function Init()
  698. {
  699. $aParams = array
  700. (
  701. "category" => "core/cmdb",
  702. "key_type" => "",
  703. "name_attcode" => "change",
  704. "state_attcode" => "",
  705. "reconc_keys" => array(),
  706. "db_table" => "priv_changeop_links_tune",
  707. "db_key_field" => "id",
  708. "db_finalclass_field" => "",
  709. );
  710. MetaModel::Init_Params($aParams);
  711. MetaModel::Init_InheritAttributes();
  712. MetaModel::Init_AddAttribute(new AttributeInteger("link_id", array("allowed_values"=>null, "sql"=>"link_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  713. }
  714. /**
  715. * Describe (as a text string) the modifications corresponding to this change
  716. */
  717. public function GetDescription()
  718. {
  719. $sResult = '';
  720. $oTargetObjectClass = $this->Get('objclass');
  721. $oTargetObjectKey = $this->Get('objkey');
  722. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  723. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  724. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  725. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  726. {
  727. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renamed attributes...
  728. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  729. $sAttName = $oAttDef->GetLabel();
  730. $sLinkClass = $oAttDef->GetLinkedClass();
  731. $aLinkClasses = MetaModel::EnumChildClasses($sLinkClass, ENUM_CHILD_CLASSES_ALL);
  732. // Search for changes on the corresponding link
  733. //
  734. $oSearch = new DBObjectSearch('CMDBChangeOpSetAttribute');
  735. $oSearch->AddCondition('change', $this->Get('change'), '=');
  736. $oSearch->AddCondition('objkey', $this->Get('link_id'), '=');
  737. if (count($aLinkClasses) == 1)
  738. {
  739. // Faster than the whole building of the expression below for just one value ??
  740. $oSearch->AddCondition('objclass', $sLinkClass, '=');
  741. }
  742. else
  743. {
  744. $oField = new FieldExpression('objclass', $oSearch->GetClassAlias());
  745. $sListExpr = '('.implode(', ', CMDBSource::Quote($aLinkClasses)).')';
  746. $sOQLCondition = $oField->Render()." IN $sListExpr";
  747. $oNewCondition = Expression::FromOQL($sOQLCondition);
  748. $oSearch->AddConditionExpression($oNewCondition);
  749. }
  750. $oSet = new DBObjectSet($oSearch);
  751. $aChanges = array();
  752. while ($oChangeOp = $oSet->Fetch())
  753. {
  754. $aChanges[] = $oChangeOp->GetDescription();
  755. }
  756. if (count($aChanges) == 0)
  757. {
  758. return '';
  759. }
  760. $sItemDesc = MetaModel::GetHyperLink($this->Get('item_class'), $this->Get('item_id'));
  761. $sResult = $sAttName.' - ';
  762. $sResult .= Dict::Format('Change:LinkSet:Modified', $sItemDesc);
  763. $sResult .= ' : '.implode(', ', $aChanges);
  764. }
  765. return $sResult;
  766. }
  767. }
  768. ?>