| 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 | | */ |
| 7 | 1 | function forum_install() { |
| 8 | | // Create tables. |
| 9 | 1 | drupal_install_schema('forum'); |
| 10 | | // Set the weight of the forum.module to 1 so it is loaded after the
taxonomy.module. |
| 11 | 1 | db_query("UPDATE {system} SET weight = 1 WHERE name = 'forum'"); |
| 12 | 1 | } |
| 13 | | |
| 14 | 1 | function forum_enable() { |
| 15 | 1 | 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. |
| 18 | 0 | $vocabulary = (array) $vocabulary; |
| 19 | 0 | $vocabulary['nodes']['forum'] = 1; |
| 20 | 0 | taxonomy_save_vocabulary($vocabulary); |
| 21 | 0 | } |
| 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( |
| 27 | 1 | 'name' => t('Forums'), |
| 28 | 1 | 'multiple' => 0, |
| 29 | 1 | 'required' => 0, |
| 30 | 1 | 'hierarchy' => 1, |
| 31 | 1 | 'relations' => 0, |
| 32 | 1 | 'module' => 'forum', |
| 33 | 1 | 'weight' => -10, |
| 34 | 1 | 'nodes' => array('forum' => 1), |
| 35 | 1 | ); |
| 36 | 1 | taxonomy_save_vocabulary($vocabulary); |
| 37 | | |
| 38 | 1 | variable_set('forum_nav_vocabulary', $vocabulary['vid']); |
| 39 | | } |
| 40 | 1 | } |
| 41 | | |
| 42 | | /** |
| 43 | | * Implementation of hook_uninstall(). |
| 44 | | */ |
| 45 | 1 | function forum_uninstall() { |
| 46 | | // Load the dependent Taxonomy module, in case it has been disabled. |
| 47 | 0 | drupal_load('module', 'taxonomy'); |
| 48 | | |
| 49 | | // Delete the vocabulary. |
| 50 | 0 | $vid = variable_get('forum_nav_vocabulary', ''); |
| 51 | 0 | taxonomy_del_vocabulary($vid); |
| 52 | | |
| 53 | 0 | db_query('DROP TABLE {forum}'); |
| 54 | 0 | variable_del('forum_containers'); |
| 55 | 0 | variable_del('forum_nav_vocabulary'); |
| 56 | 0 | variable_del('forum_hot_topic'); |
| 57 | 0 | variable_del('forum_per_page'); |
| 58 | 0 | variable_del('forum_order'); |
| 59 | 0 | variable_del('forum_block_num_active'); |
| 60 | 0 | variable_del('forum_block_num_new'); |
| 61 | 0 | } |
| 62 | | |
| 63 | | /** |
| 64 | | * Implementation of hook_schema(). |
| 65 | | */ |
| 66 | 1 | function forum_schema() { |
| 67 | 1 | $schema['forum'] = array( |
| 68 | 1 | 'description' => t('Stores the relationship of nodes to forum terms.'), |
| 69 | | 'fields' => array( |
| 70 | | 'nid' => array( |
| 71 | 1 | 'type' => 'int', |
| 72 | 1 | 'unsigned' => TRUE, |
| 73 | 1 | 'not null' => TRUE, |
| 74 | 1 | 'default' => 0, |
| 75 | 1 | 'description' => t('The {node}.nid of the node.'), |
| 76 | 1 | ), |
| 77 | | 'vid' => array( |
| 78 | 1 | 'type' => 'int', |
| 79 | 1 | 'unsigned' => TRUE, |
| 80 | 1 | 'not null' => TRUE, |
| 81 | 1 | 'default' => 0, |
| 82 | 1 | 'description' => t('Primary Key: The {node}.vid of the node.'), |
| 83 | 1 | ), |
| 84 | | 'tid' => array( |
| 85 | 1 | 'type' => 'int', |
| 86 | 1 | 'unsigned' => TRUE, |
| 87 | 1 | 'not null' => TRUE, |
| 88 | 1 | 'default' => 0, |
| 89 | 1 | 'description' => t('The {term_data}.tid of the forum term assigned
to the node.'), |
| 90 | 1 | ), |
| 91 | 1 | ), |
| 92 | | 'indexes' => array( |
| 93 | 1 | 'nid' => array('nid'), |
| 94 | 1 | 'tid' => array('tid'), |
| 95 | 1 | ), |
| 96 | 1 | 'primary key' => array('vid'), |
| 97 | | ); |
| 98 | | |
| 99 | 1 | return $schema; |
| 100 | 0 | } |
| 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 | | */ |
| 108 | 1 | function forum_update_6000() { |
| 109 | 0 | $ret = array(); |
| 110 | | |
| 111 | 0 | $vid = variable_get('forum_nav_vocabulary', 0); |
| 112 | 0 | $vocabularies = taxonomy_get_vocabularies(); |
| 113 | 0 | if (!isset($vocabularies[$vid])) { |
| 114 | | $vocabulary = array( |
| 115 | 0 | 'name' => t('Forums'), |
| 116 | 0 | 'multiple' => 0, |
| 117 | 0 | 'required' => 0, |
| 118 | 0 | 'hierarchy' => 1, |
| 119 | 0 | 'relations' => 0, |
| 120 | 0 | 'module' => 'forum', |
| 121 | 0 | 'weight' => -10, |
| 122 | 0 | 'nodes' => array('forum' => 1), |
| 123 | 0 | ); |
| 124 | 0 | taxonomy_save_vocabulary($vocabulary); |
| 125 | | |
| 126 | 0 | variable_set('forum_nav_vocabulary', $vocabulary['vid']); |
| 127 | 0 | } |
| 128 | | |
| 129 | 0 | return $ret; |
| 130 | 0 | } |
| 131 | 1 | |