taxonomy.install 9.44 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
  $schema['taxonomy_term_synonym'] = array(
144
    'description' => 'Stores term synonyms.',
145
    'fields' => array(
146 147 148
      'tsid' => array(
        'type' => 'serial',
        'not null' => TRUE,
149
        'description' => 'Primary Key: Unique term synonym ID.',
150 151 152 153 154 155
      ),
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
156
        'description' => 'The {taxonomy_term_data}.tid of the term.',
157 158 159 160 161 162
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
163
        'description' => 'The name of the synonym.',
164
      ),
165 166
    ),
    'indexes' => array(
167
      'tid' => array('tid'),
168
      'name_tid' => array('name', 'tid'),
169
    ),
170 171 172
    'foreign keys' => array(
      'tid' => array('taxonomy_term_data' => 'tid'),
    ),
173 174 175
    'primary key' => array('tsid'),
  );

176
  $schema['taxonomy_vocabulary'] = array(
177
    'description' => 'Stores vocabulary information.',
178
    'fields' => array(
179 180 181 182
      'vid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
183
        'description' => 'Primary Key: Unique vocabulary ID.',
184 185 186 187 188 189
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
190
        'description' => 'Name of the vocabulary.',
191
      ),
192 193 194 195 196 197 198
      'machine_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The vocabulary machine name.',
      ),
199 200 201 202
      'description' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
203
        'description' => 'Description of the vocabulary.',
204 205 206 207 208 209
      ),
      'help' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
210
        'description' => 'Help text to display for the vocabulary.',
211 212 213 214 215 216 217
      ),
      'relations' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
218
        'description' => 'Whether or not related terms are enabled within the vocabulary. (0 = disabled, 1 = enabled)',
219 220 221 222 223 224 225
      ),
      'hierarchy' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
226
        'description' => 'The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)',
227 228 229 230 231 232 233
      ),
      'multiple' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
234
        'description' => 'Whether or not multiple terms from this vocabulary may be assigned to a node. (0 = disabled, 1 = enabled)',
235 236 237 238 239 240 241
      ),
      'required' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
242
        'description' => 'Whether or not terms are required for nodes using this vocabulary. (0 = disabled, 1 = enabled)',
243 244 245 246 247 248 249
      ),
      'tags' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
250
        'description' => 'Whether or not free tagging is enabled for the vocabulary. (0 = disabled, 1 = enabled)',
251 252 253 254 255 256
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
257
        'description' => 'The module which created the vocabulary.',
258 259 260 261 262 263
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
264
        'description' => 'The weight of the vocabulary in relation to other vocabularies.',
265
      ),
266 267
    ),
    'primary key' => array('vid'),
268 269 270
    'indexes' => array(
      'list' => array('weight', 'name'),
    ),
271 272
  );

273
  $schema['taxonomy_vocabulary_node_type'] = array(
274
    'description' => 'Stores which node types vocabularies may be used with.',
275
    'fields' => array(
276 277 278 279 280
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
281
        'description' => 'Primary Key: the {taxonomy_vocabulary}.vid of the vocabulary.',
282 283 284
      ),
      'type' => array(
        'type' => 'varchar',
285 286
        'length' => 32,
        'not null' => TRUE,
287
        'default' => '',
288
        'description' => 'The {node}.type of the node type for which the vocabulary may be used.',
289
      ),
290
    ),
291 292 293 294
    'primary key' => array('type', 'vid'),
    'indexes' => array(
      'vid' => array('vid'),
    ),
295 296 297
    'foreign keys' => array(
      'vid' => array('taxonomy_vocabulary' => 'vid'),
    ),
298 299 300 301 302
  );

  return $schema;
}

303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
/**
 * 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;
}
328 329 330 331 332 333 334 335 336 337 338 339 340

/**
 * Remove the related terms setting from vocabularies.
 *
 * This setting has not been used since Drupal 6. The {taxonomy_relations} table
 * itself is retained to allow for data to be upgraded.
 */
function taxonomy_update_7003() {
  $ret = array();
  db_drop_field($ret, 'taxonomy_vocabulary', 'relations');

  return $ret;
}