Projet

Général

Profil

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

root / htmltest / sites / all / modules / acl / acl.install @ a5572547

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the acl module.
6
 */
7
8
/**
9
 * Implementation of hook_schema().
10
 */
11
function acl_schema() {
12
  $schema['acl'] = array(
13
    'description'     => 'The base Access Control Lists table.',
14
    'fields'          => array(
15
      'acl_id'        => array(
16
        'description' => 'Primary key: unique ACL ID.',
17
        'type'        => 'serial',
18
        'not null'    => TRUE,
19
      ),
20
      'module'        => array(
21
        'description' => 'The name of the module that created this ACL entry.',
22
        'type'        => 'varchar',
23
        'length'      => 255,
24
        'not null'    => TRUE,
25
      ),
26
      'name'          => array(
27
        'description' => 'A name (or other identifying information) for this ACL entry, given by the module that created it.',
28
        'type'        => 'varchar',
29
        'length'      => 255,
30
      ),
31
      'number'        => array(
32
        'description' => "A number for this ACL entry, given by the module that created it; use either 'name' or 'number'.",
33
        'type'        => 'int',
34
      ),
35
    ),
36
    'primary key'     => array('acl_id'),
37
    'indexes'         => array(
38
      'module_name_number' => array(array('module', 64), array('name', 64), 'number'),
39
      'module_number' => array(array('module', 64), 'number'),
40
    ),
41
  );
42
  $schema['acl_user'] = array(
43
    'description'     => 'Identifies {users} to which the referenced {acl} entry applies.',
44
    'fields'          => array(
45
      'acl_id'        => array(
46
        'description' => 'The {acl}.acl_id of the entry.',
47
        'type'        => 'int',
48
        'not null'    => TRUE,
49
        'default'     => 0,
50
      ),
51
      'uid'           => array(
52
        'description' => 'The {user}.uid to which this {acl} entry applies.',
53
        'type'        => 'int',
54
        'not null'    => TRUE,
55
        'default'     => 0,
56
      ),
57
    ),
58
    'primary key'     => array('acl_id', 'uid'),
59
    'indexes'         => array(
60
      'uid'           => array('uid'),
61
    ),
62
  );
63
  $schema['acl_node'] = array(
64
    'description'     => 'Identifies {node}s to which the referenced {acl} entry applies and defines the permissions granted.',
65
    'fields'          => array(
66
      'acl_id'        => array(
67
        'description' => 'The {acl}.acl_id of the entry.',
68
        'type'        => 'int',
69
        'not null'    => TRUE,
70
        'default'     => 0,
71
      ),
72
      'nid'           => array(
73
        'description' => 'The {node}.nid to grant permissions for.',
74
        'type'        => 'int',
75
        'not null'    => TRUE,
76
        'default'     => 0,
77
      ),
78
      'grant_view'    => array(
79
        'description' => 'Whether to grant "view" permission.',
80
        'type'        => 'int',
81
        'size'        => 'tiny',
82
        'unsigned'    => TRUE,
83
        'not null'    => TRUE,
84
        'default'     => 0,
85
      ),
86
      'grant_update'  => array(
87
        'description' => 'Whether to grant "update" permission.',
88
        'type'        => 'int',
89
        'size'        => 'tiny',
90
        'unsigned'    => TRUE,
91
        'not null'    => TRUE,
92
        'default'     => 0,
93
      ),
94
      'grant_delete'  => array(
95
        'description' => 'Whether to grant "delete" permission.',
96
        'type'        => 'int',
97
        'size'        => 'tiny',
98
        'unsigned'    => TRUE,
99
        'not null'    => TRUE,
100
        'default'     => 0,
101
      ),
102
      'priority'      => array(
103
        'description' => 'The priority of this grant record (for hook_node_access_records()).',
104
        'type'        => 'int',
105
        'size'        => 'small',
106
        'not null'    => TRUE,
107
        'default'     => 0,
108
      ),
109
    ),
110
    'primary key'     => array('acl_id', 'nid'),
111
    'indexes'         => array(
112
      'nid'           => array('nid'),
113
    ),
114
  );
115
  return $schema;
116
}
117
118
119
/**
120
 * Fixes primary keys
121
 */
