rules.install 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <?php
  2. /**
  3. * @file Rules - Installation file.
  4. */
  5. /**
  6. * Implements hook_install().
  7. */
  8. function rules_install() {
  9. module_load_include('inc', 'rules', 'modules/events');
  10. // Set the modules' weight to 20, see
  11. // http://drupal.org/node/445084#comment-1533280 for the reasoning.
  12. db_query("UPDATE {system} SET weight = 20 WHERE name = 'rules'");
  13. }
  14. /**
  15. * Implements hook_uninstall().
  16. */
  17. function rules_uninstall() {
  18. variable_del('rules_empty_sets');
  19. variable_del('rules_debug');
  20. }
  21. /**
  22. * Implements hook_schema().
  23. */
  24. function rules_schema() {
  25. $schema['rules_config'] = array(
  26. 'fields' => array(
  27. 'id' => array(
  28. 'type' => 'serial',
  29. 'not null' => TRUE,
  30. 'description' => 'The internal identifier for any configuration.',
  31. ),
  32. 'name' => array(
  33. 'type' => 'varchar',
  34. 'length' => '64',
  35. 'not null' => TRUE,
  36. 'description' => 'The name of the configuration.',
  37. ),
  38. 'label' => array(
  39. 'type' => 'varchar',
  40. 'length' => '255',
  41. 'not null' => TRUE,
  42. 'description' => 'The label of the configuration.',
  43. 'default' => 'unlabeled',
  44. ),
  45. 'plugin' => array(
  46. 'type' => 'varchar',
  47. 'length' => 127,
  48. 'not null' => TRUE,
  49. 'description' => 'The name of the plugin of this configuration.',
  50. ),
  51. 'active' => array(
  52. 'description' => 'Boolean indicating whether the configuration is active. Usage depends on how the using module makes use of it.',
  53. 'type' => 'int',
  54. 'not null' => TRUE,
  55. 'default' => 1,
  56. ),
  57. 'weight' => array(
  58. 'type' => 'int',
  59. 'not null' => TRUE,
  60. 'default' => 0,
  61. 'size' => 'tiny',
  62. 'description' => 'Weight of the configuration. Usage depends on how the using module makes use of it.',
  63. ),
  64. 'status' => array(
  65. 'type' => 'int',
  66. 'not null' => TRUE,
  67. // Set the default to ENTITY_CUSTOM without using the constant as it is
  68. // not safe to use it at this point.
  69. 'default' => 0x01,
  70. 'size' => 'tiny',
  71. 'description' => 'The exportable status of the entity.',
  72. ),
  73. 'dirty' => array(
  74. 'type' => 'int',
  75. 'not null' => TRUE,
  76. 'default' => 0,
  77. 'size' => 'tiny',
  78. 'description' => 'Dirty configurations fail the integrity check, e.g. due to missing dependencies.',
  79. ),
  80. 'module' => array(
  81. 'description' => 'The name of the providing module if the entity has been defined in code.',
  82. 'type' => 'varchar',
  83. 'length' => 255,
  84. 'not null' => FALSE,
  85. ),
  86. 'access_exposed' => array(
  87. 'type' => 'int',
  88. 'not null' => TRUE,
  89. 'default' => 0,
  90. 'size' => 'tiny',
  91. 'description' => 'Whether to use a permission to control access for using components.',
  92. ),
  93. 'data' => array(
  94. 'type' => 'blob',
  95. 'size' => 'big',
  96. 'not null' => FALSE,
  97. 'serialize' => TRUE,
  98. 'description' => 'Everything else, serialized.',
  99. ),
  100. ),
  101. 'primary key' => array('id'),
  102. 'unique keys' => array(
  103. 'name' => array('name'),
  104. ),
  105. 'indexes' => array(
  106. 'plugin' => array('plugin'),
  107. ),
  108. );
  109. $schema['rules_trigger'] = array(
  110. 'fields' => array(
  111. 'id' => array(
  112. 'type' => 'int',
  113. 'unsigned' => TRUE,
  114. 'not null' => TRUE,
  115. 'description' => 'The primary identifier of the configuration.',
  116. ),
  117. 'event' => array(
  118. 'type' => 'varchar',
  119. 'length' => '127',
  120. 'not null' => TRUE,
  121. 'default' => '',
  122. 'description' => 'The name of the event on which the configuration should be triggered.',
  123. ),
  124. ),
  125. 'primary key' => array('id', 'event'),
  126. 'foreign keys' => array(
  127. 'id' => array('rules_config' => 'id'),
  128. ),
  129. );
  130. $schema['rules_tags'] = array(
  131. 'fields' => array(
  132. 'id' => array(
  133. 'type' => 'int',
  134. 'unsigned' => TRUE,
  135. 'not null' => TRUE,
  136. 'description' => 'The primary identifier of the configuration.',
  137. ),
  138. 'tag' => array(
  139. 'type' => 'varchar',
  140. 'length' => '255',
  141. 'not null' => TRUE,
  142. 'description' => 'The tag string associated with this configuration',
  143. ),
  144. ),
  145. 'primary key' => array('id', 'tag'),
  146. 'foreign keys' => array(
  147. 'id' => array('rules_config' => 'id'),
  148. ),
  149. );
  150. $schema['rules_dependencies'] = array(
  151. 'fields' => array(
  152. 'id' => array(
  153. 'type' => 'int',
  154. 'unsigned' => TRUE,
  155. 'not null' => TRUE,
  156. 'description' => 'The primary identifier of the configuration.',
  157. ),
  158. 'module' => array(
  159. 'type' => 'varchar',
  160. 'length' => '255',
  161. 'not null' => TRUE,
  162. 'description' => 'The name of the module that is required for the configuration.',
  163. ),
  164. ),
  165. 'primary key' => array('id', 'module'),
  166. 'indexes' => array(
  167. 'module' => array('module'),
  168. ),
  169. 'foreign keys' => array(
  170. 'id' => array('rules_config' => 'id'),
  171. ),
  172. );
  173. $schema['cache_rules'] = drupal_get_schema_unprocessed('system', 'cache');
  174. $schema['cache_rules']['description'] = 'Cache table for the rules engine to store configured items.';
  175. return $schema;
  176. }
  177. /**
  178. * Upgrade from Rules 6.x-1.x to 7.x.
  179. */
  180. function rules_update_7200() {
  181. // Create the new db tables first.
  182. $schema['rules_config'] = array(
  183. 'fields' => array(
  184. 'id' => array(
  185. 'type' => 'serial',
  186. 'not null' => TRUE,
  187. 'description' => 'The internal identifier for any configuration.',
  188. ),
  189. 'name' => array(
  190. 'type' => 'varchar',
  191. 'length' => '255',
  192. 'not null' => TRUE,
  193. 'description' => 'The name of the configuration.',
  194. ),
  195. 'label' => array(
  196. 'type' => 'varchar',
  197. 'length' => '255',
  198. 'not null' => TRUE,
  199. 'description' => 'The label of the configuration.',
  200. 'default' => 'unlabeled',
  201. ),
  202. 'plugin' => array(
  203. 'type' => 'varchar',
  204. 'length' => 127,
  205. 'not null' => TRUE,
  206. 'description' => 'The name of the plugin of this configuration.',
  207. ),
  208. 'active' => array(
  209. 'description' => 'Boolean indicating whether the configuration is active. Usage depends on how the using module makes use of it.',
  210. 'type' => 'int',
  211. 'not null' => TRUE,
  212. 'default' => 1,
  213. ),
  214. 'weight' => array(
  215. 'type' => 'int',
  216. 'not null' => TRUE,
  217. 'default' => 0,
  218. 'size' => 'tiny',
  219. 'description' => 'Weight of the configuration. Usage depends on how the using module makes use of it.',
  220. ),
  221. 'status' => array(
  222. 'type' => 'int',
  223. 'not null' => TRUE,
  224. // Set the default to ENTITY_CUSTOM without using the constant as it is
  225. // not safe to use it at this point.
  226. 'default' => 0x01,
  227. 'size' => 'tiny',
  228. 'description' => 'The exportable status of the entity.',
  229. ),
  230. 'module' => array(
  231. 'description' => 'The name of the providing module if the entity has been defined in code.',
  232. 'type' => 'varchar',
  233. 'length' => 255,
  234. 'not null' => FALSE,
  235. ),
  236. 'data' => array(
  237. 'type' => 'blob',
  238. 'size' => 'big',
  239. 'not null' => FALSE,
  240. 'serialize' => TRUE,
  241. 'description' => 'Everything else, serialized.',
  242. ),
  243. ),
  244. 'primary key' => array('id'),
  245. 'unique keys' => array(
  246. 'name' => array('name'),
  247. ),
  248. );
  249. $schema['rules_trigger'] = array(
  250. 'fields' => array(
  251. 'id' => array(
  252. 'type' => 'int',
  253. 'unsigned' => TRUE,
  254. 'not null' => TRUE,
  255. 'description' => 'The primary identifier of the configuration.',
  256. ),
  257. 'event' => array(
  258. 'type' => 'varchar',
  259. 'length' => '127',
  260. 'not null' => TRUE,
  261. 'default' => '',
  262. 'description' => 'The name of the event on which the configuration should be triggered.',
  263. ),
  264. ),
  265. 'primary key' => array('id', 'event'),
  266. 'foreign keys' => array(
  267. 'id' => array('rules_config' => 'id'),
  268. ),
  269. );
  270. db_create_table('rules_config', $schema['rules_config']);
  271. db_create_table('rules_trigger', $schema['rules_trigger']);
  272. // The cache table already exists, but changed. So re-create it.
  273. db_drop_table('cache_rules');
  274. $schema['cache_rules'] = drupal_get_schema_unprocessed('system', 'cache');
  275. $schema['cache_rules']['description'] = 'Cache table for the rules engine to store configured items.';
  276. db_create_table('cache_rules', $schema['cache_rules']);
  277. // Remove deprecated variables.
  278. variable_del('rules_inactive_sets');
  279. variable_del('rules_show_fixed');
  280. variable_del('rules_hide_token_message');
  281. variable_del('rules_counter');
  282. return t('The database tables for Rules 2.x have been created. The old tables from Rules 1.x are still available and contain your rules, which are not updated yet.');
  283. }
  284. /**
  285. * Add in the exportable entity db columns as required by the entity API.
  286. */
  287. function rules_update_7201() {
  288. // Previously this was update 7200, so check whether we need to run it really.
  289. // The update has been moved as 7200 needs to be the 6.x-7.x upgrade.
  290. if (!db_field_exists('rules_config', 'status')) {
  291. db_add_field('rules_config', 'status', array(
  292. 'type' => 'int',
  293. 'not null' => TRUE,
  294. 'default' => ENTITY_CUSTOM,
  295. 'size' => 'tiny',
  296. 'description' => 'The exportable status of the entity.',
  297. ));
  298. // The module column did already exist before.
  299. }
  300. }
  301. /**
  302. * Add an index for the rules configuration plugin column.
  303. */
  304. function rules_update_7202() {
  305. db_add_index('rules_config', 'plugin', array('plugin'));
  306. }
  307. /**
  308. * Fix the length of the rules_config.name column.
  309. */
  310. function rules_update_7203() {
  311. db_drop_unique_key('rules_config', 'name');
  312. $keys = array(
  313. 'unique keys' => array(
  314. 'name' => array('name'),
  315. ),
  316. );
  317. db_change_field('rules_config', 'name', 'name', array(
  318. 'type' => 'varchar',
  319. 'length' => '64',
  320. 'not null' => TRUE,
  321. 'description' => 'The name of the configuration.',
  322. ), $keys);
  323. }
  324. /**
  325. * Add a table for rules-config tags.
  326. */
  327. function rules_update_7204() {
  328. if (!db_table_exists('rules_tags')) {
  329. $schema['rules_tags'] = array(
  330. 'fields' => array(
  331. 'id' => array(
  332. 'type' => 'int',
  333. 'unsigned' => TRUE,
  334. 'not null' => TRUE,
  335. 'description' => 'The primary identifier of the configuration.',
  336. ),
  337. 'tag' => array(
  338. 'type' => 'varchar',
  339. 'length' => '255',
  340. 'not null' => TRUE,
  341. 'description' => 'The tag string associated with this configuration',
  342. ),
  343. ),
  344. 'primary key' => array('id', 'tag'),
  345. 'foreign keys' => array(
  346. 'id' => array('rules_config' => 'id'),
  347. ),
  348. );
  349. db_create_table('rules_tags', $schema['rules_tags']);
  350. }
  351. }
  352. /**
  353. * Add the rules_dependencies table and the rules_config.dirty column.
  354. */
  355. function rules_update_7205() {
  356. if (!db_table_exists('rules_dependencies')) {
  357. $schema['rules_dependencies'] = array(
  358. 'fields' => array(
  359. 'id' => array(
  360. 'type' => 'int',
  361. 'unsigned' => TRUE,
  362. 'not null' => TRUE,
  363. 'description' => 'The primary identifier of the configuration.',
  364. ),
  365. 'module' => array(
  366. 'type' => 'varchar',
  367. 'length' => '255',
  368. 'not null' => TRUE,
  369. 'description' => 'The name of the module that is required for the configuration.',
  370. ),
  371. ),
  372. 'primary key' => array('id', 'module'),
  373. 'indexes' => array(
  374. 'module' => array('module'),
  375. ),
  376. 'foreign keys' => array(
  377. 'id' => array('rules_config' => 'id'),
  378. ),
  379. );
  380. db_create_table('rules_dependencies', $schema['rules_dependencies']);
  381. }
  382. if (!db_field_exists('rules_config', 'dirty')) {
  383. db_add_field('rules_config', 'dirty', array(
  384. 'type' => 'int',
  385. 'not null' => TRUE,
  386. 'default' => 0,
  387. 'size' => 'tiny',
  388. ));
  389. }
  390. }
  391. /**
  392. * Flush all caches.
  393. */
  394. function rules_update_7206() {
  395. // The update system is going to flush all caches anyway, so nothing to do.
  396. }
  397. /**
  398. * Flush all caches.
  399. */
  400. function rules_update_7207() {
  401. // The update system is going to flush all caches anyway, so nothing to do.
  402. }
  403. /**
  404. * Flush all caches to update the data_is_empty condition info.
  405. */
  406. function rules_update_7208() {
  407. // The update system is going to flush all caches anyway, so nothing to do.
  408. }
  409. /**
  410. * Creates a flag that enables a permission for using components.
  411. */
  412. function rules_update_7209() {
  413. // Create a access exposed flag column.
  414. db_add_field('rules_config', 'access_exposed', array(
  415. 'type' => 'int',
  416. 'not null' => TRUE,
  417. 'default' => 0,
  418. 'size' => 'tiny',
  419. 'description' => 'Whether to use a permission to control access for using components.',
  420. ));
  421. }