/[drupal]/drupal/modules/taxonomy/taxonomy.install
ViewVC logotype

Contents of /drupal/modules/taxonomy/taxonomy.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.28 - (show annotations) (download) (as text)
Sat Nov 7 14:18:07 2009 UTC (3 weeks ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.27: +22 -1 lines
File MIME type: text/x-php
#625460 by sun: Add input format to taxonomy term descriptions.
1 <?php
2 // $Id: taxonomy.install,v 1.27 2009/10/16 19:06:24 dries Exp $
3
4 /**
5 * @file
6 * Install, update and uninstall functions for the taxonomy module.
7 */
8
9 /**
10 * Implement hook_uninstall().
11 */
12 function taxonomy_uninstall() {
13 // Remove variables.
14 variable_del('taxonomy_override_selector');
15 variable_del('taxonomy_terms_per_page_admin');
16 }
17
18 /**
19 * Implement hook_schema().
20 */
21 function taxonomy_schema() {
22 $schema['taxonomy_term_data'] = array(
23 'description' => 'Stores term information.',
24 'fields' => array(
25 'tid' => array(
26 'type' => 'serial',
27 'unsigned' => TRUE,
28 'not null' => TRUE,
29 'description' => 'Primary Key: Unique term ID.',
30 ),
31 'vid' => array(
32 'type' => 'int',
33 'unsigned' => TRUE,
34 'not null' => TRUE,
35 'default' => 0,
36 'description' => 'The {taxonomy_vocabulary}.vid of the vocabulary to which the term is assigned.',
37 ),
38 'name' => array(
39 'type' => 'varchar',
40 'length' => 255,
41 'not null' => TRUE,
42 'default' => '',
43 'description' => 'The term name.',
44 'translatable' => TRUE,
45 ),
46 'description' => array(
47 'type' => 'text',
48 'not null' => FALSE,
49 'size' => 'big',
50 'description' => 'A description of the term.',
51 'translatable' => TRUE,
52 ),
53 'format' => array(
54 'type' => 'int',
55 'size' => 'small',
56 'not null' => TRUE,
57 'default' => 0,
58 'description' => 'The {filter_format}.format of the description.',
59 ),
60 'weight' => array(
61 'type' => 'int',
62 'not null' => TRUE,
63 'default' => 0,
64 'size' => 'tiny',
65 'description' => 'The weight of this term in relation to other terms.',
66 ),
67 ),
68 'primary key' => array('tid'),
69 'foreign keys' => array(
70 'vid' => array('taxonomy_vocabulary' => 'vid'),
71 ),
72 'indexes' => array(
73 'taxonomy_tree' => array('vid', 'weight', 'name'),
74 'vid_name' => array('vid', 'name'),
75 ),
76 );
77
78 $schema['taxonomy_term_hierarchy'] = array(
79 'description' => 'Stores the hierarchical relationship between terms.',
80 'fields' => array(
81 'tid' => array(
82 'type' => 'int',
83 'unsigned' => TRUE,
84 'not null' => TRUE,
85 'default' => 0,
86 'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term.',
87 ),
88 'parent' => array(
89 'type' => 'int',
90 'unsigned' => TRUE,
91 'not null' => TRUE,
92 'default' => 0,
93 'description' => "Primary Key: The {taxonomy_term_data}.tid of the term's parent. 0 indicates no parent.",
94 ),
95 ),
96 'indexes' => array(
97 'parent' => array('parent'),
98 ),
99 'foreign keys' => array(
100 'tid' => array('taxonomy_term_data' => 'tid'),
101 ),
102 'primary key' => array('tid', 'parent'),
103 );
104
105 $schema['taxonomy_vocabulary'] = array(
106 'description' => 'Stores vocabulary information.',
107 'fields' => array(
108 'vid' => array(
109 'type' => 'serial',
110 'unsigned' => TRUE,
111 'not null' => TRUE,
112 'description' => 'Primary Key: Unique vocabulary ID.',
113 ),
114 'name' => array(
115 'type' => 'varchar',
116 'length' => 255,
117 'not null' => TRUE,
118 'default' => '',
119 'description' => 'Name of the vocabulary.',
120 'translatable' => TRUE,
121 ),
122 'machine_name' => array(
123 'type' => 'varchar',
124 'length' => 255,
125 'not null' => TRUE,
126 'default' => '',
127 'description' => 'The vocabulary machine name.',
128 ),
129 'description' => array(
130 'type' => 'text',
131 'not null' => FALSE,
132 'size' => 'big',
133 'description' => 'Description of the vocabulary.',
134 'translatable' => TRUE,
135 ),
136 'relations' => array(
137 'type' => 'int',
138 'unsigned' => TRUE,
139 'not null' => TRUE,
140 'default' => 0,
141 'size' => 'tiny',
142 'description' => 'Whether or not related terms are enabled within the vocabulary. (0 = disabled, 1 = enabled)',
143 ),
144 'hierarchy' => array(
145 'type' => 'int',
146 'unsigned' => TRUE,
147 'not null' => TRUE,
148 'default' => 0,
149 'size' => 'tiny',
150 'description' => 'The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)',
151 ),
152 'module' => array(
153 'type' => 'varchar',
154 'length' => 255,
155 'not null' => TRUE,
156 'default' => '',
157 'description' => 'The module which created the vocabulary.',
158 ),
159 'weight' => array(
160 'type' => 'int',
161 'not null' => TRUE,
162 'default' => 0,
163 'size' => 'tiny',
164 'description' => 'The weight of this vocabulary in relation to other vocabularies.',
165 ),
166 ),
167 'primary key' => array('vid'),
168 'indexes' => array(
169 'list' => array('weight', 'name'),
170 ),
171 );
172
173 $schema['taxonomy_index'] = array(
174 'description' => 'Maintains denormalized information about node/term relationships.',
175 'fields' => array(
176 'nid' => array(
177 'description' => 'The {node}.nid this record tracks.',
178 'type' => 'int',
179 'unsigned' => TRUE,
180 'not null' => TRUE,
181 'default' => 0,
182 ),
183 'tid' => array(
184 'description' => 'The term ID.',
185 'type' => 'int',
186 'unsigned' => TRUE,
187 'not null' => TRUE,
188 'default' => 0,
189 ),
190 'sticky' => array(
191 'description' => 'Boolean indicating whether the node is sticky.',
192 'type' => 'int',
193 'not null' => FALSE,
194 'default' => 0,
195 'size' => 'tiny',
196 ),
197 'created' => array(
198 'description' => 'The Unix timestamp when the node was created.',
199 'type' => 'int',
200 'unsigned' => TRUE,
201 'not null' => TRUE,
202 'default'=> 0,
203 ),
204 ),
205 'indexes' => array(
206 'term_node' => array('tid', 'sticky', 'created'),
207 ),
208 'foreign keys' => array(
209 'node' => 'nid',
210 'taxonomy_term_data' => 'tid',
211 ),
212 );
213
214 return $schema;
215 }
216
217 /**
218 * Add vocabulary machine_name column.
219 */
220 function taxonomy_update_7002() {
221 $field = array(
222 'type' => 'varchar',
223 'length' => 255,
224 'not null' => TRUE,
225 'default' => '',
226 'description' => 'The vocabulary machine name.',
227 );
228
229 db_add_field('taxonomy_vocabulary', 'machine_name', $field);
230
231 foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
232 $machine_name = 'vocabulary_' . $vid;
233 db_update('taxonomy_vocabulary')
234 ->fields(array('machine_name' => 'vocabulary_' . $vid))
235 ->condition('vid', $vid)
236 ->execute();
237 field_attach_create_bundle('taxonomy_term', $machine_name);
238 }
239 }
240
241 /**
242 * Remove the related terms setting from vocabularies.
243 *
244 * This setting has not been used since Drupal 6. The {taxonomy_relations} table
245 * itself is retained to allow for data to be upgraded.
246 */
247 function taxonomy_update_7003() {
248 db_drop_field('taxonomy_vocabulary', 'relations');
249 }
250
251 /**
252 * Move taxonomy vocabulary associations for nodes to fields and field instances.
253 */
254 function taxonomy_update_7004() {
255 $taxonomy_index = array(
256 'description' => 'Maintains denormalized information about node/term relationships.',
257 'fields' => array(
258 'nid' => array(
259 'description' => 'The {node}.nid this record tracks.',
260 'type' => 'int',
261 'unsigned' => TRUE,
262 'not null' => TRUE,
263 'default' => 0,
264 ),
265 'tid' => array(
266 'description' => 'The term ID.',
267 'type' => 'int',
268 'unsigned' => TRUE,
269 'not null' => TRUE,
270 'default' => 0,
271 ),
272 'sticky' => array(
273 'description' => 'Boolean indicating whether the node is sticky.',
274 'type' => 'int',
275 'not null' => FALSE,
276 'default' => 0,
277 'size' => 'tiny',
278 ),
279 'created' => array(
280 'description' => 'The Unix timestamp when the node was created.',
281 'type' => 'int',
282 'unsigned' => TRUE,
283 'not null' => TRUE,
284 'default'=> 0,
285 ),
286 ),
287 'indexes' => array(
288 'term_node' => array('tid', 'sticky', 'created'),
289 ),
290 'foreign keys' => array(
291 'node' => 'nid',
292 'taxonomy_term_data' => 'tid',
293 ),
294 );
295 db_create_table('taxonomy_index', $taxonomy_index);
296
297 // Use an inline version of Drupal 6 taxonomy_get_vocabularies() here since
298 // we can no longer rely on $vocabulary->nodes from the API function.
299 $result = db_query('SELECT v.*, n.type FROM {taxonomy_vocabulary} v LEFT JOIN {taxonomy_vocabulary_node_type} n ON v.vid = n.vid ORDER BY v.weight, v.name');
300 $vocabularies = array();
301 foreach ($result as $record) {
302 // If no node types are associated with a vocabulary, the LEFT JOIN will
303 // return a NULL value for type.
304 if (isset($record->type)) {
305 $node_types[$record->vid][$record->type] = $record->type;
306 unset($record->type);
307 $record->nodes = $node_types[$record->vid];
308 }
309 elseif (!isset($record->nodes)) {
310 $record->nodes = array();
311 }
312 $vocabularies[$record->vid] = $record;
313 }
314
315 foreach ($vocabularies as $vocabulary) {
316 $field_name = 'taxonomy_' . $vocabulary->machine_name;
317 $field = array(
318 'field_name' => $field_name,
319 'type' => 'taxonomy_term',
320 'cardinality' => $vocabulary->multiple || $vocabulary->tags ? FIELD_CARDINALITY_UNLIMITED : 1,
321 'settings' => array(
322 'required' => $vocabulary->required ? TRUE : FALSE,
323 'allowed_values' => array(
324 array(
325 'vid' => $vocabulary->vid,
326 'parent' => 0,
327 ),
328 ),
329 ),
330 );
331 field_create_field($field);
332
333 foreach ($vocabulary->nodes as $bundle) {
334 $instance = array(
335 'label' => $vocabulary->name,
336 'field_name' => $field_name,
337 'bundle' => $bundle,
338 'description' => $vocabulary->help,
339 'widget' => array(
340 'type' => $vocabulary->tags ? 'taxonomy_autocomplete' : 'select',
341 ),
342 );
343 field_create_instance($instance);
344 }
345 }
346 db_drop_table('taxonomy_vocabulary_node_type');
347 $fields = array('help', 'multiple', 'required', 'tags');
348 foreach ($fields as $field) {
349 db_drop_field('taxonomy_vocabulary', $field);
350 }
351 }
352
353 /**
354 * Migrate {taxonomy_term_node} table to field storage.
355 */
356 function taxonomy_update_7005(&$sandbox) {
357 // Since we are upgrading from Drupal 6, we know that only
358 // field_sql_storage.module will be enabled.
359 $field = field_info_field($field['field_name']);
360 $data_table = _field_sql_storage_tablename($field);
361 $revision_table = _field_sql_storage_revision_tablename($field);
362 $etid = _field_sql_storage_etid('node');
363 $value_column = $field['field_name'] . '_value';
364 $columns = array('etid', 'entity_id', 'revision_id', 'bundle', 'delta', $value_column);
365
366 // This is a multi-pass update. On the first call we need to initialize some
367 // variables.
368 if (!isset($sandbox['total'])) {
369 $sandbox['last'] = 0;
370 $sandbox['count'] = 0;
371
372 $query = db_select('taxonomy_term_node', 't');
373 $sandbox['total'] = $query->countQuery()->execute()->fetchField();
374 $found = (bool) $sandbox['total'];
375 }
376 else {
377 // We do each pass in batches of 1000, this should result in a
378 // maximum of 2000 insert queries each operation.
379 $batch = 1000 + $sandbox['last'];
380
381 // Query and save data for the current revision.
382 $result = db_query_range('SELECT td.tid, tn.nid, td.weight, tn.vid, n2.type, n2.created, n2.sticky FROM {taxonomy_term_data} td INNER JOIN {taxonomy_term_node} tn ON td.tid = tn.tid INNER JOIN {node} n2 ON tn.nid = n2.nid INNER JOIN {node} n ON tn.vid = n.vid AND td.vid = :vocabulary_id ORDER BY td.weight ASC', array(':vocabulary_id' => $vocabulary->vid), $sandbox['last'], $batch);
383 $deltas = array();
384 foreach ($result as $record) {
385 $found = TRUE;
386 $sandbox['count'] += 1;
387 // Start deltas from 0, and increment by one for each
388 // term attached to a node.
389 $deltas[$record->nid] = isset($deltas[$record->nid]) ? ++$deltas[$record->nid] : 0;
390 $values = array($etid, $record->nid, $record->vid, $record->type, $deltas[$record->nid], $record->tid);
391 db_insert($data_table)->fields($columns)->values($values)->execute();
392
393 // Update the {taxonomy_index} table.
394 db_insert('taxonomy_index')
395 ->fields(array('nid', 'tid', 'sticky', 'created',))
396 ->values(array($record->nid, $record->tid, $record->sticky, $record->created))
397 ->execute();
398 }
399
400 // Query and save data for all revisions.
401 $result = db_query('SELECT td.tid, tn.nid, td.weight, tn.vid, n.type FROM {taxonomy_term_data} td INNER JOIN {taxonomy_term_node} tn ON td.tid = tn.tid AND td.vid = :vocabulary_id INNER JOIN {node} n ON tn.nid = n.nid ORDER BY td.weight ASC', array(':vocabulary_id' => $vocabulary->vid), $sandbox['last'][$batch]);
402 $deltas = array();
403 foreach ($result as $record) {
404 $found = TRUE;
405 $sandbox['count'] += 1;
406 // Start deltas at 0, and increment by one for each term attached to a revision.
407 $deltas[$record->vid] = isset($deltas[$record->vid]) ? ++$deltas[$record->vid] : 0;
408 $values = array($etid, $record->nid, $record->vid, $record->type, $deltas[$record->vid], $record->tid);
409 db_insert($revision_table)->fields($columns)->values($values)->execute();
410 }
411 $sandbox['last'] = $batch;
412 }
413 if (!$found) {
414 db_drop_table('taxonomy_term_node');
415 }
416 }
417
418 /**
419 * Add vocabulary machine_name column.
420 */
421 function taxonomy_update_7006() {
422 db_add_field('taxonomy_term_data', 'format', array(
423 'type' => 'int',
424 'size' => 'small',
425 'not null' => TRUE,
426 'default' => 0,
427 'description' => 'The {filter_format}.format of the description.',
428 ));
429 }
430

  ViewVC Help
Powered by ViewVC 1.1.2