forum.install 3.67 KB
Newer Older
1
<?php
2
// $Id$
3

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

9
/**
10
 * Implement hook_install().
11
 */
12
function forum_install() {
13 14
  // Create tables.
  drupal_install_schema('forum');
15 16
  // Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module.
  db_query("UPDATE {system} SET weight = 1 WHERE name = 'forum'");
17 18
}

19
function forum_enable() {
20 21 22
  if ($vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0))) {
    // Existing install. Add back forum node type, if the forums
    // vocabulary still exists. Keep all other node types intact there.
23
    $vocabulary->nodes['forum'] = 1;
24
    taxonomy_vocabulary_save($vocabulary);
25 26 27 28 29
  }
  else {
    // Create the forum vocabulary if it does not exist. Assign the vocabulary
    // a low weight so it will appear first in forum topic create and edit
    // forms.
30
    $edit = array(
31 32
      'name' => t('Forums'),
      'multiple' => 0,
33
      'required' => 0,
34 35 36 37 38 39
      'hierarchy' => 1,
      'relations' => 0,
      'module' => 'forum',
      'weight' => -10,
      'nodes' => array('forum' => 1),
    );
40 41
    $vocabulary = (object) $edit;
    taxonomy_vocabulary_save($vocabulary);
42

43
    variable_set('forum_nav_vocabulary', $vocabulary->vid);
44
  }
45
}
46 47

/**
48
 * Implement hook_uninstall().
49 50
 */
function forum_uninstall() {
51 52 53
  // Load the dependent Taxonomy module, in case it has been disabled.
  drupal_load('module', 'taxonomy');

54
  // Delete the vocabulary.
55 56
  $vid = variable_get('forum_nav_vocabulary', 0);
  taxonomy_vocabulary_delete($vid);
57

58
  db_query('DROP TABLE {forum}');
59 60 61 62 63
  variable_del('forum_containers');
  variable_del('forum_nav_vocabulary');
  variable_del('forum_hot_topic');
  variable_del('forum_per_page');
  variable_del('forum_order');
64 65
  variable_del('forum_block_num_active');
  variable_del('forum_block_num_new');
66
}
67 68

/**
69
 * Implement hook_schema().
70 71 72
 */
function forum_schema() {
  $schema['forum'] = array(
73
    'description' => 'Stores the relationship of nodes to forum terms.',
74
    'fields' => array(
75 76 77 78 79
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
80
        'description' => 'The {node}.nid of the node.',
81 82 83 84 85 86
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
87
        'description' => 'Primary Key: The {node}.vid of the node.',
88 89 90 91 92 93
      ),
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
94
        'description' => 'The {taxonomy_term_data}.tid of the forum term assigned to the node.',
95
      ),
96 97 98
    ),
    'indexes' => array(
      'nid' => array('nid'),
99
      'tid' => array('tid'),
100 101
    ),
    'primary key' => array('vid'),
102 103 104 105
    'foreign keys' => array(
      'nid' => array('node' => 'nid'),
      'vid' => array('node' => 'vid'),
    ),
106 107 108 109
  );

  return $schema;
}
110 111 112 113

/**
 * Create the forum vocabulary if does not exist. Assign the
 * vocabulary a low weight so it will appear first in forum topic
114
 * create and edit forms. Do not just call forum_enable() because in
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
 * future versions it might do something different.
 */
function forum_update_6000() {
  $ret = array();

  $vid = variable_get('forum_nav_vocabulary', 0);
  $vocabularies = taxonomy_get_vocabularies();
  if (!isset($vocabularies[$vid])) {
    $vocabulary = array(
      'name' => t('Forums'),
      'multiple' => 0,
      'required' => 0,
      'hierarchy' => 1,
      'relations' => 0,
      'module' => 'forum',
      'weight' => -10,
      'nodes' => array('forum' => 1),
    );
    taxonomy_save_vocabulary($vocabulary);

    variable_set('forum_nav_vocabulary', $vocabulary['vid']);
  }

  return $ret;
139
}