123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <?php
- /**
- * @file
- * Rules Scheduler - Installation file.
- */
- /**
- * Implements hook_schema().
- */
- function rules_scheduler_schema() {
- $schema['rules_scheduler'] = array(
- 'description' => 'Stores scheduled tasks.',
- 'fields' => array(
- 'tid' => array(
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => "The scheduled task's id.",
- ),
- 'config' => array(
- 'type' => 'varchar',
- 'length' => '64',
- 'default' => '',
- 'not null' => TRUE,
- 'description' => "The scheduled configuration's name.",
- ),
- 'date' => array(
- 'description' => 'The Unix timestamp of when the task is to be scheduled.',
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'data' => array(
- 'type' => 'blob',
- 'size' => 'big',
- 'not null' => FALSE,
- 'serialize' => TRUE,
- 'description' => 'The whole, serialized evaluation data.',
- ),
- 'identifier' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'default' => '',
- 'not null' => FALSE,
- 'description' => 'The user defined string identifying this task.',
- ),
- 'handler' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => FALSE,
- 'description' => 'The fully-qualified class name of the queue item handler.',
- ),
- ),
- 'primary key' => array('tid'),
- 'indexes' => array(
- 'date' => array('date'),
- ),
- 'unique key' => array(
- 'id' => array('config', 'identifier'),
- ),
- );
- return $schema;
- }
- /**
- * Implements hook_install().
- */
- function rules_scheduler_install() {
- // Create the queue to hold scheduled tasks.
- $queue = DrupalQueue::get('rules_scheduler_tasks', TRUE);
- $queue->createQueue();
- }
- /**
- * Implements hook_uninstall().
- */
- function rules_scheduler_uninstall() {
- // Clean up after ourselves by deleting the queue and all items in it.
- $queue = DrupalQueue::get('rules_scheduler_tasks');
- $queue->deleteQueue();
- }
- /**
- * Upgrade from Rules scheduler 6.x-1.x to 7.x.
- */
- function rules_scheduler_update_7200() {
- // Rename the old table so we can keep its content and start over with a
- // fresh one.
- db_rename_table('rules_scheduler', 'rules_scheduler_d6');
- // Create the d7 table.
- $schema['rules_scheduler'] = array(
- 'description' => 'Stores scheduled tasks.',
- 'fields' => array(
- 'tid' => array(
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => "The scheduled task's id.",
- ),
- 'config' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'default' => '',
- 'not null' => TRUE,
- 'description' => "The scheduled configuration's name.",
- ),
- 'date' => array(
- 'description' => 'The Unix timestamp of when the task is to be scheduled.',
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'data' => array(
- 'type' => 'text',
- 'not null' => FALSE,
- 'serialize' => TRUE,
- 'description' => 'The whole, serialized evaluation data.',
- ),
- 'identifier' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'default' => '',
- 'not null' => FALSE,
- 'description' => 'The user defined string identifying this task.',
- ),
- ),
- 'primary key' => array('tid'),
- 'indexes' => array('date' => array('date')),
- );
- db_create_table('rules_scheduler', $schema['rules_scheduler']);
- }
- /**
- * Fix the length of the rules_scheduler.name column.
- */
- function rules_scheduler_update_7202() {
- // Note that update 7201 (add the 'id' unique key') has been removed as it is
- // incorporated by 7202. For anyone that has already run the previous update
- // 7201, we have to first drop the unique key.
- db_drop_unique_key('rules_scheduler', 'id');
- db_change_field('rules_scheduler', 'config', 'config', array(
- 'type' => 'varchar',
- 'length' => '64',
- 'default' => '',
- 'not null' => TRUE,
- 'description' => "The scheduled configuration's name.",
- ));
- db_add_unique_key('rules_scheduler', 'id', array('config', 'identifier'));
- }
- /**
- * Add a database column for specifying a queue item handler.
- */
- function rules_scheduler_update_7203() {
- db_add_field('rules_scheduler', 'handler', array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => FALSE,
- 'description' => 'The fully-qualified class name of the queue item handler.',
- ));
- }
- /**
- * Rename rules_scheduler.state into rules_scheduler.data.
- */
- function rules_scheduler_update_7204() {
- if (db_field_exists('rules_scheduler', 'state')) {
- db_change_field('rules_scheduler', 'state', 'data', array(
- 'type' => 'text',
- 'not null' => FALSE,
- 'serialize' => TRUE,
- 'description' => 'The whole, serialized evaluation data.',
- ));
- }
- }
- /**
- * Use blob:big for rules_scheduler.data for compatibility with PostgreSQL.
- */
- function rules_scheduler_update_7205() {
- if (db_field_exists('rules_scheduler', 'data')) {
- db_change_field('rules_scheduler', 'data', 'data', array(
- 'type' => 'blob',
- 'size' => 'big',
- 'not null' => FALSE,
- 'serialize' => TRUE,
- 'description' => 'The whole, serialized evaluation data.',
- ));
- }
- }
- /**
- * Rules upgrade callback for mapping the action name.
- */
- function rules_scheduler_action_upgrade_map_name($element) {
- return 'schedule';
- }
- /**
- * Rules upgrade callback.
- */
- function rules_scheduler_action_upgrade($element, $target) {
- $target->settings['component'] = $element['#info']['set'];
- $target->settings['date'] = $element['#settings']['task_date'];
- $target->settings['identifier'] = $element['#settings']['task_identifier'];
- unset($element['#info']['arguments']['task_date'], $element['#info']['arguments']['task_identifier']);
- foreach ($element['#info']['arguments'] as $name => $info) {
- rules_upgrade_element_parameter_settings($element, $target, $name, $info, 'param_' . $name);
- }
- }
- /**
- * Rules upgrade callback for mapping the action name.
- */
- function rules_action_delete_scheduled_set_upgrade_map_name($element) {
- return 'schedule_delete';
- }
- /**
- * Rules upgrade callback.
- */
- function rules_action_delete_scheduled_set_upgrade($element, $target) {
- $target->settings['component'] = $element['#settings']['ruleset'];
- $target->settings['task'] = $element['#settings']['task_identifier'];
- }
|