taxonomy.install 10.2 KB
Newer Older
1
2
3
<?php
// $Id$

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

9
 /**
10
 * Implement hook_install().
11
12
13
14
15
16
17
 */
function taxonomy_install() {
  // Create tables.
  drupal_install_schema('taxonomy');
}

/**
18
 * Implement hook_uninstall().
19
20
21
22
 */
function taxonomy_uninstall() {
  // Remove tables.
  drupal_uninstall_schema('taxonomy');
23
24
25
26

  // Remove variables.
  variable_del('taxonomy_override_selector');
  variable_del('taxonomy_terms_per_page_admin');
27
28
}

29
/**
30
 * Implement hook_schema().
31
32
 */
function taxonomy_schema() {
33
  $schema['taxonomy_term_data'] = array(
34
    'description' => 'Stores term information.',
35
    'fields' => array(
36
37
38
39
      'tid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
40
        'description' => 'Primary Key: Unique term ID.',
41
42
43
44
45
46
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
47
        'description' => 'The {taxonomy_vocabulary}.vid of the vocabulary to which the term is assigned.',
48
49
50
51
52
53
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
54
        'description' => 'The term name.',
55
56
57
58
59
      ),
      'description' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
60
        'description' => 'A description of the term.',
61
62
63
64
65
66
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
67
        'description' => 'The weight of this term in relation to other terms.',
68
      ),
69
70
    ),
    'primary key' => array('tid'),
71
72
73
    'foreign keys' => array(
      'vid' => array('taxonomy_vocabulary' => 'vid'),
    ),
74
75
    'indexes' => array(
      'taxonomy_tree' => array('vid', 'weight', 'name'),
76
77
      'vid_name' => array('vid', 'name'),
    ),
78
79
  );

80
  $schema['taxonomy_term_hierarchy'] = array(
81
    'description' => 'Stores the hierarchical relationship between terms.',
82
    'fields' => array(
83
84
85
86
87
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
88
        'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term.',
89
90
91
92
93
94
      ),
      'parent' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
95
        'description' => "Primary Key: The {taxonomy_term_data}.tid of the term's parent. 0 indicates no parent.",
96
      ),
97
98
99
100
    ),
    'indexes' => array(
      'parent' => array('parent'),
    ),
101
102
103
    'foreign keys' => array(
      'tid' => array('taxonomy_term_data' => 'tid'),
    ),
104
105
106
    'primary key' => array('tid', 'parent'),
  );

107
  $schema['taxonomy_term_node'] = array(
108
    'description' => 'Stores the relationship of terms to nodes.',
109
    'fields' => array(
110
111
112
113
114
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
115
        'description' => 'Primary Key: The {node}.nid of the node.',
116
117
118
119
120
121
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
122
        'description' => 'Primary Key: The {node}.vid of the node.',
123
124
125
126
127
128
      ),
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
129
        'description' => 'Primary Key: The {taxonomy_term_data}.tid of a term assigned to the node.',
130
      ),
131
132
    ),
    'indexes' => array(
133
      'vid' => array('vid'),
134
      'nid' => array('nid'),
135
    ),
136
137
138
139
140
    'foreign keys' => array(
      'nid' => array('node' => 'nid'),
      'vid' => array('node' => 'vid'),
      'tid' => array('taxonomy_term_data' => 'tid'),
    ),
141
    'primary key' => array('tid', 'vid'),
142
143
  );

144
  $schema['taxonomy_term_relation'] = array(
145
    'description' => 'Stores non-hierarchical relationships between terms.',
146
    'fields' => array(
147
148
149
      'trid' => array(
        'type' => 'serial',
        'not null' => TRUE,
150
        'description' => 'Primary Key: Unique term relation ID.',
151
152
153
154
155
156
      ),
      'tid1' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
157
        'description' => 'The {taxonomy_term_data}.tid of the first term in a relationship.',
158
159
160
161
162
163
      ),
      'tid2' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
164
        'description' => 'The {taxonomy_term_data}.tid of the second term in a relationship.',
165
      ),
166
    ),
167
168
169
    'unique keys' => array(
      'tid1_tid2' => array('tid1', 'tid2'),
    ),
170
    'indexes' => array(
171
      'tid2' => array('tid2'),
172
    ),
173
174
175
176
    'foreign keys' => array(
      'tid1' => array('taxonomy_term_data' => 'tid'),
      'tid2' => array('taxonomy_term_data' => 'tid'),
    ),
