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