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