rules.install 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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. 'table' => 'rules_config',
  128. 'columns' => array('id' => 'id'),
  129. ),
  130. );
  131. $schema['rules_tags'] = array(
  132. 'fields' => array(
  133. 'id' => array(
  134. 'type' => 'int',
  135. 'unsigned' => TRUE,
  136. 'not null' => TRUE,
  137. 'description' => 'The primary identifier of the configuration.',
  138. ),
  139. 'tag' => array(
  140. 'type' => 'varchar',
  141. 'length' => '255',
  142. 'not null' => TRUE,
  143. 'description' => 'The tag string associated with this configuration',
  144. ),
  145. ),
  146. 'primary key' => array('id', 'tag'),
  147. 'foreign keys' => array(
  148. 'table' => 'rules_config',
  149. 'columns' => array('id' => 'id'),
  150. ),
  151. );
  152. $schema['rules_dependencies'] = array(
  153. 'fields' => array(
  154. 'id' => array(
  155. 'type' => 'int',
  156. 'unsigned' => TRUE,
  157. 'not null' => TRUE,
  158. 'description' => 'The primary identifier of the configuration.',
  159. ),
  160. 'module' => array(
  161. 'type' => 'varchar',
  162. 'length' => '255',
  163. 'not null' => TRUE,
  164. 'description' => 'The name of the module that is required for the configuration.',
  165. ),
  166. ),
  167. 'primary key' => array('id', 'module'),
  168. 'indexes' => array(
  169. 'module' => array('module'),
  170. ),
  171. 'foreign keys' => array(
  172. 'table' => 'rules_config',
  173. 'columns' => array('id' => 'id'),
  174. ),
  175. );
  176. $schema['cache_rules'] = drupal_get_schema_unprocessed('system', 'cache');
  177. $schema['cache_rules']['description'] = 'Cache table for the rules engine to store configured items.';
  178. return $schema;
  179. }
  180. /**
  181. * Upgrade from Rules 6.x-1.x to 7.x.
  182. */
  183. function rules_update_7200() {
  184. // Create the new db tables first.
  185. $schema['rules_config'] = array(
  186. 'fields' => array(
  187. 'id' => array(
  188. 'type' => 'serial',
  189. 'not null' => TRUE,
  190. 'description' => 'The internal identifier for any configuration.',
  191. ),
  192. 'name' => array(
  193. 'type' => 'varchar',
  194. 'length' => '255',
  195. 'not null' => TRUE,
  196. 'description' => 'The name of the configuration.',
  197. ),
  198. 'label' => array(
  199. 'type' => 'varchar',
  200. 'length' => '255',
  201. 'not null' => TRUE,
  202. 'description' => 'The label of the configuration.',
  203. 'default' => 'unlabeled',
  204. ),
  205. 'plugin' => array(
  206. 'type' => 'varchar',
  207. 'length' => 127,
  208. 'not null' => TRUE,
  209. 'description' => 'The name of the plugin of this configuration.',
  210. ),
  211. 'active' => array(
  212. 'description' => 'Boolean indicating whether the configuration is active. Usage depends on how the using module makes use of it.',
  213. 'type' => 'int',
  214. 'not null' => TRUE,
  215. 'default' => 1,
  216. ),
  217. 'weight' => array(
  218. 'type' => 'int',
  219. 'not null' => TRUE,
  220. 'default' => 0,
  221. 'size' => 'tiny',
  222. 'description' => 'Weight of the configuration. Usage depends on how the using module makes use of it.',
  223. ),
  224. 'status' => array(
  225. 'type' => 'int',
  226. 'not null' => TRUE,
  227. // Set the default to ENTITY_CUSTOM without using the constant as it is
  228. // not safe to use it at this point.
  229. 'default' => 0x01,
  230. 'size' => 'tiny',
  231. 'description' => 'The exportable status of the entity.',
  232. ),
  233. 'module' => array(
  234. 'description' => 'The name of the providing module if the entity has been defined in code.',
  235. 'type' => 'varchar',
  236. 'length' => 255,
  237. 'not null' => FALSE,
  238. ),
  239. 'data' => array(
  240. 'type' => 'blob',
  241. 'size' => 'big',
  242. 'not null' => FALSE,
  243. 'serialize' => TRUE,
  244. 'description' => 'Everything else, serialized.',
  245. ),
  246. ),
  247. 'primary key' => array('id'),
  248. 'unique keys' => array(
  249. 'name' => array('name'),
  250. ),
  251. );
  252. $schema['rules_trigger'] = array(
  253. 'fields' => array(
  254. 'id' => array(
  255. 'type' => 'int',
  256. 'unsigned' => TRUE,
  257. 'not null' => TRUE,
  258. 'description' => 'The primary identifier of the configuration.',
  259. ),
  260. 'event' => array(
  261. 'type' => 'varchar',
  262. 'length' => '127',
  263. 'not null' => TRUE,
  264. 'default' => '',
  265. 'description' => 'The name of the event on which the configuration should be triggered.',
  266. ),
  267. ),
  268. 'primary key' => array('id', 'event'),
  269. 'foreign keys' => array(
  270. 'table' => 'rules_config',
  271. 'columns' => array('id' => 'id'),
  272. ),
  273. );
  274. db_create_table('rules_config', $schema['rules_config']);
  275. db_create_table('rules_trigger', $schema['rules_trigger']);
  276. // The cache table already exists, but changed. So re-create it.
  277. db_drop_table('cache_rules');
  278. $schema['cache_rules'] = drupal_get_schema_unprocessed('system', 'cache');
  279. $schema['cache_rules']['description'] = 'Cache table for the rules engine to store configured items.';
  280. db_create_table('cache_rules', $schema['cache_rules']);
  281. // Remove deprecated variables.
  282. variable_del('rules_inactive_sets');
  283. variable_del('rules_show_fixed');
  284. variable_del('rules_hide_token_message');
  285. variable_del('rules_counter');
  286. 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.');
  287. }
  288. /**
  289. * Add in the exportable entity db columns as required by the entity API.
  290. */
  291. function rules_update_7201() {
  292. // Previously this was update 7200, so check whether we need to run it really.
  293. // The update has been moved as 7200 needs to be the 6.x-7.x upgrade.
  294. if (!db_field_exists('rules_config', 'status')) {
  295. db_add_field('rules_config', 'status', array(
  296. 'type' => 'int',
  297. 'not null' => TRUE,
  298. 'default' => ENTITY_CUSTOM,
  299. 'size' => 'tiny',
  300. 'description' => 'The exportable status of the entity.',
  301. ));
  302. // The module column did already exist before.
  303. }
  304. }
  305. /**
  306. * Add an index for the rules configuration plugin column.
  307. */
  308. function rules_update_7202() {
  309. db_add_index('rules_config', 'plugin', array('plugin'));
  310. }
  311. /**
  312. * Fix the length of the rules_config.name column.
  313. */
  314. function rules_update_7203() {
  315. db_drop_unique_key('rules_config', 'name');
  316. $keys = array(
  317. 'unique keys' => array(
  318. 'name' => array('name'),
  319. ),
  320. );
  321. db_change_field('rules_config', 'name', 'name', array(
  322. 'type' => 'varchar',
  323. 'length' => '64',
  324. 'not null' => TRUE,
  325. 'description' => 'The name of the configuration.',
  326. ), $keys);
  327. }
  328. /**
  329. * Add a table for rules-config tags.
  330. */
  331. function rules_update_7204() {
  332. if (!db_table_exists('rules_tags')) {
  333. $schema['rules_tags'] = array(
  334. 'fields' => array(
  335. 'id' => array(
  336. 'type' => 'int',
  337. 'unsigned' => TRUE,
  338. 'not null' => TRUE,
  339. 'description' => 'The primary identifier of the configuration.',
  340. ),
  341. 'tag' => array(
  342. 'type' => 'varchar',
  343. 'length' => '255',
  344. 'not null' => TRUE,
  345. 'description' => 'The tag string associated with this configuration',
  346. ),
  347. ),
  348. 'primary key' => array('id', 'tag'),
  349. 'foreign keys' => array(
  350. 'table' => 'rules_config',
  351. 'columns' => array('id' => 'id'),
  352. ),
  353. );
  354. db_create_table('rules_tags', $schema['rules_tags']);
  355. }
  356. }
  357. /**
  358. * Add the rules_dependencies table and the rules_config.dirty column.
  359. */
  360. function rules_update_7205() {
  361. if (!db_table_exists('rules_dependencies')) {
  362. $schema['rules_dependencies'] = array(
  363. 'fields' => array(
  364. 'id' => array(
  365. 'type' => 'int',
  366. 'unsigned' => TRUE,
  367. 'not null' => TRUE,
  368. 'description' => 'The primary identifier of the configuration.',
  369. ),
  370. 'module' => array(
  371. 'type' => 'varchar',
  372. 'length' => '255',
  373. 'not null' => TRUE,
  374. 'description' => 'The name of the module that is required for the configuration.',
  375. ),
  376. ),
  377. 'primary key' => array('id', 'module'),
  378. 'indexes' => array(
  379. 'module' => array('module'),
  380. ),
  381. 'foreign keys' => array(
  382. 'table' => 'rules_config',
  383. 'columns' => array('id' => 'id'),
  384. ),
  385. );
  386. db_create_table('rules_dependencies', $schema['rules_dependencies']);
  387. }
  388. if (!db_field_exists('rules_config', 'dirty')) {
  389. db_add_field('rules_config', 'dirty', array(
  390. 'type' => 'int',
  391. 'not null' => TRUE,
  392. 'default' => 0,
  393. 'size' => 'tiny',
  394. ));
  395. }
  396. }
  397. /**
  398. * Flush all caches.
  399. */
  400. function rules_update_7206() {
  401. // The update system is going to flush all caches anyway, so nothing to do.
  402. }
  403. /**
  404. * Flush all caches.
  405. */
  406. function rules_update_7207() {
  407. // The update system is going to flush all caches anyway, so nothing to do.
  408. }
  409. /**
  410. * Flush all caches to update the data_is_empty condition info.
  411. */
  412. function rules_update_7208() {
  413. // The update system is going to flush all caches anyway, so nothing to do.
  414. }
  415. /**
  416. * Creates a flag that enables a permission for using components.
  417. */
  418. function rules_update_7209() {
  419. // Create a access exposed flag column.
  420. db_add_field('rules_config', 'access_exposed', array(
  421. 'type' => 'int',
  422. 'not null' => TRUE,
  423. 'default' => 0,
  424. 'size' => 'tiny',
  425. 'description' => 'Whether to use a permission to control access for using components.',
  426. ));
  427. }