rules_scheduler.install 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /**
  3. * @file
  4. * Rules Scheduler - Installation file.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function rules_scheduler_schema() {
  10. $schema['rules_scheduler'] = array(
  11. 'description' => 'Stores scheduled tasks.',
  12. 'fields' => array(
  13. 'tid' => array(
  14. 'type' => 'serial',
  15. 'unsigned' => TRUE,
  16. 'not null' => TRUE,
  17. 'description' => "The scheduled task's id.",
  18. ),
  19. 'config' => array(
  20. 'type' => 'varchar',
  21. 'length' => '64',
  22. 'default' => '',
  23. 'not null' => TRUE,
  24. 'description' => "The scheduled configuration's name.",
  25. ),
  26. 'date' => array(
  27. 'description' => 'The Unix timestamp of when the task is to be scheduled.',
  28. 'type' => 'int',
  29. 'not null' => TRUE,
  30. ),
  31. 'data' => array(
  32. 'type' => 'blob',
  33. 'size' => 'big',
  34. 'not null' => FALSE,
  35. 'serialize' => TRUE,
  36. 'description' => 'The whole, serialized evaluation data.',
  37. ),
  38. 'identifier' => array(
  39. 'type' => 'varchar',
  40. 'length' => '255',
  41. 'default' => '',
  42. 'not null' => FALSE,
  43. 'description' => 'The user defined string identifying this task.',
  44. ),
  45. 'handler' => array(
  46. 'type' => 'varchar',
  47. 'length' => '255',
  48. 'not null' => FALSE,
  49. 'description' => 'The fully-qualified class name of the queue item handler.',
  50. ),
  51. ),
  52. 'primary key' => array('tid'),
  53. 'indexes' => array(
  54. 'date' => array('date'),
  55. ),
  56. 'unique key' => array(
  57. 'id' => array('config', 'identifier'),
  58. ),
  59. );
  60. return $schema;
  61. }
  62. /**
  63. * Implements hook_install().
  64. */
  65. function rules_scheduler_install() {
  66. // Create the queue to hold scheduled tasks.
  67. $queue = DrupalQueue::get('rules_scheduler_tasks', TRUE);
  68. $queue->createQueue();
  69. }
  70. /**
  71. * Implements hook_uninstall().
  72. */
  73. function rules_scheduler_uninstall() {
  74. // Clean up after ourselves by deleting the queue and all items in it.
  75. $queue = DrupalQueue::get('rules_scheduler_tasks');
  76. $queue->deleteQueue();
  77. }
  78. /**
  79. * Upgrade from Rules scheduler 6.x-1.x to 7.x.
  80. */
  81. function rules_scheduler_update_7200() {
  82. // Rename the old table so we can keep its content and start over with a
  83. // fresh one.
  84. db_rename_table('rules_scheduler', 'rules_scheduler_d6');
  85. // Create the d7 table.
  86. $schema['rules_scheduler'] = array(
  87. 'description' => 'Stores scheduled tasks.',
  88. 'fields' => array(
  89. 'tid' => array(
  90. 'type' => 'serial',
  91. 'unsigned' => TRUE,
  92. 'not null' => TRUE,
  93. 'description' => "The scheduled task's id.",
  94. ),
  95. 'config' => array(
  96. 'type' => 'varchar',
  97. 'length' => '255',
  98. 'default' => '',
  99. 'not null' => TRUE,
  100. 'description' => "The scheduled configuration's name.",
  101. ),
  102. 'date' => array(
  103. 'description' => 'The Unix timestamp of when the task is to be scheduled.',
  104. 'type' => 'int',
  105. 'not null' => TRUE,
  106. ),
  107. 'data' => array(
  108. 'type' => 'text',
  109. 'not null' => FALSE,
  110. 'serialize' => TRUE,
  111. 'description' => 'The whole, serialized evaluation data.',
  112. ),
  113. 'identifier' => array(
  114. 'type' => 'varchar',
  115. 'length' => '255',
  116. 'default' => '',
  117. 'not null' => FALSE,
  118. 'description' => 'The user defined string identifying this task.',
  119. ),
  120. ),
  121. 'primary key' => array('tid'),
  122. 'indexes' => array('date' => array('date')),
  123. );
  124. db_create_table('rules_scheduler', $schema['rules_scheduler']);
  125. }
  126. /**
  127. * Fix the length of the rules_scheduler.name column.
  128. */
  129. function rules_scheduler_update_7202() {
  130. // Note that update 7201 (add the 'id' unique key') has been removed as it is
  131. // incorporated by 7202. For anyone that has already run the previous update
  132. // 7201, we have to first drop the unique key.
  133. db_drop_unique_key('rules_scheduler', 'id');
  134. db_change_field('rules_scheduler', 'config', 'config', array(
  135. 'type' => 'varchar',
  136. 'length' => '64',
  137. 'default' => '',
  138. 'not null' => TRUE,
  139. 'description' => "The scheduled configuration's name.",
  140. ));
  141. db_add_unique_key('rules_scheduler', 'id', array('config', 'identifier'));
  142. }
  143. /**
  144. * Add a database column for specifying a queue item handler.
  145. */
  146. function rules_scheduler_update_7203() {
  147. db_add_field('rules_scheduler', 'handler', array(
  148. 'type' => 'varchar',
  149. 'length' => '255',
  150. 'not null' => FALSE,
  151. 'description' => 'The fully-qualified class name of the queue item handler.',
  152. ));
  153. }
  154. /**
  155. * Rename rules_scheduler.state into rules_scheduler.data.
  156. */
  157. function rules_scheduler_update_7204() {
  158. if (db_field_exists('rules_scheduler', 'state')) {
  159. db_change_field('rules_scheduler', 'state', 'data', array(
  160. 'type' => 'text',
  161. 'not null' => FALSE,
  162. 'serialize' => TRUE,
  163. 'description' => 'The whole, serialized evaluation data.',
  164. ));
  165. }
  166. }
  167. /**
  168. * Use blob:big for rules_scheduler.data for compatibility with PostgreSQL.
  169. */
  170. function rules_scheduler_update_7205() {
  171. if (db_field_exists('rules_scheduler', 'data')) {
  172. db_change_field('rules_scheduler', 'data', 'data', array(
  173. 'type' => 'blob',
  174. 'size' => 'big',
  175. 'not null' => FALSE,
  176. 'serialize' => TRUE,
  177. 'description' => 'The whole, serialized evaluation data.',
  178. ));
  179. }
  180. }
  181. /**
  182. * Rules upgrade callback for mapping the action name.
  183. */
  184. function rules_scheduler_action_upgrade_map_name($element) {
  185. return 'schedule';
  186. }
  187. /**
  188. * Rules upgrade callback.
  189. */
  190. function rules_scheduler_action_upgrade($element, $target) {
  191. $target->settings['component'] = $element['#info']['set'];
  192. $target->settings['date'] = $element['#settings']['task_date'];
  193. $target->settings['identifier'] = $element['#settings']['task_identifier'];
  194. unset($element['#info']['arguments']['task_date'], $element['#info']['arguments']['task_identifier']);
  195. foreach ($element['#info']['arguments'] as $name => $info) {
  196. rules_upgrade_element_parameter_settings($element, $target, $name, $info, 'param_' . $name);
  197. }
  198. }
  199. /**
  200. * Rules upgrade callback for mapping the action name.
  201. */
  202. function rules_action_delete_scheduled_set_upgrade_map_name($element) {
  203. return 'schedule_delete';
  204. }
  205. /**
  206. * Rules upgrade callback.
  207. */
  208. function rules_action_delete_scheduled_set_upgrade($element, $target) {
  209. $target->settings['component'] = $element['#settings']['ruleset'];
  210. $target->settings['task'] = $element['#settings']['task_identifier'];
  211. }