summaryrefslogtreecommitdiff
path: root/modules/trigger/trigger.install
blob: b8553e48c7a76567377b475150f5c3c7e3fe0607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// $Id$

/**
 * @file
 * Install, update and uninstall functions for the trigger module.
 */

/**
 * Implement hook_install().
 */
function trigger_install() {
  // Do initial synchronization of actions in code and the database.
  actions_synchronize();
}

/**
 * Implement hook_schema().
 */
function trigger_schema() {
  $schema['trigger_assignments'] = array(
    'description' => 'Maps trigger to hook and operation assignments from trigger.module.',
    'fields' => array(
      'hook' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.',
      ),
      'aid' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => "Primary Key: Action's {actions}.aid.",
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The weight of the trigger assignment in relation to other triggers.',
      ),
    ),
    'primary key' => array('hook', 'aid'),
    'foreign keys' => array(
      'aid' => array('actions' => 'aid'),
    ),
  );
  return $schema;
}

/**
 * Adds operation names to the hook names and drops the "op" field.
 */
function trigger_update_7000() {
  $ret = array();
  $result = db_query("SELECT hook, op, aid FROM {trigger_assignments} WHERE op <> ''");

  while ($row = db_fetch_object($result)) {
    $ret[] = update_sql("UPDATE {trigger_assignments} SET hook = '%s' WHERE hook = '%s' AND op = '%s' AND aid = '%s'", $row->hook . '_' . $row->op, $row->hook, $row->op, $row->aid);
  }
  $ret[] = update_sql("ALTER TABLE {trigger_assignments} DROP op");

  return $ret;
}