122
function acl_update_2() {
123
  $ret = array();
124
  // drop the previously created indexes (except for acl_user.uid)
125
  db_drop_index($ret, 'acl', 'acl_id');
126
  db_drop_index($ret, 'acl_user', 'acl_id');
127
  db_drop_index($ret, 'acl_node', 'acl_id');
128
  db_drop_index($ret, 'acl_node', 'nid');
129
  // create new indexes (as primary keys this time)
130
  db_add_primary_key($ret, 'acl', array('acl_id'));
131
  db_add_primary_key($ret, 'acl_user', array('acl_id', 'uid'));
132
  db_add_primary_key($ret, 'acl_node', array('acl_id', 'nid'));
133
  return $ret;
134
}
135
136
/**
137
 * Put back acl_node(nid) index for deleting nodes and clean up {acl_node}.
138
 */
139
function acl_update_4() {
140
  $ret = array();
141
  db_add_index($ret, 'acl_node', 'nid', array('nid'));
142
  $ret[] = update_sql("DELETE FROM {acl_node} WHERE nid NOT IN (SELECT nid FROM {node})");
143
  return $ret;
144
}
145
146
/**
147
 * Clean up {acl_user}.
148
 */
149
function acl_update_5() {
150
  $ret = array();
151
  $ret[] = update_sql("DELETE FROM {acl_user} WHERE uid NOT IN (SELECT uid FROM {users})");
152
  return $ret;
153
}
154
155
/**
156
 * Add 'priority' column.
157
 */
158
function acl_update_6() {
159
  $ret = array();
160
  db_add_field($ret, 'acl_node', 'priority', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
161
  return $ret;
162
}
163
164
/**
165
 * Change acl_id to auto-increment.
166
 */
167
function acl_update_6000() {
168
  $ret = array();
169
  db_change_field($ret, 'acl', 'acl_id', 'acl_id', array('type' => 'serial', 'not null' => TRUE));
170
  // (Dropping and recreating the primary key on an auto_increment column would cause a MySQL failure.)
171
  db_change_field($ret, 'acl', 'module', 'module', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
172
  db_change_field($ret, 'acl', 'name', 'name', array('type' => 'varchar', 'length' => 255));
173
  db_add_index($ret, 'acl_node', 'nid', array('nid'));
174
  return $ret;
175
}
176
177
/**
178
 * Add index that should have been added when upgrading from D5.
179
 */
180
function acl_update_6001() {
181
  $ret = array();
182
  @db_add_index($ret, 'acl_node', 'nid', array('nid'));
183
  return ($ret['success'] ? $ret : array()); // ignore possible error, if the index already exists
184
}
185
186
/**
187
 * Add 'number' column if it's not there yet.
188
 */
189
function acl_update_7000() {
190
  if (!db_field_exists('acl', 'number')) {
191
    db_add_field('acl', 'number', array('type' => 'int', 'description' => "A number for this ACL entry, given by the module that created it; use either 'name' or 'number'."));
192
  }
193
}
194
195
/**
196
 * Install better indexes.
197
 */
198
function acl_update_7001() {
199
  if (db_index_exists('acl', 'name')) {
200
    db_drop_index('acl', 'name');
201
  }
202
  if (!db_index_exists('acl', 'module_name_number')) {
203
    db_add_index('acl', 'module_name_number', array(array('module', 64), array('name', 64), 'number'));
204
  }
205
  if (db_index_exists('acl', 'number')) {
206
    db_drop_index('acl', 'number');
207
  }
208
  if (!db_index_exists('acl', 'module_number')) {
209
    db_add_index('acl', 'module_number', array(array('module', 64), 'number'));
210
  }
211
}