cmdbchangeop.class.inc.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Persistent classes (internal) : cmdbChangeOp and derived
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. /**
  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. /**
  63. * Record the creation of an object
  64. *
  65. * @package iTopORM
  66. */
  67. class CMDBChangeOpCreate extends CMDBChangeOp
  68. {
  69. public static function Init()
  70. {
  71. $aParams = array
  72. (
  73. "category" => "core/cmdb",
  74. "key_type" => "",
  75. "name_attcode" => "change",
  76. "state_attcode" => "",
  77. "reconc_keys" => array(),
  78. "db_table" => "priv_changeop_create",
  79. "db_key_field" => "id",
  80. "db_finalclass_field" => "",
  81. );
  82. MetaModel::Init_Params($aParams);
  83. MetaModel::Init_InheritAttributes();
  84. }
  85. /**
  86. * Describe (as a text string) the modifications corresponding to this change
  87. */
  88. public function GetDescription()
  89. {
  90. return Dict::S('Change:ObjectCreated');
  91. }
  92. }
  93. /**
  94. * Record the deletion of an object
  95. *
  96. * @package iTopORM
  97. */
  98. class CMDBChangeOpDelete extends CMDBChangeOp
  99. {
  100. public static function Init()
  101. {
  102. $aParams = array
  103. (
  104. "category" => "core/cmdb",
  105. "key_type" => "",
  106. "name_attcode" => "change",
  107. "state_attcode" => "",
  108. "reconc_keys" => array(),
  109. "db_table" => "priv_changeop_delete",
  110. "db_key_field" => "id",
  111. "db_finalclass_field" => "",
  112. );
  113. MetaModel::Init_Params($aParams);
  114. MetaModel::Init_InheritAttributes();
  115. }
  116. /**
  117. * Describe (as a text string) the modifications corresponding to this change
  118. */
  119. public function GetDescription()
  120. {
  121. return Dict::S('Change:ObjectDeleted');
  122. }
  123. }
  124. /**
  125. * Record the modification of an attribute (abstract)
  126. *
  127. * @package iTopORM
  128. */
  129. class CMDBChangeOpSetAttribute extends CMDBChangeOp
  130. {
  131. public static function Init()
  132. {
  133. $aParams = array
  134. (
  135. "category" => "core/cmdb",
  136. "key_type" => "",
  137. "name_attcode" => "change",
  138. "state_attcode" => "",
  139. "reconc_keys" => array(),
  140. "db_table" => "priv_changeop_setatt",
  141. "db_key_field" => "id",
  142. "db_finalclass_field" => "",
  143. );
  144. MetaModel::Init_Params($aParams);
  145. MetaModel::Init_InheritAttributes();
  146. MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  147. // Display lists
  148. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  149. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  150. }
  151. }
  152. /**
  153. * Record the modification of a scalar attribute
  154. *
  155. * @package iTopORM
  156. */
  157. class CMDBChangeOpSetAttributeScalar extends CMDBChangeOpSetAttribute
  158. {
  159. public static function Init()
  160. {
  161. $aParams = array
  162. (
  163. "category" => "core/cmdb",
  164. "key_type" => "",
  165. "name_attcode" => "change",
  166. "state_attcode" => "",
  167. "reconc_keys" => array(),
  168. "db_table" => "priv_changeop_setatt_scalar",
  169. "db_key_field" => "id",
  170. "db_finalclass_field" => "",
  171. );
  172. MetaModel::Init_Params($aParams);
  173. MetaModel::Init_InheritAttributes();
  174. MetaModel::Init_AddAttribute(new AttributeString("oldvalue", array("allowed_values"=>null, "sql"=>"oldvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  175. MetaModel::Init_AddAttribute(new AttributeString("newvalue", array("allowed_values"=>null, "sql"=>"newvalue", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  176. // Display lists
  177. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for the complete details
  178. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode', 'oldvalue', 'newvalue')); // Attributes to be displayed for a list
  179. }
  180. /**
  181. * Describe (as a text string) the modifications corresponding to this change
  182. */
  183. public function GetDescription()
  184. {
  185. // Temporary, until we change the options of GetDescription() -needs a more global revision
  186. $bIsHtml = true;
  187. $sResult = '';
  188. $oTargetObjectClass = $this->Get('objclass');
  189. $oTargetObjectKey = $this->Get('objkey');
  190. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  191. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  192. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  193. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  194. {
  195. if (!MetaModel::IsValidAttCode($this->Get('objclass'), $this->Get('attcode'))) return ''; // Protects against renammed attributes...
  196. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  197. $sAttName = $oAttDef->GetLabel();
  198. $sNewValue = $this->Get('newvalue');
  199. $sOldValue = $this->Get('oldvalue');
  200. if ( (($oAttDef->GetType() == 'String') || ($oAttDef->GetType() == 'Text')) &&
  201. (strlen($sNewValue) > strlen($sOldValue)) )
  202. {
  203. // Check if some text was not appended to the field
  204. if (substr($sNewValue,0, strlen($sOldValue)) == $sOldValue) // Text added at the end
  205. {
  206. $sDelta = substr($sNewValue, strlen($sOldValue));
  207. $sResult = Dict::Format('Change:Text_AppendedTo_AttName', $sDelta, $sAttName);
  208. }
  209. else if (substr($sNewValue, -strlen($sOldValue)) == $sOldValue) // Text added at the beginning
  210. {
  211. $sDelta = substr($sNewValue, 0, strlen($sNewValue) - strlen($sOldValue));
  212. $sResult = Dict::Format('Change:Text_AppendedTo_AttName', $sDelta, $sAttName);
  213. }
  214. else
  215. {
  216. if (strlen($sOldValue) == 0)
  217. {
  218. $sResult = Dict::Format('Change:AttName_SetTo', $sAttName, $sNewValue);
  219. }
  220. else
  221. {
  222. $sResult = Dict::Format('Change:AttName_SetTo_NewValue_PreviousValue_OldValue', $sAttName, $sNewValue, $sOldValue);
  223. }
  224. }
  225. }
  226. elseif($bIsHtml && $oAttDef->IsExternalKey())
  227. {
  228. $sTargetClass = $oAttDef->GetTargetClass();
  229. $sFrom = MetaModel::GetHyperLink($sTargetClass, $sOldValue);
  230. $sTo = MetaModel::GetHyperLink($sTargetClass, $sNewValue);
  231. $sResult = "$sAttName set to $sTo (previous: $sFrom)";
  232. if (strlen($sFrom) == 0)
  233. {
  234. $sResult = Dict::Format('Change:AttName_SetTo', $sAttName, $sTo);
  235. }
  236. else
  237. {
  238. $sResult = Dict::Format('Change:AttName_SetTo_NewValue_PreviousValue_OldValue', $sAttName, $sTo, $sFrom);
  239. }
  240. }
  241. elseif ($oAttDef instanceOf AttributeBlob)
  242. {
  243. $sResult = "#@# Issue... found an attribute for which other type of tracking should be made";
  244. }
  245. else
  246. {
  247. if (strlen($sOldValue) == 0)
  248. {
  249. $sResult = Dict::Format('Change:AttName_SetTo', $sAttName, $sNewValue);
  250. }
  251. else
  252. {
  253. $sResult = Dict::Format('Change:AttName_SetTo_NewValue_PreviousValue_OldValue', $sAttName, $sNewValue, $sOldValue);
  254. }
  255. }
  256. }
  257. return $sResult;
  258. }
  259. }
  260. /**
  261. * Record the modification of a blob
  262. *
  263. * @package iTopORM
  264. */
  265. class CMDBChangeOpSetAttributeBlob extends CMDBChangeOpSetAttribute
  266. {
  267. public static function Init()
  268. {
  269. $aParams = array
  270. (
  271. "category" => "core/cmdb",
  272. "key_type" => "",
  273. "name_attcode" => "change",
  274. "state_attcode" => "",
  275. "reconc_keys" => array(),
  276. "db_table" => "priv_changeop_setatt_data",
  277. "db_key_field" => "id",
  278. "db_finalclass_field" => "",
  279. );
  280. MetaModel::Init_Params($aParams);
  281. MetaModel::Init_InheritAttributes();
  282. MetaModel::Init_AddAttribute(new AttributeBlob("prevdata", array("depends_on"=>array())));
  283. // Display lists
  284. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  285. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  286. }
  287. /**
  288. * Describe (as a text string) the modifications corresponding to this change
  289. */
  290. public function GetDescription()
  291. {
  292. // Temporary, until we change the options of GetDescription() -needs a more global revision
  293. $bIsHtml = true;
  294. $sResult = '';
  295. $oTargetObjectClass = $this->Get('objclass');
  296. $oTargetObjectKey = $this->Get('objkey');
  297. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  298. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  299. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  300. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  301. {
  302. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  303. $sAttName = $oAttDef->GetLabel();
  304. $oPrevDoc = $this->Get('prevdata');
  305. $sDocView = $oPrevDoc->GetAsHtml();
  306. $sDocView .= "<br/>".Dict::Format('UI:OpenDocumentInNewWindow_',$oPrevDoc->GetDisplayLink(get_class($this), $this->GetKey(), 'prevdata')).", \n";
  307. $sDocView .= Dict::Format('UI:DownloadDocument_', $oPrevDoc->GetDownloadLink(get_class($this), $this->GetKey(), 'prevdata'))."\n";
  308. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  309. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sDocView);
  310. }
  311. return $sResult;
  312. }
  313. }
  314. /**
  315. * Safely record the modification of one way encrypted password
  316. */
  317. class CMDBChangeOpSetAttributeOneWayPassword extends CMDBChangeOpSetAttribute
  318. {
  319. public static function Init()
  320. {
  321. $aParams = array
  322. (
  323. "category" => "core/cmdb",
  324. "key_type" => "",
  325. "name_attcode" => "change",
  326. "state_attcode" => "",
  327. "reconc_keys" => array(),
  328. "db_table" => "priv_changeop_setatt_pwd",
  329. "db_key_field" => "id",
  330. "db_finalclass_field" => "",
  331. );
  332. MetaModel::Init_Params($aParams);
  333. MetaModel::Init_InheritAttributes();
  334. MetaModel::Init_AddAttribute(new AttributeOneWayPassword("prev_pwd", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  335. // Display lists
  336. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  337. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  338. }
  339. /**
  340. * Describe (as a text string) the modifications corresponding to this change
  341. */
  342. public function GetDescription()
  343. {
  344. // Temporary, until we change the options of GetDescription() -needs a more global revision
  345. $bIsHtml = true;
  346. $sResult = '';
  347. $oTargetObjectClass = $this->Get('objclass');
  348. $oTargetObjectKey = $this->Get('objkey');
  349. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  350. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  351. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  352. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  353. {
  354. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  355. $sAttName = $oAttDef->GetLabel();
  356. $sResult = Dict::Format('Change:AttName_Changed', $sAttName);
  357. }
  358. return $sResult;
  359. }
  360. }
  361. /**
  362. * Safely record the modification of an encrypted field
  363. */
  364. class CMDBChangeOpSetAttributeEncrypted extends CMDBChangeOpSetAttribute
  365. {
  366. public static function Init()
  367. {
  368. $aParams = array
  369. (
  370. "category" => "core/cmdb",
  371. "key_type" => "",
  372. "name_attcode" => "change",
  373. "state_attcode" => "",
  374. "reconc_keys" => array(),
  375. "db_table" => "priv_changeop_setatt_encrypted",
  376. "db_key_field" => "id",
  377. "db_finalclass_field" => "",
  378. );
  379. MetaModel::Init_Params($aParams);
  380. MetaModel::Init_InheritAttributes();
  381. MetaModel::Init_AddAttribute(new AttributeEncryptedString("prevstring", array("sql" => 'data', "default_value" => '', "is_null_allowed"=> true, "allowed_values" => null, "depends_on"=>array())));
  382. // Display lists
  383. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  384. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  385. }
  386. /**
  387. * Describe (as a text string) the modifications corresponding to this change
  388. */
  389. public function GetDescription()
  390. {
  391. // Temporary, until we change the options of GetDescription() -needs a more global revision
  392. $bIsHtml = true;
  393. $sResult = '';
  394. $oTargetObjectClass = $this->Get('objclass');
  395. $oTargetObjectKey = $this->Get('objkey');
  396. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  397. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  398. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  399. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  400. {
  401. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  402. $sAttName = $oAttDef->GetLabel();
  403. $sPrevString = $this->Get('prevstring');
  404. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sPrevString);
  405. }
  406. return $sResult;
  407. }
  408. }
  409. /**
  410. * Record the modification of a multiline string (text)
  411. *
  412. * @package iTopORM
  413. */
  414. class CMDBChangeOpSetAttributeText extends CMDBChangeOpSetAttribute
  415. {
  416. public static function Init()
  417. {
  418. $aParams = array
  419. (
  420. "category" => "core/cmdb",
  421. "key_type" => "",
  422. "name_attcode" => "change",
  423. "state_attcode" => "",
  424. "reconc_keys" => array(),
  425. "db_table" => "priv_changeop_setatt_text",
  426. "db_key_field" => "id",
  427. "db_finalclass_field" => "",
  428. );
  429. MetaModel::Init_Params($aParams);
  430. MetaModel::Init_InheritAttributes();
  431. MetaModel::Init_AddAttribute(new AttributeText("prevdata", array("allowed_values"=>null, "sql"=>"prevdata", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  432. // Display lists
  433. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  434. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  435. }
  436. /**
  437. * Describe (as a text string) the modifications corresponding to this change
  438. */
  439. public function GetDescription()
  440. {
  441. // Temporary, until we change the options of GetDescription() -needs a more global revision
  442. $bIsHtml = true;
  443. $sResult = '';
  444. $oTargetObjectClass = $this->Get('objclass');
  445. $oTargetObjectKey = $this->Get('objkey');
  446. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  447. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  448. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  449. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  450. {
  451. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  452. $sAttName = $oAttDef->GetLabel();
  453. $sTextView = '<div>'.$this->GetAsHtml('prevdata').'</div>';
  454. //$sDocView = $oPrevDoc->GetDisplayInline(get_class($this), $this->GetKey(), 'prevdata');
  455. $sResult = Dict::Format('Change:AttName_Changed_PreviousValue_OldValue', $sAttName, $sTextView);
  456. }
  457. return $sResult;
  458. }
  459. }
  460. /**
  461. * Record the modification of a caselog (text)
  462. * since the caselog itself stores the history
  463. * of its entries, there is no need to duplicate
  464. * the text here
  465. *
  466. * @package iTopORM
  467. */
  468. class CMDBChangeOpSetAttributeCaseLog extends CMDBChangeOpSetAttribute
  469. {
  470. public static function Init()
  471. {
  472. $aParams = array
  473. (
  474. "category" => "core/cmdb",
  475. "key_type" => "",
  476. "name_attcode" => "change",
  477. "state_attcode" => "",
  478. "reconc_keys" => array(),
  479. "db_table" => "priv_changeop_setatt_log",
  480. "db_key_field" => "id",
  481. "db_finalclass_field" => "",
  482. );
  483. MetaModel::Init_Params($aParams);
  484. MetaModel::Init_InheritAttributes();
  485. MetaModel::Init_AddAttribute(new AttributeInteger("lastentry", array("allowed_values"=>null, "sql"=>"lastentry", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  486. // Display lists
  487. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for the complete details
  488. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'attcode')); // Attributes to be displayed for a list
  489. }
  490. /**
  491. * Describe (as a text string) the modifications corresponding to this change
  492. */
  493. public function GetDescription()
  494. {
  495. // Temporary, until we change the options of GetDescription() -needs a more global revision
  496. $bIsHtml = true;
  497. $sResult = '';
  498. $oTargetObjectClass = $this->Get('objclass');
  499. $oTargetObjectKey = $this->Get('objkey');
  500. $oTargetSearch = new DBObjectSearch($oTargetObjectClass);
  501. $oTargetSearch->AddCondition('id', $oTargetObjectKey, '=');
  502. $oMonoObjectSet = new DBObjectSet($oTargetSearch);
  503. if (UserRights::IsActionAllowedOnAttribute($this->Get('objclass'), $this->Get('attcode'), UR_ACTION_READ, $oMonoObjectSet) == UR_ALLOWED_YES)
  504. {
  505. $oAttDef = MetaModel::GetAttributeDef($this->Get('objclass'), $this->Get('attcode'));
  506. $sAttName = $oAttDef->GetLabel();
  507. $sResult = Dict::Format('Change:AttName_EntryAdded', $sAttName);
  508. }
  509. return $sResult;
  510. }
  511. }
  512. /**
  513. * Record an action made by a plug-in
  514. *
  515. * @package iTopORM
  516. */
  517. class CMDBChangeOpPlugin extends CMDBChangeOp
  518. {
  519. public static function Init()
  520. {
  521. $aParams = array
  522. (
  523. "category" => "core/cmdb",
  524. "key_type" => "",
  525. "name_attcode" => "change",
  526. "state_attcode" => "",
  527. "reconc_keys" => array(),
  528. "db_table" => "priv_changeop_plugin",
  529. "db_key_field" => "id",
  530. "db_finalclass_field" => "",
  531. );
  532. MetaModel::Init_Params($aParams);
  533. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  534. /* 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
  535. MetaModel::Init_AddAttribute(new AttributeString("extension_class", array("allowed_values"=>null, "sql"=>"extension_class", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array())));
  536. MetaModel::Init_AddAttribute(new AttributeInteger("extension_id", array("allowed_values"=>null, "sql"=>"extension_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  537. */
  538. MetaModel::Init_InheritAttributes();
  539. }
  540. /**
  541. * Describe (as a text string) the modifications corresponding to this change
  542. */
  543. public function GetDescription()
  544. {
  545. return $this->Get('description');
  546. }
  547. }
  548. ?>