177
178
179
    'primary key' => array('trid'),
  );

180
  $schema['taxonomy_term_synonym'] = array(
181
    'description' => 'Stores term synonyms.',
182
    'fields' => array(
183
184
185
      'tsid' => array(
        'type' => 'serial',
        'not null' => TRUE,
186
        'description' => 'Primary Key: Unique term synonym ID.',
187
188
189
190
191
192
      ),
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
193
        'description' => 'The {taxonomy_term_data}.tid of the term.',
194
195
196
197
198
199
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
200
        'description' => 'The name of the synonym.',
201
      ),
202
203
    ),
    'indexes' => array(
204
      'tid' => array('tid'),
205
      'name_tid' => array('name', 'tid'),
206
    ),
207
208
209
    'foreign keys' => array(
      'tid' => array('taxonomy_term_data' => 'tid'),
    ),
210
211
212
    'primary key' => array('tsid'),
  );

213
  $schema['taxonomy_vocabulary'] = array(
214
    'description' => 'Stores vocabulary information.',
215
    'fields' => array(
216
217
218
219
      'vid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
220
        'description' => 'Primary Key: Unique vocabulary ID.',
221
222
223
224
225
226
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
227
        'description' => 'Name of the vocabulary.',
228
      ),
229
230
231
232
233
234
235
      'machine_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The vocabulary machine name.',
      ),
236
237
238
239
      'description' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
240
        'description' => 'Description of the vocabulary.',
241
242
243
244
245
246
      ),
      'help' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
247
        'description' => 'Help text to display for the vocabulary.',
248
249
250
251
252
253
254
      ),
      'relations' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
255
        'description' => 'Whether or not related terms are enabled within the vocabulary. (0 = disabled, 1 = enabled)',
256
257
258
259
260
261
262
      ),
      'hierarchy' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
263
        'description' => 'The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)',
264
265
266
267
268
269
270
      ),
      'multiple' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
271
        'description' => 'Whether or not multiple terms from this vocabulary may be assigned to a node. (0 = disabled, 1 = enabled)',
272
273
274
275
276
277
278
      ),
      'required' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
279
        'description' => 'Whether or not terms are required for nodes using this vocabulary. (0 = disabled, 1 = enabled)',
280
281
282
283
284
285
286
      ),
      'tags' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
287
        'description' => 'Whether or not free tagging is enabled for the vocabulary. (0 = disabled, 1 = enabled)',
288
289
290
291
292
293
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
294
        'description' => 'The module which created the vocabulary.',
295
296
297
298
299
300
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
301
        'description' => 'The weight of the vocabulary in relation to other vocabularies.',
302
      ),
303
304
    ),
    'primary key' => array('vid'),
305
306
307
    'indexes' => array(
      'list' => array('weight', 'name'),
    ),
308
309
  );

310
  $schema['taxonomy_vocabulary_node_type'] = array(
311
    'description' => 'Stores which node types vocabularies may be used with.',
312
    'fields' => array(
313
314
315
316
317
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
318
        'description' => 'Primary Key: the {taxonomy_vocabulary}.vid of the vocabulary.',
319
320
321
      ),
      'type' => array(
        'type' => 'varchar',
322
323
        'length' => 32,
        'not null' => TRUE,
324
        'default' => '',
325
        'description' => 'The {node}.type of the node type for which the vocabulary may be used.',
326
      ),
327
    ),
328
329
330
331
    'primary key' => array('type', 'vid'),
    'indexes' => array(
      'vid' => array('vid'),
    ),
332
333
334
    'foreign keys' => array(
      'vid' => array('taxonomy_vocabulary' => 'vid'),
    ),
335
336
337
338
339
  );

  return $schema;
}

340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/**
 * Add vocabulary machine_name column.
 */
function taxonomy_update_7002() {
  $ret = array();
  $field = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
    'description' => 'The vocabulary machine name.',
  );

  db_add_field($ret, 'taxonomy_vocabulary', 'machine_name', $field);

  foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
    $machine_name = 'vocabulary_' . $vid;
    db_update('taxonomy_vocabulary')
      ->fields(array('machine_name' => 'vocabulary_' . $vid))
      ->condition('vid', $vid)
      ->execute();
    field_attach_create_bundle($machine_name);
  }
  return $ret;
}