trigger.class.inc.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 class Trigger and derived
  20. * User defined triggers, that may be used in conjunction with user defined actions
  21. *
  22. * @copyright Copyright (C) 2010-2012 Combodo SARL
  23. * @license http://opensource.org/licenses/AGPL-3.0
  24. */
  25. /**
  26. * A user defined trigger, to customize the application
  27. * A trigger will activate an action
  28. *
  29. * @package iTopORM
  30. */
  31. abstract class Trigger extends cmdbAbstractObject
  32. {
  33. public static function Init()
  34. {
  35. $aParams = array
  36. (
  37. "category" => "core/cmdb",
  38. "key_type" => "autoincrement",
  39. "name_attcode" => "description",
  40. "state_attcode" => "",
  41. "reconc_keys" => array('description'),
  42. "db_table" => "priv_trigger",
  43. "db_key_field" => "id",
  44. "db_finalclass_field" => "realclass",
  45. "display_template" => "",
  46. );
  47. MetaModel::Init_Params($aParams);
  48. //MetaModel::Init_InheritAttributes();
  49. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  50. MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("action_list", array("linked_class"=>"lnkTriggerAction", "ext_key_to_me"=>"trigger_id", "ext_key_to_remote"=>"action_id", "allowed_values"=>null, "count_min"=>1, "count_max"=>0, "depends_on"=>array())));
  51. // Display lists
  52. MetaModel::Init_SetZListItems('details', array('finalclass', 'description', 'action_list')); // Attributes to be displayed for the complete details
  53. MetaModel::Init_SetZListItems('list', array('finalclass')); // Attributes to be displayed for a list
  54. // Search criteria
  55. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  56. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  57. }
  58. public function DoActivate($aContextArgs)
  59. {
  60. // Find the related
  61. $oLinkedActions = $this->Get('action_list');
  62. while ($oLink = $oLinkedActions->Fetch())
  63. {
  64. $iActionId = $oLink->Get('action_id');
  65. $oAction = MetaModel::GetObject('Action', $iActionId);
  66. if ($oAction->IsActive())
  67. {
  68. $oAction->DoExecute($this, $aContextArgs);
  69. }
  70. }
  71. }
  72. }
  73. abstract class TriggerOnObject extends Trigger
  74. {
  75. public static function Init()
  76. {
  77. $aParams = array
  78. (
  79. "category" => "core/cmdb",
  80. "key_type" => "autoincrement",
  81. "name_attcode" => "description",
  82. "state_attcode" => "",
  83. "reconc_keys" => array('description'),
  84. "db_table" => "priv_trigger_onobject",
  85. "db_key_field" => "id",
  86. "db_finalclass_field" => "",
  87. "display_template" => "",
  88. );
  89. MetaModel::Init_Params($aParams);
  90. MetaModel::Init_InheritAttributes();
  91. MetaModel::Init_AddAttribute(new AttributeClass("target_class", array("class_category"=>"bizmodel", "more_values"=>null, "sql"=>"target_class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  92. // Display lists
  93. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'action_list')); // Attributes to be displayed for the complete details
  94. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
  95. // Search criteria
  96. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  97. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  98. }
  99. }
  100. /**
  101. * To trigger notifications when a ticket is updated from the portal
  102. */
  103. class TriggerOnPortalUpdate extends TriggerOnObject
  104. {
  105. public static function Init()
  106. {
  107. $aParams = array
  108. (
  109. "category" => "core/cmdb,bizmodel",
  110. "key_type" => "autoincrement",
  111. "name_attcode" => "description",
  112. "state_attcode" => "",
  113. "reconc_keys" => array('description'),
  114. "db_table" => "priv_trigger_onportalupdate",
  115. "db_key_field" => "id",
  116. "db_finalclass_field" => "",
  117. "display_template" => "",
  118. );
  119. MetaModel::Init_Params($aParams);
  120. MetaModel::Init_InheritAttributes();
  121. // Display lists
  122. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'action_list')); // Attributes to be displayed for the complete details
  123. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
  124. // Search criteria
  125. }
  126. }
  127. abstract class TriggerOnStateChange extends TriggerOnObject
  128. {
  129. public static function Init()
  130. {
  131. $aParams = array
  132. (
  133. "category" => "core/cmdb",
  134. "key_type" => "autoincrement",
  135. "name_attcode" => "description",
  136. "state_attcode" => "",
  137. "reconc_keys" => array('description'),
  138. "db_table" => "priv_trigger_onstatechange",
  139. "db_key_field" => "id",
  140. "db_finalclass_field" => "",
  141. "display_template" => "",
  142. );
  143. MetaModel::Init_Params($aParams);
  144. MetaModel::Init_InheritAttributes();
  145. MetaModel::Init_AddAttribute(new AttributeString("state", array("allowed_values"=>null, "sql"=>"state", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  146. // Display lists
  147. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state', 'action_list')); // Attributes to be displayed for the complete details
  148. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'state')); // Attributes to be displayed for a list
  149. // Search criteria
  150. MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form
  151. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  152. }
  153. }
  154. class TriggerOnStateEnter extends TriggerOnStateChange
  155. {
  156. public static function Init()
  157. {
  158. $aParams = array
  159. (
  160. "category" => "core/cmdb,bizmodel",
  161. "key_type" => "autoincrement",
  162. "name_attcode" => "description",
  163. "state_attcode" => "",
  164. "reconc_keys" => array('description'),
  165. "db_table" => "priv_trigger_onstateenter",
  166. "db_key_field" => "id",
  167. "db_finalclass_field" => "",
  168. "display_template" => "",
  169. );
  170. MetaModel::Init_Params($aParams);
  171. MetaModel::Init_InheritAttributes();
  172. // Display lists
  173. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state', 'action_list')); // Attributes to be displayed for the complete details
  174. MetaModel::Init_SetZListItems('list', array('target_class', 'state')); // Attributes to be displayed for a list
  175. // Search criteria
  176. MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form
  177. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  178. }
  179. }
  180. class TriggerOnStateLeave extends TriggerOnStateChange
  181. {
  182. public static function Init()
  183. {
  184. $aParams = array
  185. (
  186. "category" => "core/cmdb,bizmodel",
  187. "key_type" => "autoincrement",
  188. "name_attcode" => "description",
  189. "state_attcode" => "",
  190. "reconc_keys" => array('description'),
  191. "db_table" => "priv_trigger_onstateleave",
  192. "db_key_field" => "id",
  193. "db_finalclass_field" => "",
  194. "display_template" => "",
  195. );
  196. MetaModel::Init_Params($aParams);
  197. MetaModel::Init_InheritAttributes();
  198. // Display lists
  199. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state', 'action_list')); // Attributes to be displayed for the complete details
  200. MetaModel::Init_SetZListItems('list', array('target_class', 'state')); // Attributes to be displayed for a list
  201. // Search criteria
  202. MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form
  203. // MetaModel::Init_SetZListItems('advanced_search', array('')); // Criteria of the advanced search form
  204. }
  205. }
  206. class TriggerOnObjectCreate extends TriggerOnObject
  207. {
  208. public static function Init()
  209. {
  210. $aParams = array
  211. (
  212. "category" => "core/cmdb,bizmodel",
  213. "key_type" => "autoincrement",
  214. "name_attcode" => "description",
  215. "state_attcode" => "",
  216. "reconc_keys" => array('description'),
  217. "db_table" => "priv_trigger_onobjcreate",
  218. "db_key_field" => "id",
  219. "db_finalclass_field" => "",
  220. "display_template" => "",
  221. );
  222. MetaModel::Init_Params($aParams);
  223. MetaModel::Init_InheritAttributes();
  224. // Display lists
  225. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'action_list')); // Attributes to be displayed for the complete details
  226. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class')); // Attributes to be displayed for a list
  227. // Search criteria
  228. MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class')); // Criteria of the std search form
  229. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  230. }
  231. }
  232. class lnkTriggerAction extends cmdbAbstractObject
  233. {
  234. public static function Init()
  235. {
  236. $aParams = array
  237. (
  238. "category" => "core/cmdb,bizmodel",
  239. "key_type" => "autoincrement",
  240. "name_attcode" => "",
  241. "state_attcode" => "",
  242. "reconc_keys" => array('action_id', 'trigger_id'),
  243. "db_table" => "priv_link_action_trigger",
  244. "db_key_field" => "link_id",
  245. "db_finalclass_field" => "",
  246. "display_template" => "",
  247. );
  248. MetaModel::Init_Params($aParams);
  249. MetaModel::Init_AddAttribute(new AttributeExternalKey("action_id", array("targetclass"=>"Action", "jointype"=> '', "allowed_values"=>null, "sql"=>"action_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  250. MetaModel::Init_AddAttribute(new AttributeExternalField("action_name", array("allowed_values"=>null, "extkey_attcode"=> 'action_id', "target_attcode"=>"name")));
  251. MetaModel::Init_AddAttribute(new AttributeExternalKey("trigger_id", array("targetclass"=>"Trigger", "jointype"=> '', "allowed_values"=>null, "sql"=>"trigger_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  252. MetaModel::Init_AddAttribute(new AttributeExternalField("trigger_name", array("allowed_values"=>null, "extkey_attcode"=> 'trigger_id', "target_attcode"=>"description")));
  253. MetaModel::Init_AddAttribute(new AttributeInteger("order", array("allowed_values"=>null, "sql"=>"order", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  254. // Display lists
  255. MetaModel::Init_SetZListItems('details', array('action_id', 'trigger_id', 'order')); // Attributes to be displayed for a list
  256. MetaModel::Init_SetZListItems('list', array('action_id', 'trigger_id', 'order')); // Attributes to be displayed for a list
  257. // Search criteria
  258. MetaModel::Init_SetZListItems('standard_search', array('action_id', 'trigger_id', 'order')); // Criteria of the std search form
  259. MetaModel::Init_SetZListItems('advanced_search', array('action_id', 'trigger_id', 'order')); // Criteria of the advanced search form
  260. }
  261. }
  262. class TriggerOnThresholdReached extends TriggerOnObject
  263. {
  264. public static function Init()
  265. {
  266. $aParams = array
  267. (
  268. "category" => "core/cmdb,bizmodel",
  269. "key_type" => "autoincrement",
  270. "name_attcode" => "description",
  271. "state_attcode" => "",
  272. "reconc_keys" => array('description'),
  273. "db_table" => "priv_trigger_threshold",
  274. "db_key_field" => "id",
  275. "db_finalclass_field" => "",
  276. "display_template" => "",
  277. );
  278. MetaModel::Init_Params($aParams);
  279. MetaModel::Init_InheritAttributes();
  280. MetaModel::Init_AddAttribute(new AttributeString("stop_watch_code", array("allowed_values"=>null, "sql"=>"stop_watch_code", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  281. MetaModel::Init_AddAttribute(new AttributeString("threshold_index", array("allowed_values"=>null, "sql"=>"threshold_index", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  282. // Display lists
  283. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'stop_watch_code', 'threshold_index', 'action_list')); // Attributes to be displayed for the complete details
  284. MetaModel::Init_SetZListItems('list', array('target_class', 'threshold_index', 'threshold_index')); // Attributes to be displayed for a list
  285. // Search criteria
  286. MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class')); // Criteria of the std search form
  287. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  288. }
  289. }
  290. ?>