rules_scheduler.install 4.6 KB

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