Projet

Général

Profil

Paste
Télécharger (3,52 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / trigger / trigger.install @ db2d93dd

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the trigger module.
6
 */
7

    
8
/**
9
 * Implements hook_schema().
10
 */
11
function trigger_schema() {
12
  // The total index length (hook and aid) must be less than 333. Since the aid
13
  // field is 255 characters, the hook field can have a maximum length of 78.
14
  $schema['trigger_assignments'] = array(
15
    'description' => 'Maps trigger to hook and operation assignments from trigger.module.',
16
    'fields' => array(
17
      'hook' => array(
18
        'type' => 'varchar',
19
        'length' => 78,
20
        'not null' => TRUE,
21
        'default' => '',
22
        'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.',
23
      ),
24
      'aid' => array(
25
        'type' => 'varchar',
26
        'length' => 255,
27
        'not null' => TRUE,
28
        'default' => '',
29
        'description' => "Primary Key: Action's {actions}.aid.",
30
      ),
31
      'weight' => array(
32
        'type' => 'int',
33
        'not null' => TRUE,
34
        'default' => 0,
35
        'description' => 'The weight of the trigger assignment in relation to other triggers.',
36
      ),
37
    ),
38
    'primary key' => array('hook', 'aid'),
39
    'foreign keys' => array(
40
      'action' => array(
41
        'table' => 'actions',
42
        'columns' => array('aid' => 'aid'),
43
      ),
44
    ),
45
  );
46
  return $schema;
47
}
48

    
49
/**
50
 * Implements hook_install().
51
 */
52
function trigger_install() {
53
  // Do initial synchronization of actions in code and the database.
54
  actions_synchronize();
55
}
56

    
57
/**
58
 * Alter the "hook" field and drop the "op field" of {trigger_assignments}.
59
 *
60
 * Increase the length of the "hook" field to 78 characters and adds operation
61
 * names to the hook names, and drops the "op" field.
62
 */
63
function trigger_update_7000() {
64
  db_drop_primary_key('trigger_assignments');
65
  db_change_field('trigger_assignments', 'hook', 'hook', array('type' => 'varchar', 'length' => 78, 'not null' => TRUE, 'default' => '', 'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.'));
66

    
67
  $result = db_query("SELECT hook, op, aid FROM {trigger_assignments} WHERE op <> ''");
68

    
69
  foreach ($result as $record) {
70
    db_update('trigger_assignments')
71
      ->fields(array('hook' => $record->hook . '_' . $record->op))
72
      ->condition('hook', $record->hook)
73
      ->condition('op', $record->op)
74
      ->condition('aid', $record->aid)
75
      ->execute();
76
  }
77
  db_drop_field('trigger_assignments', 'op');
78

    
79
  db_add_primary_key('trigger_assignments', array('hook', 'aid'));
80
}
81

    
82
/**
83
 * @addtogroup updates-7.x-extra
84
 * @{
85
 */
86

    
87
/**
88
 * Increase the length of the "hook" field to 78 characters.
89
 *
90
 * This is a separate function for those who ran an older version of
91
 * trigger_update_7000() that did not do this.
92
 */
93
function trigger_update_7001() {
94
  db_drop_primary_key('trigger_assignments');
95
  db_change_field('trigger_assignments', 'hook', 'hook', array('type' => 'varchar', 'length' => 78, 'not null' => TRUE, 'default' => '', 'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.', ), array('primary key' => array('hook', 'aid')));
96
}
97

    
98
/**
99
 * Renames nodeapi to node.
100
 */
101
function trigger_update_7002() {
102
  $result = db_query("SELECT hook, aid FROM {trigger_assignments}");
103

    
104
  foreach($result as $record) {
105
    $new_hook = str_replace('nodeapi', 'node', $record->hook);
106
    db_update('trigger_assignments')
107
      ->fields(array('hook' => $new_hook))
108
      ->condition('hook', $record->hook)
109
      ->condition('aid', $record->aid)
110
      ->execute();
111
  }
112
}
113

    
114
/**
115
 * @} End of "addtogroup updates-7.x-extra".
116
 */