/[drupal]/contributions/modules/category/category.install
ViewVC logotype

Contents of /contributions/modules/category/category.install

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


Revision 1.24 - (show annotations) (download) (as text)
Wed Aug 5 04:58:56 2009 UTC (3 months, 3 weeks ago) by jaza
Branch: MAIN
CVS Tags: DRUPAL-6--2-0-RC1, HEAD
Changes since 1.23: +1 -21 lines
File MIME type: text/x-php
Rollback #523492 by schildi: write a hook_uninstall for category (this was written for the D5 branch of category, which is currently unmaintained).
1 <?php
2 // $Id: category.install,v 1.23 2009/08/05 04:56:27 jaza Exp $
3
4 /**
5 * @file
6 * Installation and update file for the category and related modules. All
7 * functions in this file are implementations of hook_update_N(), unless
8 * indicated otherwise.
9 */
10
11 /**
12 * Implementation of hook_install().
13 */
14 function category_install() {
15 drupal_install_schema('category');
16 $info = _category_default_node_types();
17
18 node_type_save($info['category']);
19 node_type_save($info['container']);
20
21 // Default category and container nodes to not be promoted and have comments
22 // disabled.
23 variable_set('node_options_category', array('status'));
24 variable_set('comment_category', COMMENT_NODE_DISABLED);
25 variable_set('node_options_container', array('status'));
26 variable_set('comment_container', COMMENT_NODE_DISABLED);
27
28 // Don't display date and author information for category and container nodes
29 // by default.
30 $theme_settings = variable_get('theme_settings', array());
31 $theme_settings['toggle_node_info_category'] = FALSE;
32 $theme_settings['toggle_node_info_container'] = FALSE;
33 variable_set('theme_settings', $theme_settings);
34
35 variable_set('category_behavior_category', 'category');
36 variable_set('category_behavior_container', 'container');
37 }
38
39 /**
40 * Implementation of hook_uninstall().
41 */
42 function category_uninstall() {
43 drupal_uninstall_schema('category');
44
45 foreach (node_get_types() as $type) {
46 variable_del('category_behavior_'. $type->type);
47 variable_del('category_allowed_containers_'. $type->type);
48 }
49
50 node_type_delete($info['category']);
51 node_type_delete($info['container']);
52 }
53
54 /**
55 * Get Category's built in node types.
56 * Internal.
57 */
58 function _category_default_node_types() {
59 $types = array(
60 'category' => array(
61 'type' => 'category',
62 'name' => t('Category'),
63 'module' => 'node',
64 'description' => t("A <em>category</em> is used to structure your site, and to categorize content. You can create a category as the child of a container, or of another category. You can assign content to one or more categories."),
65 'title_label' => t('Name'),
66 'body_label' => t('Description'),
67 'custom' => TRUE,
68 'modified' => TRUE,
69 'locked' => FALSE,
70 'help' => '',
71 'min_word_count' => '',
72 ),
73 'container' => array(
74 'type' => 'container',
75 'name' => st('Container'),
76 'module' => 'node',
77 'description' => t('A <em>container</em> is usually the root of a category tree, but can also be created as the child of another container, or of a category. Containers are used for describing a particular way of classifying content.'),
78 'title_label' => t('Name'),
79 'body_label' => t('Description'),
80 'custom' => TRUE,
81 'modified' => TRUE,
82 'locked' => FALSE,
83 'help' => '',
84 'min_word_count' => '',
85 ),
86 );
87
88 foreach (array_keys($types) as $key) {
89 $types[$key] = (object) _node_type_set_defaults($types[$key]);
90 }
91
92 return $types;
93 }
94
95 /**
96 * Implementation of hook_schema().
97 */
98 function category_schema() {
99 $schema['category'] = array(
100 'description' => 'Stores category information.',
101 'fields' => array(
102 'cid' => array(
103 'type' => 'int',
104 'unsigned' => TRUE,
105 'not null' => TRUE,
106 'default' => 0,
107 'description' => "Primary key: The category's {node}.nid.",
108 ),
109 'cnid' => array(
110 'type' => 'int',
111 'unsigned' => TRUE,
112 'not null' => TRUE,
113 'default' => 0,
114 'description' => 'The {category_cont}.cid of the container to which the category is assigned. (0 = category is a container)',
115 ),
116 'weight' => array(
117 'type' => 'int',
118 'not null' => TRUE,
119 'default' => 0,
120 'size' => 'tiny',
121 'description' => 'The weight of this category in relation to other categories.',
122 ),
123 'depth' => array(
124 'type' => 'int',
125 'not null' => TRUE,
126 'default' => 0,
127 'size' => 'tiny',
128 'description' => 'The depth of child categories that are reflected in node listings for this category.',
129 ),
130 ),
131 'primary key' => array('cid'),
132 'indexes' => array(
133 'cnid' => array('cnid'),
134 'weight' => array('weight'),
135 ),
136 );
137
138 $schema['category_hierarchy'] = array(
139 'description' => 'Stores the hierarchical relationship between categories.',
140 'fields' => array(
141 'cid' => array(
142 'type' => 'int',
143 'unsigned' => TRUE,
144 'not null' => TRUE,
145 'default' => 0,
146 'description' => 'Primary Key: The {category}.cid of the category.',
147 ),
148 'parent' => array(
149 'type' => 'int',
150 'unsigned' => TRUE,
151 'not null' => TRUE,
152 'default' => 0,
153 'description' => "Primary Key: The {category}.cid of the category's parent. 0 indicates no parent.",
154 ),
155 ),
156 'primary key' => array('cid', 'parent'),
157 'indexes' => array(
158 'parent' => array('parent'),
159 ),
160 );
161
162 $schema['category_node'] = array(
163 'description' => 'Stores the relationship of categories to nodes.',
164 'fields' => array(
165 'nid' => array(
166 'type' => 'int',
167 'unsigned' => TRUE,
168 'not null' => TRUE,
169 'default' => 0,
170 'description' => 'The {node}.nid of the node.',
171 ),
172 'vid' => array(
173 'type' => 'int',
174 'unsigned' => TRUE,
175 'not null' => TRUE,
176 'default' => 0,
177 'description' => 'Primary Key: The {node}.vid of the node.',
178 ),
179 'cid' => array(
180 'type' => 'int',
181 'unsigned' => TRUE,
182 'not null' => TRUE,
183 'default' => 0,
184 'description' => 'Primary Key: The {category}.cid of a category assigned to the node.',
185 ),
186 ),
187 'primary key' => array('cid', 'vid'),
188 'indexes' => array(
189 'vid' => array('vid'),
190 'nid' => array('nid'),
191 ),
192 );
193
194 $schema['category_relation'] = array(
195 'description' => 'Stores non-hierarchical relationships between categories.',
196 'fields' => array(
197 'crid' => array(
198 'type' => 'serial',
199 'not null' => TRUE,
200 'description' => 'Primary Key: Unique category relation ID.',
201 ),
202 'cid1' => array(
203 'type' => 'int',
204 'unsigned' => TRUE,
205 'not null' => TRUE,
206 'default' => 0,
207 'description' => 'The {category}.cid of the first category in a relationship.',
208 ),
209 'cid2' => array(
210 'type' => 'int',
211 'unsigned' => TRUE,
212 'not null' => TRUE,
213 'default' => 0,
214 'description' => 'The {category}.cid of the second category in a relationship.',
215 ),
216 ),
217 'primary key' => array('crid'),
218 'unique keys' => array(
219 'cid1_cid2' => array('cid1', 'cid2'),
220 ),
221 'indexes' => array(
222 'cid2' => array('cid2'),
223 ),
224 );
225
226 $schema['category_synonym'] = array(
227 'description' => 'Stores category synonyms.',
228 'fields' => array(
229 'csid' => array(
230 'type' => 'serial',
231 'not null' => TRUE,
232 'description' => 'Primary Key: Unique category synonym ID.',
233 ),
234 'cid' => array(
235 'type' => 'int',
236 'unsigned' => TRUE,
237 'not null' => TRUE,
238 'default' => 0,
239 'description' => 'The {category}.cid of the category.',
240 ),
241 'name' => array(
242 'type' => 'varchar',
243 'length' => 255,
244 'not null' => TRUE,
245 'default' => '',
246 'description' => 'The name of the synonym.',
247 ),
248 ),
249 'primary key' => array('csid'),
250 'indexes' => array(
251 'cid' => array('cid'),
252 'name_cid' => array('name', 'cid'),
253 ),
254 );
255
256 $schema['category_cont'] = array(
257 'description' => 'Stores container information.',
258 'fields' => array(
259 'cid' => array(
260 'type' => 'int',
261 'unsigned' => TRUE,
262 'not null' => TRUE,
263 'default' => 0,
264 'description' => 'Primary Key: The {category}.cid of the container.',
265 ),
266 'admin_title' => array(
267 'type' => 'varchar',
268 'length' => 255,
269 'not null' => TRUE,
270 'default' => '',
271 'description' => 'Title of the container for administrative purposes.',
272 ),
273 'help' => array(
274 'type' => 'varchar',
275 'length' => 255,
276 'not null' => TRUE,
277 'default' => '',
278 'description' => 'Help text to display for the container.',
279 ),
280 'module' => array(
281 'type' => 'varchar',
282 'length' => 255,
283 'not null' => TRUE,
284 'default' => '',
285 'description' => 'The module which created the container.',
286 ),
287 'relations' => array(
288 'type' => 'int',
289 'unsigned' => TRUE,
290 'not null' => TRUE,
291 'default' => 0,
292 'size' => 'tiny',
293 'description' => 'Whether or not related categories are enabled within the container. (0 = disabled, 1 = enabled)',
294 ),
295 'synonyms' => array(
296 'type' => 'int',
297 'unsigned' => TRUE,
298 'not null' => TRUE,
299 'default' => 0,
300 'size' => 'tiny',
301 'description' => 'Whether or not synonyms for categories are enabled within the container. (0 = disabled, 1 = enabled)',
302 ),
303 'hierarchy' => array(
304 'type' => 'int',
305 'unsigned' => TRUE,
306 'not null' => TRUE,
307 'default' => 0,
308 'size' => 'tiny',
309 'description' => 'The type of hierarchy allowed within the container. (0 = disabled, 1 = single, 2 = multiple)',
310 ),
311 'multiple' => array(
312 'type' => 'int',
313 'unsigned' => TRUE,
314 'not null' => TRUE,
315 'default' => 0,
316 'size' => 'tiny',
317 'description' => 'Whether or not multiple categories from this container may be assigned to a node. (0 = disabled, 1 = enabled)',
318 ),
319 'required' => array(
320 'type' => 'int',
321 'unsigned' => TRUE,
322 'not null' => TRUE,
323 'default' => 0,
324 'size' => 'tiny',
325 'description' => 'Whether or not categories are required for nodes using this container. (0 = disabled, 1 = enabled)',
326 ),
327 'tags' => array(
328 'type' => 'int',
329 'unsigned' => TRUE,
330 'not null' => TRUE,
331 'default' => 0,
332 'size' => 'tiny',
333 'description' => 'Whether or not free tagging is enabled for the container. (0 = disabled, 1 = enabled)',
334 ),
335 'hidden_cont' => array(
336 'type' => 'int',
337 'unsigned' => TRUE,
338 'not null' => TRUE,
339 'default' => 0,
340 'size' => 'tiny',
341 'description' => 'Whether or not this container is hidden from your category hierarchy for end-users. (0 = disabled, 1 = enabled)',
342 ),
343 'allowed_parent' => array(
344 'type' => 'int',
345 'unsigned' => TRUE,
346 'not null' => TRUE,
347 'default' => 0,
348 'description' => "The {category}.cid of a container whose categories the categories in this container may have as parents. (0 = this container or a category within it is an allowed parent)",
349 ),
350 ),
351 'primary key' => array('cid'),
352 'indexes' => array(
353 'admin_title' => array('admin_title'),
354 'allowed_parent' => array('allowed_parent'),
355 ),
356 );
357
358 $schema['category_cont_node_types'] = array(
359 'description' => "Stores which node types containers may be used with. (I.e. categories in container 'cid' may be used to tag content of type 'type'.)",
360 'fields' => array(
361 'cid' => array(
362 'type' => 'int',
363 'unsigned' => TRUE,
364 'not null' => TRUE,
365 'default' => 0,
366 'description' => 'Primary Key: the {category}.cid of the container.',
367 ),
368 'type' => array(
369 'type' => 'varchar',
370 'length' => 32,
371 'not null' => TRUE,
372 'default' => '',
373 'description' => 'The {node_type}.type of the node type for which the container may be used.',
374 ),
375 ),
376 'primary key' => array('cid', 'type'),
377 'indexes' => array(
378 'cid' => array('cid'),
379 ),
380 );
381
382 $schema['cache_category'] = drupal_get_schema_unprocessed('system', 'cache');
383 $schema['cache_category']['description'] = 'Cache table for category module, to store various preprocessed data, both per-node and global.';
384
385 return $schema;
386 }
387
388 /**
389 * Drupal 6 updates for the category module.
390 */
391 function category_update_6000() {
392 $ret = array();
393
394 db_drop_field($ret, 'category', 'description');
395 db_drop_index($ret, 'category', 'tid');
396 db_add_index($ret, 'category', 'cnid', array('cnid'));
397
398 db_change_field($ret, 'category_cont', 'has_relations', 'relations', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
399 db_change_field($ret, 'category_cont', 'has_synonyms', 'synonyms', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
400 db_add_field($ret, 'category_cont', 'allowed_parent', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
401
402 $result = db_query('SELECT * FROM {category_cont_distant}');
403 while ($distant = db_fetch_object($result)) {
404 if (is_numeric($distant->allowed_parent)) {
405 db_query('UPDATE {category_cont} SET allowed_parent = %d WHERE cid = %d', $distant->allowed_parent, $distant->cid);
406 }
407 }
408
409 db_add_index($ret, 'category_cont', 'admin_title', array('admin_title'));
410 db_add_index($ret, 'category_cont', 'allowed_parent', array('allowed_parent'));
411 db_drop_table($ret, 'category_cont_distant');
412
413 db_add_index($ret, 'category_cont_node_types', 'cid', array('cid'));
414
415 db_drop_index($ret, 'category_hierarchy', 'nid');
416
417 db_drop_primary_key($ret, 'category_node');
418 db_drop_index($ret, 'category_node', 'nid');
419 db_drop_index($ret, 'category_node', 'cid');
420
421 db_add_field($ret, 'category_node', 'vid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
422
423 $ret[] = update_sql('UPDATE {category_node} SET vid = (SELECT vid FROM {node} n WHERE {category_node}.nid = n.nid)');
424
425 db_add_primary_key($ret, 'category_node', array('cid, vid'));
426 db_add_index($ret, 'category_node', 'vid', array('vid'));
427 db_add_index($ret, 'category_node', 'nid', array('nid'));
428
429 db_drop_index($ret, 'category_relation', 'nid1');
430 db_drop_index($ret, 'category_relation', 'nid2');
431 db_add_field($ret, 'category_relation', 'crid', array('type' => 'serial', 'not null' => TRUE), array('primary key' => array('crid')));
432 db_add_index($ret, 'category_relation', 'cid1_cid2', array('cid1', 'cid2'));
433 db_add_index($ret, 'category_relation', 'cid2', array('cid2'));
434
435 db_drop_index($ret, 'category_synonym', 'nid');
436 db_drop_index($ret, 'category_synonym', 'name');
437 db_add_field($ret, 'category_synonym', 'csid', array('type' => 'serial', 'not null' => TRUE), array('primary key' => array('csid')));
438 db_add_index($ret, 'category_synonym', 'cid', array('cid'));
439 db_add_index($ret, 'category_synonym', 'name_cid', array('name', 'cid'));
440
441 $info = _category_default_node_types();
442 node_type_save($info['category']);
443 node_type_save($info['container']);
444 variable_set('category_behavior_category', 'category');
445 variable_set('category_behavior_container', 'container');
446
447 $ret[] = update_sql("UPDATE {node} SET type = 'category' WHERE type = 'category_cat'");
448 $ret[] = update_sql("UPDATE {node} SET type = 'container' WHERE type = 'category_cont'");
449
450 variable_del('category_allow_nodetypes');
451 variable_del('category_base_nodetypes');
452 variable_del('category_distant_containers');
453 variable_del('book_maintain_db');
454 variable_del('taxonomy_maintain_db');
455 variable_del('category_menu_default_menu');
456
457 return $ret;
458 }
459
460 /**
461 * Transfer settings from old content types. This was added after beta 2
462 * release, so avoid changes to new variables possibly already there.
463 */
464 function category_update_6001() {
465 $ret = array();
466
467 $candidates = db_query("SELECT name FROM {variable} WHERE name LIKE '%%\_category\_cat%%' OR name LIKE '%%\_category\_cont%%'");
468 while ($old_name = db_fetch_array($candidates)) {
469 $old_name = $old_name['name'];
470 $new_name = str_replace(array('_category_cat', '_category_cont'), array('_category', '_container'), $old_name);
471 if ($old_name != $new_name) {
472 $old_value = variable_get($old_name, NULL);
473 $new_value = variable_get($new_name, NULL);
474 if (isset($old_value) && !isset($new_value)) {
475 variable_set($new_name, $old_value);
476 $ret[] = array('success' => TRUE, 'query' => "variable_set($new_name)");
477 }
478 variable_del($old_name);
479 $ret[] = array('success' => TRUE, 'query' => "variable_del($old_name)");
480 }
481 }
482 return $ret;
483 }
484
485 /**
486 * Uninstall and remove Menu wrapper module, if present. The wrapper only existed in
487 * 6.x releases 6.x-2.0-beta3 and below.
488 */
489 function category_update_6002() {
490 $ret = array();
491
492 $wrapper_path = drupal_get_path('module', 'category') .'/wrappers/menu';
493 if (is_dir($wrapper_path)) {
494 $success = TRUE;
495 $files = array('menu.admin.inc', 'menu.info', 'menu.info.php', 'menu.install', 'menu.install.php', 'menu.module', 'menu.module.php');
496 foreach ($files as $file) {
497 $filepath = $wrapper_path .'/'. $file;
498 if (is_file($filepath) && !@unlink($filepath)) {
499 $success = FALSE;
500 }
501 }
502 if (!@rmdir($wrapper_path)) {
503 $success = FALSE;
504 }
505
506 drupal_flush_all_caches();
507 module_rebuild_cache();
508
509 if (!$success) {
510 drupal_set_message("The attempt to remove <em>$wrapper_path</em> directory and all it's contents failed. Please ensure that the webserver have write permissions to the <em>wrappers</em> directory and below, and re-run the Category module's update 6002. If that's not possible, you might need to remove the files manually.", 'error');
511 }
512 $ret[] = array('success' => $success, 'query' => "Uninstall Menu wrapper, and remove $wrapper_path directory.");
513 }
514
515 return $ret;
516 }
517
518 /**
519 * Add cache table.
520 */
521 function category_update_6003() {
522 $ret = array();
523
524 // This is verbatim from system module (minus descriptions), to avoid call to
525 // drupal_get_schema_unprocessed() which may change in future, per schema/updates
526 // guidelines.
527 $schema = array(
528 'fields' => array(
529 'cid' => array(
530 'type' => 'varchar',
531 'length' => 255,
532 'not null' => TRUE,
533 'default' => ''),
534 'data' => array(
535 'type' => 'blob',
536 'not null' => FALSE,
537 'size' => 'big'),
538 'expire' => array(
539 'type' => 'int',
540 'not null' => TRUE,
541 'default' => 0),
542 'created' => array(
543 'type' => 'int',
544 'not null' => TRUE,
545 'default' => 0),
546 'headers' => array(
547 'type' => 'text',
548 'not null' => FALSE),
549 'serialized' => array(
550 'type' => 'int',
551 'size' => 'small',
552 'not null' => TRUE,
553 'default' => 0)
554 ),
555 'indexes' => array('expire' => array('expire')),
556 'primary key' => array('cid'),
557 );
558
559 db_create_table($ret, 'cache_category', $schema);
560 return $ret;
561 }

  ViewVC Help
Powered by ViewVC 1.1.2