Projet

Général

Profil

Paste
Télécharger (5,11 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / job_scheduler / job_scheduler.install @ 082b75eb

1
<?php
2

    
3
/**
4
 * @file
5
 * Schema definitions install/update/uninstall hooks.
6
 */
7

    
8
/**
9
 * Implements hook_uninstall().
10
 */
11
function job_scheduler_uninstall() {
12

    
13
  db_delete('variable')
14
    ->condition('name', 'job_scheduler_class_%', 'like')
15
    ->execute();
16

    
17
  variable_del('job_scheduler_rebuild_all');
18
}
19

    
20
/**
21
 * Implements hook_schema().
22
 */
23
function job_scheduler_schema() {
24
  $schema = array();
25
  $schema['job_schedule'] = array(
26
    'description' => 'Schedule of jobs to be executed.',
27
    'fields' => array(
28
      'item_id' => array(
29
        'type' => 'serial',
30
        'unsigned' => TRUE,
31
        'not null' => TRUE,
32
        'description' => 'Primary Key: Unique item ID.',
33
      ),
34
      'name' => array(
35
        'type' => 'varchar',
36
        'length' => 128,
37
        'not null' => TRUE,
38
        'default' => '',
39
        'description' => 'Name of the schedule.',
40
      ),
41
      'type' => array(
42
        'type' => 'varchar',
43
        'length' => 128,
44
        'not null' => TRUE,
45
        'default' => '',
46
        'description' => 'Type identifier of the job.',
47
      ),
48
      'id' => array(
49
        'type' => 'int',
50
        'not null' => TRUE,
51
        'default' => 0,
52
        'unsigned' => TRUE,
53
        'description' => 'Numeric identifier of the job.',
54
      ),
55
      'period' => array(
56
        'type' => 'int',
57
        'unsigned' => TRUE,
58
        'default' => 0,
59
        'not null' => TRUE,
60
        'description' => 'Time period after which job is to be executed.',
61
      ),
62
      'crontab' => array(
63
        'type' => 'varchar',
64
        'length' => 255,
65
        'not null' => TRUE,
66
        'default' => '',
67
        'description' => 'Crontab line in *NIX format.',
68
      ),
69
      'data' => array(
70
        'type' => 'blob',
71
        'not null' => FALSE,
72
        'size' => 'big',
73
        'serialize' => TRUE,
74
        'description' => 'The arbitrary data for the item.',
75
      ),
76
      'expire' => array(
77
        'type' => 'int',
78
        'not null' => TRUE,
79
        'default' => 0,
80
        'description' => 'Timestamp when job expires.',
81
      ),
82
      'last' => array(
83
        'type' => 'int',
84
        'unsigned' => TRUE,
85
        'default' => 0,
86
        'not null' => TRUE,
87
        'description' => 'Timestamp when a job was last executed.',
88
      ),
89
      'periodic' => array(
90
        'type' => 'int',
91
        'size' => 'small',
92
        'unsigned' => TRUE,
93
        'default' => 0,
94
        'not null' => TRUE,
95
        'description' => 'If true job will be automatically rescheduled.',
96
      ),
97
      'next' => array(
98
        'type' => 'int',
99
        'unsigned' => TRUE,
100
        'default' => 0,
101
        'not null' => TRUE,
102
        'description' => 'Timestamp when a job is to be executed (next = last + period), used for fast ordering.',
103
      ),
104
      'scheduled' => array(
105
        'type' => 'int',
106
        'unsigned' => TRUE,
107
        'default' => 0,
108
        'not null' => TRUE,
109
        'description' => 'Timestamp when a job was scheduled. 0 if a job is currently not scheduled.',
110
      ),
111
    ),
112
    'primary key' => array('item_id'),
113
    'indexes' => array(
114
      'name_type_id' => array('name', 'type', 'id'),
115
      'name_type' => array('name', 'type'),
116
      'next' => array('next'),
117
      'scheduled' => array('scheduled'),
118
    ),
119
  );
120
  return $schema;
121
}
122

    
123
/**
124
 * Fix indexes on next.
125
 */
126
function job_scheduler_update_6101() {
127
  $ret = array();
128
  db_drop_index($ret, 'job_schedule', 'last_period');
129
  db_drop_index($ret, 'job_schedule', 'periodic');
130
  db_add_index($ret, 'job_schedule', 'next', array('next'));
131
  return $ret;
132
}
133

    
134
/**
135
 * Rename 'callback' to 'name' field.
136
 */
137
function job_scheduler_update_7100() {
138
  db_drop_index('job_schedule', 'callback_type_id');
139
  db_drop_index('job_schedule', 'callback_type');
140
  $spec = array(
141
    'type' => 'varchar',
142
    'length' => 128,
143
    'not null' => TRUE,
144
    'default' => '',
145
    'description' => 'Name of the schedule.',
146
  );
147
  db_change_field('job_schedule', 'callback', 'name', $spec);
148
  db_add_index('job_schedule', 'name_type_id', array('name', 'type', 'id'));
149
  db_add_index('job_schedule', 'name_type', array('name', 'type'));
150
}
151

    
152
/**
153
 * Add fields: item_id, crontab, data, expire.
154
 */
155
function job_scheduler_update_7101() {
156
  $spec = array(
157
    'type' => 'varchar',
158
    'length' => 255,
159
    'not null' => TRUE,
160
    'default' => '',
161
    'description' => 'Crontab line in *NIX format.',
162
  );
163
  db_add_field('job_schedule', 'crontab', $spec);
164
  $spec = array(
165
    'type' => 'blob',
166
    'not null' => FALSE,
167
    'size' => 'big',
168
    'serialize' => TRUE,
169
    'description' => 'The arbitrary data for the item.',
170
  );
171
  db_add_field('job_schedule', 'data', $spec);
172
  $spec = array(
173
    'type' => 'int',
174
    'not null' => TRUE,
175
    'default' => 0,
176
    'description' => 'Timestamp when job expires.',
177
  );
178
  db_add_field('job_schedule', 'expire', $spec);
179
  $spec = array(
180
    'type' => 'serial',
181
    'unsigned' => TRUE,
182
    'not null' => TRUE,
183
    'description' => 'Primary Key: Unique item ID.',
184
  );
185
  db_add_field('job_schedule', 'item_id', $spec, array('primary key' => array('item_id')));
186
}
187

    
188
/**
189
 * Drop field: created.
190
 */
191
function job_scheduler_update_7102() {
192
  if (db_field_exists('job_schedule', 'created')) {
193
    db_drop_field('job_schedule', 'created');
194
  }
195
}