Projet

Général

Profil

Paste
Télécharger (14,4 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / rules / rules.install @ 87dbc3bf

1
<?php
2

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

    
7
/**
8
 * Implements hook_install().
9
 */
10
function rules_install() {
11
  module_load_include('inc', 'rules', 'modules/events');
12
  // Set the modules' weight to 20, see
13
  // http://drupal.org/node/445084#comment-1533280 for the reasoning.
14
  db_query("UPDATE {system} SET weight = 20 WHERE name = 'rules'");
15
}
16

    
17
/**
18
 * Implements hook_uninstall().
19
 */
20
function rules_uninstall() {
21
  variable_del('rules_event_whitelist');
22
  variable_del('rules_debug');
23
}
24

    
25
/**
26
 * Implements hook_schema().
27
 */
28
function rules_schema() {
29
  $schema['rules_config'] = array(
30
    'fields' => array(
31
      'id' => array(
32
        'type' => 'serial',
33
        'not null' => TRUE,
34
        'description' => 'The internal identifier for any configuration.',
35
      ),
36
      'name' => array(
37
        'type' => 'varchar',
38
        'length' => '64',
39
        'not null' => TRUE,
40
        'description' => 'The name of the configuration.',
41
      ),
42
      'label' => array(
43
        'type' => 'varchar',
44
        'length' => '255',
45
        'not null' => TRUE,
46
        'description' => 'The label of the configuration.',
47
        'default' => 'unlabeled',
48
      ),
49
     'plugin' => array(
50
        'type' => 'varchar',
51
        'length' => 127,
52
        'not null' => TRUE,
53
        'description' => 'The name of the plugin of this configuration.',
54
      ),
55
      'active' => array(
56
        'description' => 'Boolean indicating whether the configuration is active. Usage depends on how the using module makes use of it.',
57
        'type' => 'int',
58
        'not null' => TRUE,
59
        'default' => 1,
60
      ),
61
      'weight' => array(
62
        'type' => 'int',
63
        'not null' => TRUE,
64
        'default' => 0,
65
        'size' => 'tiny',
66
        'description' => 'Weight of the configuration. Usage depends on how the using module makes use of it.',
67
      ),
68
      'status' => array(
69
        'type' => 'int',
70
        'not null' => TRUE,
71
        // Set the default to ENTITY_CUSTOM without using the constant as it is
72
        // not safe to use it at this point.
73
        'default' => 0x01,
74
        'size' => 'tiny',
75
        'description' => 'The exportable status of the entity.',
76
      ),
77
      'dirty' => array(
78
        'type' => 'int',
79
        'not null' => TRUE,
80
        'default' => 0,
81
        'size' => 'tiny',
82
        'description' => 'Dirty configurations fail the integrity check, e.g. due to missing dependencies.',
83
      ),
84
      'module' => array(
85
        'description' => 'The name of the providing module if the entity has been defined in code.',
86
        'type' => 'varchar',
87
        'length' => 255,
88
        'not null' => FALSE,
89
      ),
90
      'owner' => array(
91
        'description' => 'The name of the module via which the rule has been configured.',
92
        'type' => 'varchar',
93
        'length' => 255,
94
        'not null' => TRUE,
95
        'default' => 'rules',
96
      ),
97
      'access_exposed' => array(
98
        'type' => 'int',
99
        'not null' => TRUE,
100
        'default' => 0,
101
        'size' => 'tiny',
102
        'description' => 'Whether to use a permission to control access for using components.',
103
      ),
104
      'data' => array(
105
        'type' => 'blob',
106
        'size' => 'big',
107
        'not null' => FALSE,
108
        'serialize' => TRUE,
109
        'description' => 'Everything else, serialized.',
110
      ),
111
    ),
112
    'primary key' => array('id'),
113
    'unique keys' => array(
114
      'name' => array('name'),
115
    ),
116
    'indexes' => array(
117
      'plugin' => array('plugin'),
118
    ),
119
  );
120
  $schema['rules_trigger'] = array(
121
    'fields' => array(
122
      'id' => array(
123
        'type' => 'int',
124
        'unsigned' => TRUE,
125
        'not null' => TRUE,
126
        'description' => 'The primary identifier of the configuration.',
127
      ),
128
      'event' => array(
129
        'type' => 'varchar',
130
        'length' => '127',
131
        'not null' => TRUE,
132
        'default' => '',
133
        'description' => 'The name of the event on which the configuration should be triggered.',
134
      ),
135
    ),
136
    'primary key' => array('id', 'event'),
137
    'foreign keys' => array(
138
      'table' => 'rules_config',
139
      'columns' => array('id' => 'id'),
140
    ),
141
  );
142
  $schema['rules_tags'] = array(
143
    'fields' => array(
144
      'id' => array(
145
        'type' => 'int',
146
        'unsigned' => TRUE,
147
        'not null' => TRUE,
148
        'description' => 'The primary identifier of the configuration.',
149
      ),
150
      'tag' => array(
151
        'type' => 'varchar',
152
        'length' => '255',
153
        'not null' => TRUE,
154
        'description' => 'The tag string associated with this configuration',
155
      ),
156
    ),
157
    'primary key' => array('id', 'tag'),
158
    'foreign keys' => array(
159
      'table' => 'rules_config',
160
      'columns' => array('id' => 'id'),
161
    ),
162
  );
163
  $schema['rules_dependencies'] = array(
164
    'fields' => array(
165
      'id' => array(
166
        'type' => 'int',
167
        'unsigned' => TRUE,
168
        'not null' => TRUE,
169
        'description' => 'The primary identifier of the configuration.',
170
      ),
171
      'module' => array(
172
        'type' => 'varchar',
173
        'length' => '255',
174
        'not null' => TRUE,
175
        'description' => 'The name of the module that is required for the configuration.',
176
      ),
177
    ),
178
    'primary key' => array('id', 'module'),
179
    'indexes' => array(
180
      'module' => array('module'),
181
    ),
182
    'foreign keys' => array(
183
      'table' => 'rules_config',
184
      'columns' => array('id' => 'id'),
185
    ),
186
  );
187
  $schema['cache_rules'] = drupal_get_schema_unprocessed('system', 'cache');
188
  $schema['cache_rules']['description'] = 'Cache table for the rules engine to store configured items.';
189
  return $schema;
190
}
191

    
192
/**
193
 * Upgrade from Rules 6.x-1.x to 7.x.
194
 */
195
function rules_update_7200() {
196
  // Create the new db tables first.
197
  $schema['rules_config'] = array(
198
    'fields' => array(
199
      'id' => array(
200
        'type' => 'serial',
201
        'not null' => TRUE,
202
        'description' => 'The internal identifier for any configuration.',
203
      ),
204
      'name' => array(
205
        'type' => 'varchar',
206
        'length' => '255',
207
        'not null' => TRUE,
208
        'description' => 'The name of the configuration.',
209
      ),
210
      'label' => array(
211
        'type' => 'varchar',
212
        'length' => '255',
213
        'not null' => TRUE,
214
        'description' => 'The label of the configuration.',
215
        'default' => 'unlabeled',
216
      ),
217
     'plugin' => array(
218
        'type' => 'varchar',
219
        'length' => 127,
220
        'not null' => TRUE,
221
        'description' => 'The name of the plugin of this configuration.',
222
      ),
223
      'active' => array(
224
        'description' => 'Boolean indicating whether the configuration is active. Usage depends on how the using module makes use of it.',
225
        'type' => 'int',
226
        'not null' => TRUE,
227
        'default' => 1,
228
      ),
229
      'weight' => array(
230
        'type' => 'int',
231
        'not null' => TRUE,
232
        'default' => 0,
233
        'size' => 'tiny',
234
        'description' => 'Weight of the configuration. Usage depends on how the using module makes use of it.',
235
      ),
236
      'status' => array(
237
        'type' => 'int',
238
        'not null' => TRUE,
239
        // Set the default to ENTITY_CUSTOM without using the constant as it is
240
        // not safe to use it at this point.
241
        'default' => 0x01,
242
        'size' => 'tiny',
243
        'description' => 'The exportable status of the entity.',
244
      ),
245
      'module' => array(
246
        'description' => 'The name of the providing module if the entity has been defined in code.',
247
        'type' => 'varchar',
248
        'length' => 255,
249
        'not null' => FALSE,
250
      ),
251
      'data' => array(
252
        'type' => 'blob',
253
        'size' => 'big',
254
        'not null' => FALSE,
255
        'serialize' => TRUE,
256
        'description' => 'Everything else, serialized.',
257
      ),
258
    ),
259
    'primary key' => array('id'),
260
    'unique keys' => array(
261
      'name' => array('name'),
262
    ),
263
  );
264
  $schema['rules_trigger'] = array(
265
    'fields' => array(
266
      'id' => array(
267
        'type' => 'int',
268
        'unsigned' => TRUE,
269
        'not null' => TRUE,
270
        'description' => 'The primary identifier of the configuration.',
271
      ),
272
      'event' => array(
273
        'type' => 'varchar',
274
        'length' => '127',
275
        'not null' => TRUE,
276
        'default' => '',
277
        'description' => 'The name of the event on which the configuration should be triggered.',
278
      ),
279
    ),
280
    'primary key' => array('id', 'event'),
281
    'foreign keys' => array(
282
      'table' => 'rules_config',
283
      'columns' => array('id' => 'id'),
284
    ),
285
  );
286
  db_create_table('rules_config', $schema['rules_config']);
287
  db_create_table('rules_trigger', $schema['rules_trigger']);
288
  // The cache table already exists, but changed. So re-create it.
289
  db_drop_table('cache_rules');
290
  $schema['cache_rules'] = drupal_get_schema_unprocessed('system', 'cache');
291
  $schema['cache_rules']['description'] = 'Cache table for the rules engine to store configured items.';
292
  db_create_table('cache_rules', $schema['cache_rules']);
293
  // Remove deprecated variables.
294
  variable_del('rules_inactive_sets');
295
  variable_del('rules_show_fixed');
296
  variable_del('rules_hide_token_message');
297
  variable_del('rules_counter');
298

    
299
  return t('The database tables for Rules 2.x have been created. The old tables from Rules 1.x are still available and contain your rules, which are not updated yet.');
300
}
301

    
302
/**
303
 * Add in the exportable entity db columns as required by the entity API.
304
 */
305
function rules_update_7201() {
306
  // Previously this was update 7200, so check whether we need to run it really.
307
  // The update has been moved as 7200 needs to be the 6.x-7.x upgrade.
308
  if (!db_field_exists('rules_config', 'status')) {
309
    db_add_field('rules_config', 'status', array(
310
      'type' => 'int',
311
      'not null' => TRUE,
312
      'default' => ENTITY_CUSTOM,
313
      'size' => 'tiny',
314
      'description' => 'The exportable status of the entity.',
315
    ));
316
    // The module column did already exist before.
317
  }
318
}
319

    
320
/**
321
 * Add an index for the rules configuration plugin column.
322
 */
323
function rules_update_7202() {
324
  db_add_index('rules_config', 'plugin', array('plugin'));
325
}
326

    
327
/**
328
 * Fix the length of the rules_config.name column.
329
 */
330
function rules_update_7203() {
331
  db_drop_unique_key('rules_config', 'name');
332
  $keys = array(
333
    'unique keys' => array(
334
      'name' => array('name'),
335
    ),
336
  );
337
  db_change_field('rules_config', 'name', 'name', array(
338
    'type' => 'varchar',
339
    'length' => '64',
340
    'not null' => TRUE,
341
    'description' => 'The name of the configuration.',
342
  ), $keys);
343
}
344

    
345
/**
346
 * Add a table for rules-config tags.
347
 */
348
function rules_update_7204() {
349
  if (!db_table_exists('rules_tags')) {
350
    $schema['rules_tags'] = array(
351
      'fields' => array(
352
        'id' => array(
353
          'type' => 'int',
354
          'unsigned' => TRUE,
355
          'not null' => TRUE,
356
          'description' => 'The primary identifier of the configuration.',
357
        ),
358
        'tag' => array(
359
          'type' => 'varchar',
360
          'length' => '255',
361
          'not null' => TRUE,
362
          'description' => 'The tag string associated with this configuration',
363
        ),
364
      ),
365
      'primary key' => array('id', 'tag'),
366
      'foreign keys' => array(
367
        'table' => 'rules_config',
368
        'columns' => array('id' => 'id'),
369
      ),
370
    );
371
    db_create_table('rules_tags', $schema['rules_tags']);
372
  }
373
}
374

    
375
/**
376
 * Add the rules_dependencies table and the rules_config.dirty column.
377
 */
378
function rules_update_7205() {
379
  if (!db_table_exists('rules_dependencies')) {
380
    $schema['rules_dependencies'] = array(
381
      'fields' => array(
382
        'id' => array(
383
          'type' => 'int',
384
          'unsigned' => TRUE,
385
          'not null' => TRUE,
386
          'description' => 'The primary identifier of the configuration.',
387
        ),
388
        'module' => array(
389
          'type' => 'varchar',
390
          'length' => '255',
391
          'not null' => TRUE,
392
          'description' => 'The name of the module that is required for the configuration.',
393
        ),
394
      ),
395
      'primary key' => array('id', 'module'),
396
      'indexes' => array(
397
        'module' => array('module'),
398
      ),
399
      'foreign keys' => array(
400
        'table' => 'rules_config',
401
        'columns' => array('id' => 'id'),
402
      ),
403
    );
404
    db_create_table('rules_dependencies', $schema['rules_dependencies']);
405
  }
406
  if (!db_field_exists('rules_config', 'dirty')) {
407
    db_add_field('rules_config', 'dirty', array(
408
      'type' => 'int',
409
      'not null' => TRUE,
410
      'default' => 0,
411
      'size' => 'tiny',
412
    ));
413
  }
414
}
415

    
416
/**
417
 * Flush all caches.
418
 */
419
function rules_update_7206() {
420
  // The update system is going to flush all caches anyway, so nothing to do.
421
}
422

    
423
/**
424
 * Flush all caches.
425
 */
426
function rules_update_7207() {
427
  // The update system is going to flush all caches anyway, so nothing to do.
428
}
429

    
430
/**
431
 * Flush all caches to update the data_is_empty condition info.
432
 */
433
function rules_update_7208() {
434
  // The update system is going to flush all caches anyway, so nothing to do.
435
}
436

    
437
/**
438
 * Creates a flag that enables a permission for using components.
439
 */
440
function rules_update_7209() {
441
  // Create a access exposed flag column.
442
  db_add_field('rules_config', 'access_exposed', array(
443
    'type' => 'int',
444
    'not null' => TRUE,
445
    'default' => 0,
446
    'size' => 'tiny',
447
    'description' => 'Whether to use a permission to control access for using components.',
448
  ));
449
}
450

    
451
/**
452
 * Deletes the unused rules_empty_sets variable.
453
 */
454
function rules_update_7210() {
455
  variable_del('rules_empty_sets');
456
}
457

    
458
/**
459
 * Creates the "owner" column.
460
 */
461
function rules_update_7211() {
462
  // Create a owner column.
463
  if (!db_field_exists('rules_config', 'owner')) {
464
    db_add_field('rules_config', 'owner', array(
465
      'description' => 'The name of the module via which the rule has been configured.',
466
      'type' => 'varchar',
467
      'length' => 255,
468
      'not null' => TRUE,
469
      'default' => 'rules',
470
    ));
471
  }
472
}
473

    
474
/**
475
 * Make sure registry gets rebuilt to avoid upgrade troubles.
476
 */
477
function rules_update_7212() {
478
  // Make sure module information gets refreshed and registry is rebuilt.
479
  drupal_static_reset('system_rebuild_module_data');
480
  registry_rebuild();
481
}
482

    
483
/**
484
 * Recover the "owner" property for broken configurations.
485
 */
486
function rules_update_7213() {
487
  $rows= db_select('rules_config', 'c')
488
    ->fields('c')
489
    ->condition('status', ENTITY_OVERRIDDEN)
490
    ->condition('owner', 'rules', '<>')
491
    ->execute()
492
    ->fetchAllAssoc('id');
493

    
494
  foreach ($rows as $id => $row) {
495
    if ($row->module == $row->owner) {
496
      db_update('rules_config')
497
        ->condition('id', $id)
498
        ->fields(array('owner' => 'rules'))
499
        ->execute();
500
    }
501
  }
502
}