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

Contents of /drupal/modules/comment/comment.install

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


Revision 1.51 - (show annotations) (download) (as text)
Fri Oct 16 13:20:15 2009 UTC (6 weeks ago) by dries
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10
Changes since 1.50: +21 -1 lines
File MIME type: text/x-php
- Patch #275368 by michaelfavia, sun, mattconnolly: allow disabling comment preview + unify with node preview settings.
1 <?php
2 // $Id: comment.install,v 1.50 2009/10/16 03:40:40 webchick Exp $
3
4 /**
5 * @file
6 * Install, update and uninstall functions for the comment module.
7 */
8
9 /**
10 * Implement hook_uninstall().
11 */
12 function comment_uninstall() {
13 // Remove variables.
14 variable_del('comment_block_count');
15 $node_types = array_keys(node_type_get_types());
16 foreach ($node_types as $node_type) {
17 variable_del('comment_' . $node_type);
18 variable_del('comment_anonymous_' . $node_type);
19 variable_del('comment_controls_' . $node_type);
20 variable_del('comment_default_mode_' . $node_type);
21 variable_del('comment_default_order_' . $node_type);
22 variable_del('comment_default_per_page_' . $node_type);
23 variable_del('comment_form_location_' . $node_type);
24 variable_del('comment_preview_' . $node_type);
25 variable_del('comment_subject_field_' . $node_type);
26 }
27 }
28
29 /**
30 * Implement hook_enable().
31 */
32 function comment_enable() {
33 // Insert records into the node_comment_statistics for nodes that are missing.
34 $query = db_select('node', 'n');
35 $query->leftJoin('node_comment_statistics', 'ncs', 'ncs.nid = n.nid');
36 $query->addField('n', 'changed', 'last_comment_timestamp');
37 $query->addField('n', 'uid', 'last_comment_uid');
38 $query->addField('n', 'nid');
39 $query->addExpression('0', 'comment_count');
40 $query->addExpression('NULL', 'last_comment_name');
41 $query->isNull('ncs.comment_count');
42
43 db_insert('node_comment_statistics')
44 ->from($query)
45 ->execute();
46 }
47
48 /**
49 * @defgroup updates-6.x-to-7.x Comment updates from 6.x to 7.x
50 * @{
51 */
52
53 /**
54 * Remove comment settings for page ordering.
55 */
56 function comment_update_7000() {
57 $types = node_type_get_types();
58 foreach ($types as $type => $object) {
59 variable_del('comment_default_order' . $type);
60 }
61 return t('Comment order settings removed.');
62 }
63
64 /**
65 * Change comment status from published being 0 to being 1
66 */
67 function comment_update_7001() {
68 $changes = array(
69 3 => 0,
70 0 => 1,
71 1 => 3,
72 );
73
74 foreach ($changes as $old => $new) {
75 db_update('comments')
76 ->fields(array('status', $new))
77 ->condition('status', $old)
78 ->execute();
79 }
80 }
81
82 /**
83 * Rename {comments} table to {comment}.
84 */
85 function comment_update_7002() {
86 db_rename_table('comments', 'comment');
87 }
88
89 /**
90 * Improve indexes on the comment table.
91 */
92 function comment_update_7003() {
93 db_drop_index('comment', 'status');
94 db_drop_index('comment', 'pid');
95 db_add_index('comment', 'comment_pid_status', array('pid', 'status'));
96 db_add_index('comment', 'comment_num_new', array('nid', 'timestamp', 'status'));
97 }
98
99 /**
100 * Rename comment display setting variables.
101 */
102 function comment_update_7004() {
103 $types = node_type_get_types();
104 foreach ($types as $type => $object) {
105 $setting = variable_get('comment_default_mode_' . $type, 4);
106 if ($setting == 3 || $setting == 4) {
107 variable_set('comment_default_mode_' . $type, 1);
108 }
109 else {
110 variable_set('comment_default_mode_' . $type, 0);
111 }
112 }
113 }
114
115 /**
116 * Create comment Field API bundles.
117 */
118 function comment_update_7005() {
119 foreach (node_type_get_types() as $info) {
120 field_attach_create_bundle('comment', 'comment_node_' . $info->type);
121 }
122 }
123
124 /**
125 * Create user related indexes.
126 */
127 function comment_update_7006() {
128 db_add_index('comment', 'comment_uid', array('uid'));
129 db_add_index('node_comment_statistics', 'last_comment_uid', array('last_comment_uid'));
130 }
131
132 /**
133 * Split {comment}.timestamp into {comment}.created and {comment}.changed.
134 */
135 function comment_update_7007() {
136 // Drop the index associated to timestamp.
137 db_drop_index('comment', 'comment_num_new');
138
139 // Create a created column.
140 db_add_field('comment', 'created', array(
141 'type' => 'int',
142 'not null' => TRUE,
143 'default' => 0,
144 ));
145
146 // Rename the timestamp column to changed.
147 db_change_field('comment', 'timestamp', 'changed', array(
148 'type' => 'int',
149 'not null' => TRUE,
150 'default' => 0,
151 ));
152
153 // Recreate the index.
154 db_add_index('comment', 'comment_num_new', array('nid', 'changed', 'status'));
155
156 // Migrate the data.
157 // @todo db_update() should support this.
158 db_query('UPDATE {comment} SET created = changed');
159 }
160
161 /**
162 * Add language column to the {comment} table.
163 */
164 function comment_update_7008() {
165 // Create a language column.
166 db_add_field('comment', 'language', array(
167 'type' => 'varchar',
168 'length' => 12,
169 'not null' => TRUE,
170 'default' => '',
171 ));
172
173 // Create the index.
174 db_add_index('comment', 'comment_nid_language', array('nid', 'language'));
175 }
176
177 /**
178 * Update preview setting variable to use new constants
179 */
180 function comment_update_7009() {
181 foreach (node_type_get_types() as $type => $object) {
182 // There were only two comment modes in the past:
183 // - 1 was 'required' previously, convert into DRUPAL_REQUIRED (2).
184 // - 0 was 'optional' previously, convert into DRUPAL_OPTIONAL (1).
185 $original_preview = variable_get('comment_preview_' . $type, 1);
186 if ($original_preview) {
187 $preview = DRUPAL_REQUIRED;
188 }
189 else {
190 $preview = DRUPAL_OPTIONAL;
191 }
192 variable_set('comment_preview_' . $type, $preview);
193 }
194 return array();
195 }
196
197 /**
198 * @} End of "defgroup updates-6.x-to-7.x"
199 * The next series of updates should start at 8000.
200 */
201
202 /**
203 * Implement hook_schema().
204 */
205 function comment_schema() {
206 $schema['comment'] = array(
207 'description' => 'Stores comments and associated data.',
208 'fields' => array(
209 'cid' => array(
210 'type' => 'serial',
211 'not null' => TRUE,
212 'description' => 'Primary Key: Unique comment ID.',
213 ),
214 'pid' => array(
215 'type' => 'int',
216 'not null' => TRUE,
217 'default' => 0,
218 'description' => 'The {comment}.cid to which this comment is a reply. If set to 0, this comment is not a reply to an existing comment.',
219 ),
220 'nid' => array(
221 'type' => 'int',
222 'not null' => TRUE,
223 'default' => 0,
224 'description' => 'The {node}.nid to which this comment is a reply.',
225 ),
226 'uid' => array(
227 'type' => 'int',
228 'not null' => TRUE,
229 'default' => 0,
230 'description' => 'The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.',
231 ),
232 'subject' => array(
233 'type' => 'varchar',
234 'length' => 64,
235 'not null' => TRUE,
236 'default' => '',
237 'description' => 'The comment title.',
238 ),
239 'comment' => array(
240 'type' => 'text',
241 'not null' => TRUE,
242 'size' => 'big',
243 'description' => 'The comment body.',
244 ),
245 'hostname' => array(
246 'type' => 'varchar',
247 'length' => 128,
248 'not null' => TRUE,
249 'default' => '',
250 'description' => "The author's host name.",
251 ),
252 'created' => array(
253 'type' => 'int',
254 'not null' => TRUE,
255 'default' => 0,
256 'description' => 'The time that the comment was created, as a Unix timestamp.',
257 ),
258 'changed' => array(
259 'type' => 'int',
260 'not null' => TRUE,
261 'default' => 0,
262 'description' => 'The time that the comment was last edited, as a Unix timestamp.',
263 ),
264 'status' => array(
265 'type' => 'int',
266 'unsigned' => TRUE,
267 'not null' => TRUE,
268 'default' => 1,
269 'size' => 'tiny',
270 'description' => 'The published status of a comment. (0 = Not Published, 1 = Published)',
271 ),
272 'format' => array(
273 'type' => 'int',
274 'size' => 'small',
275 'not null' => TRUE,
276 'default' => 0,
277 'description' => 'The {filter_format}.format of the comment body.',
278 ),
279 'thread' => array(
280 'type' => 'varchar',
281 'length' => 255,
282 'not null' => TRUE,
283 'description' => "The vancode representation of the comment's place in a thread.",
284 ),
285 'name' => array(
286 'type' => 'varchar',
287 'length' => 60,
288 'not null' => FALSE,
289 'description' => "The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form.",
290 ),
291 'mail' => array(
292 'type' => 'varchar',
293 'length' => 64,
294 'not null' => FALSE,
295 'description' => "The comment author's e-mail address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on.",
296 ),
297 'homepage' => array(
298 'type' => 'varchar',
299 'length' => 255,
300 'not null' => FALSE,
301 'description' => "The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on.",
302 ),
303 'language' => array(
304 'description' => 'The {languages}.language of this comment.',
305 'type' => 'varchar',
306 'length' => 12,
307 'not null' => TRUE,
308 'default' => '',
309 ),
310 ),
311 'indexes' => array(
312 'comment_status_pid' => array('pid', 'status'),
313 'comment_num_new' => array('nid', 'changed', 'status'),
314 'comment_uid' => array('uid'),
315 'comment_nid_language' => array('nid', 'language'),
316 ),
317 'primary key' => array('cid'),
318 'foreign keys' => array(
319 'nid' => array('node' => 'nid'),
320 'uid' => array('users' => 'uid'),
321 ),
322 );
323
324 $schema['node_comment_statistics'] = array(
325 'description' => 'Maintains statistics of node and comments posts to show "new" and "updated" flags.',
326 'fields' => array(
327 'nid' => array(
328 'type' => 'int',
329 'unsigned' => TRUE,
330 'not null' => TRUE,
331 'default' => 0,
332 'description' => 'The {node}.nid for which the statistics are compiled.',
333 ),
334 'last_comment_timestamp' => array(
335 'type' => 'int',
336 'not null' => TRUE,
337 'default' => 0,
338 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
339 ),
340 'last_comment_name' => array(
341 'type' => 'varchar',
342 'length' => 60,
343 'not null' => FALSE,
344 'description' => 'The name of the latest author to post a comment on this node, from {comment}.name.',
345 ),
346 'last_comment_uid' => array(
347 'type' => 'int',
348 'not null' => TRUE,
349 'default' => 0,
350 'description' => 'The user ID of the latest author to post a comment on this node, from {comment}.uid.',
351 ),
352 'comment_count' => array(
353 'type' => 'int',
354 'unsigned' => TRUE,
355 'not null' => TRUE,
356 'default' => 0,
357 'description' => 'The total number of comments on this node.',
358 ),
359 ),
360 'primary key' => array('nid'),
361 'indexes' => array(
362 'node_comment_timestamp' => array('last_comment_timestamp'),
363 'comment_count' => array('comment_count'),
364 'last_comment_uid' => array('last_comment_uid'),
365 ),
366 'foreign keys' => array(
367 'nid' => array('node' => 'nid'),
368 'last_comment_uid' => array('users' => 'uid'),
369 ),
370 );
371
372 return $schema;
373 }

  ViewVC Help
Powered by ViewVC 1.1.2