annotate modules/forum/forum.install @ 5:2427550111ae 6.2

Drupal 6.2
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:30:08 +0100
parents c1f4ac30525a
children fff6d4c8c043
rev   line source
webmaster@1 1 <?php
webmaster@1 2 // $Id: forum.install,v 1.16 2007/12/31 16:58:34 goba Exp $
webmaster@1 3
webmaster@1 4 /**
webmaster@1 5 * Implementation of hook_install().
webmaster@1 6 */
webmaster@1 7 function forum_install() {
webmaster@1 8 // Create tables.
webmaster@1 9 drupal_install_schema('forum');
webmaster@1 10 // Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module.
webmaster@1 11 db_query("UPDATE {system} SET weight = 1 WHERE name = 'forum'");
webmaster@1 12 }
webmaster@1 13
webmaster@1 14 function forum_enable() {
webmaster@1 15 if ($vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0))) {
webmaster@1 16 // Existing install. Add back forum node type, if the forums
webmaster@1 17 // vocabulary still exists. Keep all other node types intact there.
webmaster@1 18 $vocabulary = (array) $vocabulary;
webmaster@1 19 $vocabulary['nodes']['forum'] = 1;
webmaster@1 20 taxonomy_save_vocabulary($vocabulary);
webmaster@1 21 }
webmaster@1 22 else {
webmaster@1 23 // Create the forum vocabulary if it does not exist. Assign the vocabulary
webmaster@1 24 // a low weight so it will appear first in forum topic create and edit
webmaster@1 25 // forms.
webmaster@1 26 $vocabulary = array(
webmaster@1 27 'name' => t('Forums'),
webmaster@1 28 'multiple' => 0,
webmaster@1 29 'required' => 0,
webmaster@1 30 'hierarchy' => 1,
webmaster@1 31 'relations' => 0,
webmaster@1 32 'module' => 'forum',
webmaster@1 33 'weight' => -10,
webmaster@1 34 'nodes' => array('forum' => 1),
webmaster@1 35 );
webmaster@1 36 taxonomy_save_vocabulary($vocabulary);
webmaster@1 37
webmaster@1 38 variable_set('forum_nav_vocabulary', $vocabulary['vid']);
webmaster@1 39 }
webmaster@1 40 }
webmaster@1 41
webmaster@1 42 /**
webmaster@1 43 * Implementation of hook_uninstall().
webmaster@1 44 */
webmaster@1 45 function forum_uninstall() {
webmaster@1 46 // Load the dependent Taxonomy module, in case it has been disabled.
webmaster@1 47 drupal_load('module', 'taxonomy');
webmaster@1 48
webmaster@1 49 // Delete the vocabulary.
webmaster@1 50 $vid = variable_get('forum_nav_vocabulary', '');
webmaster@1 51 taxonomy_del_vocabulary($vid);
webmaster@1 52
webmaster@1 53 db_query("DELETE FROM {node} WHERE type = 'forum'");
webmaster@1 54 db_query('DROP TABLE {forum}');
webmaster@1 55 variable_del('forum_containers');
webmaster@1 56 variable_del('forum_nav_vocabulary');
webmaster@1 57 variable_del('forum_hot_topic');
webmaster@1 58 variable_del('forum_per_page');
webmaster@1 59 variable_del('forum_order');
webmaster@1 60 variable_del('forum_block_num_0');
webmaster@1 61 variable_del('forum_block_num_1');
webmaster@1 62 }
webmaster@1 63
webmaster@1 64 /**
webmaster@1 65 * Implementation of hook_schema().
webmaster@1 66 */
webmaster@1 67 function forum_schema() {
webmaster@1 68 $schema['forum'] = array(
webmaster@1 69 'description' => t('Stores the relationship of nodes to forum terms.'),
webmaster@1 70 'fields' => array(
webmaster@1 71 'nid' => array(
webmaster@1 72 'type' => 'int',
webmaster@1 73 'unsigned' => TRUE,
webmaster@1 74 'not null' => TRUE,
webmaster@1 75 'default' => 0,
webmaster@1 76 'description' => t('The {node}.nid of the node.'),
webmaster@1 77 ),
webmaster@1 78 'vid' => array(
webmaster@1 79 'type' => 'int',
webmaster@1 80 'unsigned' => TRUE,
webmaster@1 81 'not null' => TRUE,
webmaster@1 82 'default' => 0,
webmaster@1 83 'description' => t('Primary Key: The {node}.vid of the node.'),
webmaster@1 84 ),
webmaster@1 85 'tid' => array(
webmaster@1 86 'type' => 'int',
webmaster@1 87 'unsigned' => TRUE,
webmaster@1 88 'not null' => TRUE,
webmaster@1 89 'default' => 0,
webmaster@1 90 'description' => t('The {term_data}.tid of the forum term assigned to the node.'),
webmaster@1 91 ),
webmaster@1 92 ),
webmaster@1 93 'indexes' => array(
webmaster@1 94 'nid' => array('nid'),
webmaster@1 95 'tid' => array('tid')
webmaster@1 96 ),
webmaster@1 97 'primary key' => array('vid'),
webmaster@1 98 );
webmaster@1 99
webmaster@1 100 return $schema;
webmaster@1 101 }
webmaster@1 102
webmaster@1 103 /**
webmaster@1 104 * Create the forum vocabulary if does not exist. Assign the
webmaster@1 105 * vocabulary a low weight so it will appear first in forum topic
webmaster@1 106 * create and edit forms. Do not just call forum_enable() because in
webmaster@1 107 * future versions it might do something different.
webmaster@1 108 */
webmaster@1 109 function forum_update_6000() {
webmaster@1 110 $ret = array();
webmaster@1 111
webmaster@1 112 $vid = variable_get('forum_nav_vocabulary', 0);
webmaster@1 113 $vocabularies = taxonomy_get_vocabularies();
webmaster@1 114 if (!isset($vocabularies[$vid])) {
webmaster@1 115 $vocabulary = array(
webmaster@1 116 'name' => t('Forums'),
webmaster@1 117 'multiple' => 0,
webmaster@1 118 'required' => 0,
webmaster@1 119 'hierarchy' => 1,
webmaster@1 120 'relations' => 0,
webmaster@1 121 'module' => 'forum',
webmaster@1 122 'weight' => -10,
webmaster@1 123 'nodes' => array('forum' => 1),
webmaster@1 124 );
webmaster@1 125 taxonomy_save_vocabulary($vocabulary);
webmaster@1 126
webmaster@1 127 variable_set('forum_nav_vocabulary', $vocabulary['vid']);
webmaster@1 128 }
webmaster@1 129
webmaster@1 130 return $ret;
webmaster@1 131 }