Code coverage for /20080809/modules/forum/forum.install

Line #Times calledCode
1
<?php
2
// $Id: forum.install,v 1.19 2008/06/25 07:47:20 dries Exp $
3
4
/**
5
 * Implementation of hook_install().
6
 */
71
function forum_install() {
8
  // Create tables.
91
  drupal_install_schema('forum');
10
  // Set the weight of the forum.module to 1 so it is loaded after the
taxonomy.module.
111
  db_query("UPDATE {system} SET weight = 1 WHERE name = 'forum'");
121
}
13
141
function forum_enable() {
151
  if ($vocabulary =
taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0))) {
16
    // Existing install. Add back forum node type, if the forums
17
    // vocabulary still exists. Keep all other node types intact there.
180
    $vocabulary = (array) $vocabulary;
190
    $vocabulary['nodes']['forum'] = 1;
200
    taxonomy_save_vocabulary($vocabulary);
210
  }
22
  else {
23
    // Create the forum vocabulary if it does not exist. Assign the
vocabulary
24
    // a low weight so it will appear first in forum topic create and edit
25
    // forms.
26
    $vocabulary = array(
271
      'name' => t('Forums'),
281
      'multiple' => 0,
291
      'required' => 0,
301
      'hierarchy' => 1,
311
      'relations' => 0,
321
      'module' => 'forum',
331
      'weight' => -10,
341
      'nodes' => array('forum' => 1),
351
    );
361
    taxonomy_save_vocabulary($vocabulary);
37
381
    variable_set('forum_nav_vocabulary', $vocabulary['vid']);
39
  }
401
}
41
42
/**
43
 * Implementation of hook_uninstall().
44
 */
451
function forum_uninstall() {
46
  // Load the dependent Taxonomy module, in case it has been disabled.
470
  drupal_load('module', 'taxonomy');
48
49
  // Delete the vocabulary.
500
  $vid = variable_get('forum_nav_vocabulary', '');
510
  taxonomy_del_vocabulary($vid);
52
530
  db_query('DROP TABLE {forum}');
540
  variable_del('forum_containers');
550
  variable_del('forum_nav_vocabulary');
560
  variable_del('forum_hot_topic');
570
  variable_del('forum_per_page');
580
  variable_del('forum_order');
590
  variable_del('forum_block_num_active');
600
  variable_del('forum_block_num_new');
610
}
62
63
/**
64
 * Implementation of hook_schema().
65
 */
661
function forum_schema() {
671
  $schema['forum'] = array(
681
    'description' => t('Stores the relationship of nodes to forum
terms.'),
69
    'fields' => array(
70
      'nid' => array(
711
        'type' => 'int',
721
        'unsigned' => TRUE,
731
        'not null' => TRUE,
741
        'default' => 0,
751
        'description' => t('The {node}.nid of the node.'),
761
      ),
77
      'vid' => array(
781
        'type' => 'int',
791
        'unsigned' => TRUE,
801
        'not null' => TRUE,
811
        'default' => 0,
821
        'description' => t('Primary Key: The {node}.vid of the node.'),
831
      ),
84
      'tid' => array(
851
        'type' => 'int',
861
        'unsigned' => TRUE,
871
        'not null' => TRUE,
881
        'default' => 0,
891
        'description' => t('The {term_data}.tid of the forum term assigned
to the node.'),
901
      ),
911
    ),
92
    'indexes' => array(
931
      'nid' => array('nid'),
941
      'tid' => array('tid'),
951
    ),
961
    'primary key' => array('vid'),
97
  );
98
991
  return $schema;
1000
}
101
102
/**
103
 * Create the forum vocabulary if does not exist. Assign the
104
 * vocabulary a low weight so it will appear first in forum topic
105
 * create and edit forms.  Do not just call forum_enable() because in
106
 * future versions it might do something different.
107
 */
1081
function forum_update_6000() {
1090
  $ret = array();
110
1110
  $vid = variable_get('forum_nav_vocabulary', 0);
1120
  $vocabularies = taxonomy_get_vocabularies();
1130
  if (!isset($vocabularies[$vid])) {
114
    $vocabulary = array(
1150
      'name' => t('Forums'),
1160
      'multiple' => 0,
1170
      'required' => 0,
1180
      'hierarchy' => 1,
1190
      'relations' => 0,
1200
      'module' => 'forum',
1210
      'weight' => -10,
1220
      'nodes' => array('forum' => 1),
1230
    );
1240
    taxonomy_save_vocabulary($vocabulary);
125
1260
    variable_set('forum_nav_vocabulary', $vocabulary['vid']);
1270
  }
128
1290
  return $ret;
1300
}
1311