/[drupal]/drupal/modules/forum/forum.install
ViewVC logotype

Contents of /drupal/modules/forum/forum.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.38 - (show annotations) (download) (as text)
Tue Oct 20 00:28:16 2009 UTC (5 weeks, 4 days ago) by dries
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.37: +2 -4 lines
File MIME type: text/x-php
- Patch #601938 by mfb: fixed some forum exceptions and added tests.
1 <?php
2 // $Id: forum.install,v 1.37 2009/10/15 12:44:36 dries Exp $
3
4 /**
5 * @file
6 * Install, update and uninstall functions for the forum module.
7 */
8
9 /**
10 * Implement hook_install().
11 */
12 function forum_install() {
13 // Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module.
14 db_update('system')
15 ->fields(array('weight' => 1))
16 ->condition('name', 'forum')
17 ->execute();
18 // Forum topics are published by default, but do not have any other default
19 // options set (for example, they are not promoted to the front page).
20 variable_set('node_options_forum', array('status'));
21 }
22
23 function forum_enable() {
24 if ($vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0))) {
25 // Save the vocabulary to create the default field instance.
26 taxonomy_vocabulary_save($vocabulary);
27 }
28 else {
29 // Create the forum vocabulary if it does not exist. Assign the vocabulary
30 // a low weight so it will appear first in forum topic create and edit
31 // forms.
32 $edit = array(
33 'name' => t('Forums'),
34 'machine_name' => 'forums',
35 'description' => t('Forum navigation vocabulary'),
36 'hierarchy' => 1,
37 'relations' => 0,
38 'module' => 'forum',
39 'weight' => -10,
40 );
41 $vocabulary = (object) $edit;
42 taxonomy_vocabulary_save($vocabulary);
43
44 $instance = array(
45 'field_name' => 'taxonomy_' . $vocabulary->machine_name,
46 'object_type' => 'node',
47 'label' => $vocabulary->name,
48 'bundle' => 'forum',
49 'widget' => array(
50 'type' => 'options_select',
51 ),
52 );
53 field_create_instance($instance);
54
55 variable_set('forum_nav_vocabulary', $vocabulary->vid);
56 }
57 }
58
59 /**
60 * Implement hook_uninstall().
61 */
62 function forum_uninstall() {
63 // Load the dependent Taxonomy module, in case it has been disabled.
64 drupal_load('module', 'taxonomy');
65
66 // Delete the vocabulary.
67 $vid = variable_get('forum_nav_vocabulary', 0);
68 taxonomy_vocabulary_delete($vid);
69
70 variable_del('forum_containers');
71 variable_del('forum_nav_vocabulary');
72 variable_del('forum_hot_topic');
73 variable_del('forum_per_page');
74 variable_del('forum_order');
75 variable_del('forum_block_num_active');
76 variable_del('forum_block_num_new');
77 variable_del('node_options_forum');
78 }
79
80 /**
81 * Implement hook_schema().
82 */
83 function forum_schema() {
84 $schema['forum'] = array(
85 'description' => 'Stores the relationship of nodes to forum terms.',
86 'fields' => array(
87 'nid' => array(
88 'type' => 'int',
89 'unsigned' => TRUE,
90 'not null' => TRUE,
91 'default' => 0,
92 'description' => 'The {node}.nid of the node.',
93 ),
94 'vid' => array(
95 'type' => 'int',
96 'unsigned' => TRUE,
97 'not null' => TRUE,
98 'default' => 0,
99 'description' => 'Primary Key: The {node}.vid of the node.',
100 ),
101 'tid' => array(
102 'type' => 'int',
103 'unsigned' => TRUE,
104 'not null' => TRUE,
105 'default' => 0,
106 'description' => 'The {taxonomy_term_data}.tid of the forum term assigned to the node.',
107 ),
108 ),
109 'indexes' => array(
110 'forum_topic' => array('nid', 'tid'),
111 'tid' => array('tid'),
112 ),
113 'primary key' => array('vid'),
114 'foreign keys' => array(
115 'nid' => array('node' => 'nid'),
116 'vid' => array('node' => 'vid'),
117 ),
118 );
119
120 $schema['forum_index'] = array(
121 'description' => 'Maintains denormalized information about node/term relationships.',
122 'fields' => array(
123 'nid' => array(
124 'description' => 'The {node}.nid this record tracks.',
125 'type' => 'int',
126 'unsigned' => TRUE,
127 'not null' => TRUE,
128 'default' => 0,
129 ),
130 'title' => array(
131 'description' => 'The title of this node, always treated as non-markup plain text.',
132 'type' => 'varchar',
133 'length' => 255,
134 'not null' => TRUE,
135 'default' => '',
136 ),
137 'tid' => array(
138 'description' => 'The term ID.',
139 'type' => 'int',
140 'unsigned' => TRUE,
141 'not null' => TRUE,
142 'default' => 0,
143 ),
144 'sticky' => array(
145 'description' => 'Boolean indicating whether the node is sticky.',
146 'type' => 'int',
147 'not null' => FALSE,
148 'default' => 0,
149 'size' => 'tiny',
150 ),
151 'created' => array(
152 'description' => 'The Unix timestamp when the node was created.',
153 'type' => 'int',
154 'unsigned' => TRUE,
155 'not null' => TRUE,
156 'default'=> 0,
157 ),
158 'last_comment_timestamp' => array(
159 'type' => 'int',
160 'not null' => TRUE,
161 'default' => 0,
162 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
163 ),
164 'comment_count' => array(
165 'type' => 'int',
166 'unsigned' => TRUE,
167 'not null' => TRUE,
168 'default' => 0,
169 'description' => 'The total number of comments on this node.',
170 ),
171 ),
172 'indexes' => array(
173 'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'),
174 ),
175 'foreign keys' => array(
176 'node' => 'nid',
177 'taxonomy_term_data' => 'tid',
178 ),
179 );
180
181
182 return $schema;
183 }
184
185 /**
186 * Add new index to forum table.
187 */
188 function forum_update_7000() {
189 db_drop_index('forum', 'nid');
190 db_add_index('forum', 'forum_topic', array('nid', 'tid'));
191 }
192
193 /**
194 * Create new {forum_index} table.
195 */
196 function forum_update_7001() {
197 $forum_index = array(
198 'description' => 'Maintains denormalized information about node/term relationships.',
199 'fields' => array(
200 'nid' => array(
201 'description' => 'The {node}.nid this record tracks.',
202 'type' => 'int',
203 'unsigned' => TRUE,
204 'not null' => TRUE,
205 'default' => 0,
206 ),
207 'title' => array(
208 'description' => 'The title of this node, always treated as non-markup plain text.',
209 'type' => 'varchar',
210 'length' => 255,
211 'not null' => TRUE,
212 'default' => '',
213 ),
214 'tid' => array(
215 'description' => 'The term ID.',
216 'type' => 'int',
217 'unsigned' => TRUE,
218 'not null' => TRUE,
219 'default' => 0,
220 ),
221 'sticky' => array(
222 'description' => 'Boolean indicating whether the node is sticky.',
223 'type' => 'int',
224 'not null' => FALSE,
225 'default' => 0,
226 'size' => 'tiny',
227 ),
228 'created' => array(
229 'description' => 'The Unix timestamp when the node was created.',
230 'type' => 'int',
231 'unsigned' => TRUE,
232 'not null' => TRUE,
233 'default'=> 0,
234 ),
235 'last_comment_timestamp' => array(
236 'type' => 'int',
237 'not null' => TRUE,
238 'default' => 0,
239 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
240 ),
241 'comment_count' => array(
242 'type' => 'int',
243 'unsigned' => TRUE,
244 'not null' => TRUE,
245 'default' => 0,
246 'description' => 'The total number of comments on this node.',
247 ),
248 ),
249 'indexes' => array(
250 'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'),
251 ),
252 'foreign keys' => array(
253 'node' => 'nid',
254 'taxonomy_term_data' => 'tid',
255 ),
256 );
257 db_create_table('forum_index', $forum_index);
258
259 db_query('INSERT INTO {forum_index} (SELECT n.nid, n.title, f.tid, n.sticky, n.created, ncs.last_comment_timestamp, ncs.comment_count FROM {node} n INNER JOIN {forum} f on n.vid = f.vid INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid)');
260 }

  ViewVC Help
Powered by ViewVC 1.1.2