rules_scheduler.install 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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' => 'text',
  33. 'not null' => FALSE,
  34. 'serialize' => TRUE,
  35. 'description' => 'The whole, serialized evaluation data.',
  36. ),
  37. 'identifier' => array(
  38. 'type' => 'varchar',
  39. 'length' => '255',
  40. 'default' => '',
  41. 'not null' => FALSE,
  42. 'description' => 'The user defined string identifying this task.',
  43. ),
  44. 'handler' => array(
  45. 'type' => 'varchar',
  46. 'length' => '255',
  47. 'not null' => FALSE,
  48. 'description' => 'The fully qualified class name of a the queue item handler.',
  49. ),
  50. ),
  51. 'primary key' => array('tid'),
  52. 'indexes' => array(
  53. 'date' => array('date'),
  54. ),
  55. 'unique key' => array(
  56. 'id' => array('config', 'identifier'),
  57. ),
  58. );
  59. return $schema;
  60. }
  61. /**
  62. * Upgrade from Rules scheduler 6.x-1.x to 7.x.
  63. */
  64. function rules_scheduler_update_7200() {
  65. // Rename the old table so we can keep its content and start over with a
  66. // fresh one.
  67. db_rename_table('rules_scheduler', 'rules_scheduler_d6');
  68. // Create the d7 table.
  69. $schema['rules_scheduler'] = array(
  70. 'description' => 'Stores scheduled tasks.',
  71. 'fields' => array(
  72. 'tid' => array(
  73. 'type' => 'serial',
  74. 'unsigned' => TRUE,
  75. 'not null' => TRUE,
  76. 'description' => "The scheduled task's id.",
  77. ),
  78. 'config' => array(
  79. 'type' => 'varchar',
  80. 'length' => '255',
  81. 'default' => '',
  82. 'not null' => TRUE,
  83. 'description' => "The scheduled configuration's name.",
  84. ),
  85. 'date' => array(
  86. 'description' => 'The Unix timestamp of when the task is to be scheduled.',
  87. 'type' => 'int',
  88. 'not null' => TRUE,
  89. ),
  90. 'data' => array(
  91. 'type' => 'text',
  92. 'not null' => FALSE,
  93. 'serialize' => TRUE,
  94. 'description' => 'The whole, serialized evaluation data.',
  95. ),
  96. 'identifier' => array(
  97. 'type' => 'varchar',
  98. 'length' => '255',
  99. 'default' => '',
  100. 'not null' => FALSE,
  101. 'description' => 'The user defined string identifying this task.',
  102. ),
  103. ),
  104. 'primary key' => array('tid'),
  105. 'indexes' => array('date' => array('date')),
  106. );
  107. db_create_table('rules_scheduler', $schema['rules_scheduler']);
  108. }
  109. /**
  110. * Fix the length of the rules_scheduler.name column.
  111. */
  112. function rules_scheduler_update_7202() {
  113. // Note that update 7201 (add the 'id' unique key') has been removed as it is
  114. // incorporated by 7202. For anyone that has already run the previous update
  115. // 7201, we have to first drop the unique key.
  116. db_drop_unique_key('rules_scheduler', 'id');
  117. db_change_field('rules_scheduler', 'config', 'config', array(
  118. 'type' => 'varchar',
  119. 'length' => '64',
  120. 'default' => '',
  121. 'not null' => TRUE,
  122. 'description' => "The scheduled configuration's name.",
  123. ));
  124. db_add_unique_key('rules_scheduler', 'id', array('config', 'identifier'));
  125. }
  126. /**
  127. * Add a database column for specifying a queue item handler.
  128. */
  129. function rules_scheduler_update_7203() {
  130. db_add_field('rules_scheduler', 'handler', array(
  131. 'type' => 'varchar',
  132. 'length' => '255',
  133. 'not null' => FALSE,
  134. 'description' => 'The fully qualified class name of a the queue item handler.',
  135. ));
  136. }
  137. /**
  138. * Rename rules_scheduler.state into rules_scheduler.data.
  139. */
  140. function rules_scheduler_update_7204() {
  141. if (db_field_exists('rules_scheduler', 'state')) {
  142. db_change_field('rules_scheduler', 'state', 'data', array(
  143. 'type' => 'text',
  144. 'not null' => FALSE,
  145. 'serialize' => TRUE,
  146. 'description' => 'The whole, serialized evaluation data.',
  147. ));
  148. }
  149. }
  150. /**
  151. * Rules upgrade callback for mapping the action name.
  152. */
  153. function rules_scheduler_action_upgrade_map_name($element) {
  154. return 'schedule';
  155. }
  156. /**
  157. * Rules upgrade callback.
  158. */
  159. function rules_scheduler_action_upgrade($element, $target) {
  160. $target->settings['component'] = $element['#info']['set'];
  161. $target->settings['date'] = $element['#settings']['task_date'];
  162. $target->settings['identifier'] = $element['#settings']['task_identifier'];
  163. unset($element['#info']['arguments']['task_date'], $element['#info']['arguments']['task_identifier']);
  164. foreach ($element['#info']['arguments'] as $name => $info) {
  165. rules_upgrade_element_parameter_settings($element, $target, $name, $info, 'param_' . $name);
  166. }
  167. }
  168. /**
  169. * Rules upgrade callback for mapping the action name.
  170. */
  171. function rules_action_delete_scheduled_set_upgrade_map_name($element) {
  172. return 'schedule_delete';
  173. }
  174. /**
  175. * Rules upgrade callback.
  176. */
  177. function rules_action_delete_scheduled_set_upgrade($element, $target) {
  178. $target->settings['component'] = $element['#settings']['ruleset'];
  179. $target->settings['task'] = $element['#settings']['task_identifier'];
  180. }