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