diff modules/forum/forum.install @ 1:c1f4ac30525a 6.0

Drupal 6.0
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:28:28 +0100
parents
children fff6d4c8c043
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/forum/forum.install	Tue Dec 23 14:28:28 2008 +0100
@@ -0,0 +1,131 @@
+<?php
+// $Id: forum.install,v 1.16 2007/12/31 16:58:34 goba Exp $
+
+/**
+ * Implementation of hook_install().
+ */
+function forum_install() {
+  // Create tables.
+  drupal_install_schema('forum');
+  // 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'");
+}
+
+function forum_enable() {
+  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.
+    $vocabulary = (array) $vocabulary;
+    $vocabulary['nodes']['forum'] = 1;
+    taxonomy_save_vocabulary($vocabulary);
+  }
+  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.
+    $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']);
+  }
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function forum_uninstall() {
+  // Load the dependent Taxonomy module, in case it has been disabled.
+  drupal_load('module', 'taxonomy');
+
+  // Delete the vocabulary.
+  $vid = variable_get('forum_nav_vocabulary', '');
+  taxonomy_del_vocabulary($vid);
+
+  db_query("DELETE FROM {node} WHERE type = 'forum'");
+  db_query('DROP TABLE {forum}');
+  variable_del('forum_containers');
+  variable_del('forum_nav_vocabulary');
+  variable_del('forum_hot_topic');
+  variable_del('forum_per_page');
+  variable_del('forum_order');
+  variable_del('forum_block_num_0');
+  variable_del('forum_block_num_1');
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function forum_schema() {
+  $schema['forum'] = array(
+    'description' => t('Stores the relationship of nodes to forum terms.'),
+    'fields' => array(
+      'nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => t('The {node}.nid of the node.'),
+      ),
+      'vid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => t('Primary Key: The {node}.vid of the node.'),
+      ),
+      'tid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => t('The {term_data}.tid of the forum term assigned to the node.'),
+      ),
+    ),
+    'indexes' => array(
+      'nid' => array('nid'),
+      'tid' => array('tid')
+    ),
+    'primary key' => array('vid'),
+  );
+
+  return $schema;
+}
+
+/**
+ * Create the forum vocabulary if does not exist. Assign the
+ * vocabulary a low weight so it will appear first in forum topic
+ * create and edit forms.  Do not just call forum_enable() because in
+ * 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;
+}