Projet

Général

Profil

Paste
Télécharger (6,35 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / rules / rules_scheduler / rules_scheduler.install @ 950416da

1
<?php
2

    
3
/**
4
 * @file
5
 * Rules Scheduler - Installation file.
6
 */
7

    
8
/**
9
 * Implements hook_schema().
10
 */
11
function rules_scheduler_schema() {
12
  $schema['rules_scheduler'] = array(
13
    'description' => 'Stores scheduled tasks.',
14
    'fields' => array(
15
      'tid' => array(
16
        'type' => 'serial',
17
        'unsigned' => TRUE,
18
        'not null' => TRUE,
19
        'description' => "The scheduled task's id.",
20
      ),
21
      'config' => array(
22
        'type' => 'varchar',
23
        'length' => '64',
24
        'default' => '',
25
        'not null' => TRUE,
26
        'description' => "The scheduled configuration's name.",
27
      ),
28
      'date' => array(
29
        'description' => 'The Unix timestamp of when the task is to be scheduled.',
30
        'type' => 'int',
31
        'not null' => TRUE,
32
      ),
33
      'data' => array(
34
        'type' => 'blob',
35
        'size' => 'big',
36
        'not null' => FALSE,
37
        'serialize' => TRUE,
38
        'description' => 'The whole, serialized evaluation data.',
39
      ),
40
      'identifier' => array(
41
        'type' => 'varchar',
42
        'length' => '255',
43
        'default' => '',
44
        'not null' => FALSE,
45
        'description' => 'The user defined string identifying this task.',
46
      ),
47
      'handler' => array(
48
        'type' => 'varchar',
49
        'length' => '255',
50
        'not null' => FALSE,
51
        'description' => 'The fully-qualified class name of the queue item handler.',
52
      ),
53
    ),
54
    'primary key' => array('tid'),
55
    'indexes' => array(
56
      'date' => array('date'),
57
    ),
58
    'unique key' => array(
59
      'id' => array('config', 'identifier'),
60
    ),
61
  );
62
  return $schema;
63
}
64

    
65
/**
66
 * Implements hook_install().
67
 */
68
function rules_scheduler_install() {
69
  // Create the queue to hold scheduled tasks.
70
  $queue = DrupalQueue::get('rules_scheduler_tasks', TRUE);
71
  $queue->createQueue();
72
}
73

    
74
/**
75
 * Implements hook_uninstall().
76
 */
77
function rules_scheduler_uninstall() {
78
  // Clean up after ourselves by deleting the queue and all items in it.
79
  $queue = DrupalQueue::get('rules_scheduler_tasks');
80
  $queue->deleteQueue();
81
}
82

    
83
/**
84
 * Upgrade from Rules scheduler 6.x-1.x to 7.x.
85
 */
86
function rules_scheduler_update_7200() {
87
  // Rename the old table so we can keep its content and start over with a
88
  // fresh one.
89
  db_rename_table('rules_scheduler', 'rules_scheduler_d6');
90
  // Create the d7 table.
91
  $schema['rules_scheduler'] = array(
92
    'description' => 'Stores scheduled tasks.',
93
    'fields' => array(
94
      'tid' => array(
95
        'type' => 'serial',
96
        'unsigned' => TRUE,
97
        'not null' => TRUE,
98
        'description' => "The scheduled task's id.",
99
      ),
100
      'config' => array(
101
        'type' => 'varchar',
102
        'length' => '255',
103
        'default' => '',
104
        'not null' => TRUE,
105
        'description' => "The scheduled configuration's name.",
106
      ),
107
      'date' => array(
108
        'description' => 'The Unix timestamp of when the task is to be scheduled.',
109
        'type' => 'int',
110
        'not null' => TRUE,
111
      ),
112
      'data' => array(
113
        'type' => 'text',
114
        'not null' => FALSE,
115
        'serialize' => TRUE,
116
        'description' => 'The whole, serialized evaluation data.',
117
      ),
118
      'identifier' => array(
119
        'type' => 'varchar',
120
        'length' => '255',
121
        'default' => '',
122
        'not null' => FALSE,
123
        'description' => 'The user defined string identifying this task.',
124
      ),
125
    ),
126
    'primary key' => array('tid'),
127
    'indexes' => array('date' => array('date')),
128
  );
129
  db_create_table('rules_scheduler', $schema['rules_scheduler']);
130
}
131

    
132
/**
133
 * Fix the length of the rules_scheduler.name column.
134
 */
135
function rules_scheduler_update_7202() {
136
  // Note that update 7201 (add the 'id' unique key') has been removed as it is
137
  // incorporated by 7202. For anyone that has already run the previous update
138
  // 7201, we have to first drop the unique key.
139
  db_drop_unique_key('rules_scheduler', 'id');
140
  db_change_field('rules_scheduler', 'config', 'config', array(
141
    'type' => 'varchar',
142
    'length' => '64',
143
    'default' => '',
144
    'not null' => TRUE,
145
    'description' => "The scheduled configuration's name.",
146
  ));
147
  db_add_unique_key('rules_scheduler', 'id', array('config', 'identifier'));
148
}
149

    
150
/**
151
 * Add a database column for specifying a queue item handler.
152
 */
153
function rules_scheduler_update_7203() {
154
  db_add_field('rules_scheduler', 'handler', array(
155
    'type' => 'varchar',
156
    'length' => '255',
157
    'not null' => FALSE,
158
    'description' => 'The fully-qualified class name of the queue item handler.',
159
  ));
160
}
161

    
162
/**
163
 * Rename rules_scheduler.state into rules_scheduler.data.
164
 */
165
function rules_scheduler_update_7204() {
166
  if (db_field_exists('rules_scheduler', 'state')) {
167
    db_change_field('rules_scheduler', 'state', 'data', array(
168
      'type' => 'text',
169
      'not null' => FALSE,
170
      'serialize' => TRUE,
171
      'description' => 'The whole, serialized evaluation data.',
172
    ));
173
  }
174
}
175

    
176
/**
177
 * Use blob:big for rules_scheduler.data for compatibility with PostgreSQL.
178
 */
179
function rules_scheduler_update_7205() {
180
  if (db_field_exists('rules_scheduler', 'data')) {
181
    db_change_field('rules_scheduler', 'data', 'data', array(
182
      'type' => 'blob',
183
      'size' => 'big',
184
      'not null' => FALSE,
185
      'serialize' => TRUE,
186
      'description' => 'The whole, serialized evaluation data.',
187
    ));
188
  }
189
}
190

    
191
/**
192
 * Rules upgrade callback for mapping the action name.
193
 */
194
function rules_scheduler_action_upgrade_map_name($element) {
195
  return 'schedule';
196
}
197

    
198
/**
199
 * Rules upgrade callback.
200
 */
201
function rules_scheduler_action_upgrade($element, $target) {
202
  $target->settings['component'] = $element['#info']['set'];
203
  $target->settings['date'] = $element['#settings']['task_date'];
204
  $target->settings['identifier'] = $element['#settings']['task_identifier'];
205

    
206
  unset($element['#info']['arguments']['task_date'], $element['#info']['arguments']['task_identifier']);
207
  foreach ($element['#info']['arguments'] as $name => $info) {
208
    rules_upgrade_element_parameter_settings($element, $target, $name, $info, 'param_' . $name);
209
  }
210
}
211

    
212
/**
213
 * Rules upgrade callback for mapping the action name.
214
 */
215
function rules_action_delete_scheduled_set_upgrade_map_name($element) {
216
  return 'schedule_delete';
217
}
218

    
219
/**
220
 * Rules upgrade callback.
221
 */
222
function rules_action_delete_scheduled_set_upgrade($element, $target) {
223
  $target->settings['component'] = $element['#settings']['ruleset'];
224
  $target->settings['task'] = $element['#settings']['task_identifier'];
225
}