webmaster@1
|
1 <?php |
webmaster@1
|
2 // $Id: comment.install,v 1.19 2008/01/16 21:45:30 goba Exp $ |
webmaster@1
|
3 |
webmaster@1
|
4 /** |
webmaster@1
|
5 * Implementation of hook_enable(). |
webmaster@1
|
6 */ |
webmaster@1
|
7 function comment_enable() { |
webmaster@1
|
8 // Insert records into the node_comment_statistics for nodes that are missing. |
webmaster@1
|
9 db_query("INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, n.changed, NULL, n.uid, 0 FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE c.comment_count IS NULL"); |
webmaster@1
|
10 } |
webmaster@1
|
11 |
webmaster@1
|
12 /** |
webmaster@1
|
13 * Changed node_comment_statistics to use node->changed to avoid future timestamps. |
webmaster@1
|
14 */ |
webmaster@1
|
15 function comment_update_1() { |
webmaster@1
|
16 // Change any future last comment timestamps to now. |
webmaster@1
|
17 db_query('UPDATE {node_comment_statistics} SET last_comment_timestamp = %d WHERE last_comment_timestamp > %d', time(), time()); |
webmaster@1
|
18 |
webmaster@1
|
19 // Unstuck node indexing timestamp if needed. |
webmaster@1
|
20 if (($last = variable_get('node_cron_last', FALSE)) !== FALSE) { |
webmaster@1
|
21 variable_set('node_cron_last', min(time(), $last)); |
webmaster@1
|
22 } |
webmaster@1
|
23 return array(); |
webmaster@1
|
24 } |
webmaster@1
|
25 |
webmaster@1
|
26 function comment_update_6001() { |
webmaster@1
|
27 $ret[] = update_sql("ALTER TABLE {comments} DROP score"); |
webmaster@1
|
28 $ret[] = update_sql("ALTER TABLE {comments} DROP users"); |
webmaster@1
|
29 return $ret; |
webmaster@1
|
30 } |
webmaster@1
|
31 |
webmaster@1
|
32 /** |
webmaster@1
|
33 * Changed comment settings from global to per-node -- copy global |
webmaster@1
|
34 * settings to all node types. |
webmaster@1
|
35 */ |
webmaster@1
|
36 function comment_update_6002() { |
webmaster@1
|
37 // Comment module might not be enabled when this is run, but we need the |
webmaster@1
|
38 // constants defined by the module for this update. |
webmaster@1
|
39 drupal_load('module', 'comment'); |
webmaster@1
|
40 $settings = array( |
webmaster@1
|
41 'comment_default_mode' => COMMENT_MODE_THREADED_EXPANDED, |
webmaster@1
|
42 'comment_default_order' => COMMENT_ORDER_NEWEST_FIRST, |
webmaster@1
|
43 'comment_default_per_page' => 50, |
webmaster@1
|
44 'comment_controls' => COMMENT_CONTROLS_HIDDEN, |
webmaster@1
|
45 'comment_anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT, |
webmaster@1
|
46 'comment_subject_field' => 1, |
webmaster@1
|
47 'comment_preview' => COMMENT_PREVIEW_REQUIRED, |
webmaster@1
|
48 'comment_form_location' => COMMENT_FORM_SEPARATE_PAGE, |
webmaster@1
|
49 ); |
webmaster@1
|
50 $types = node_get_types(); |
webmaster@1
|
51 foreach ($settings as $setting => $default) { |
webmaster@1
|
52 $value = variable_get($setting, $default); |
webmaster@1
|
53 foreach ($types as $type => $object) { |
webmaster@1
|
54 variable_set($setting .'_'. $type, $value); |
webmaster@1
|
55 } |
webmaster@1
|
56 variable_del($setting); |
webmaster@1
|
57 } |
webmaster@1
|
58 return array(array('success' => TRUE, 'query' => 'Global comment settings copied to all node types.')); |
webmaster@1
|
59 } |
webmaster@1
|
60 |
webmaster@1
|
61 /** |
webmaster@1
|
62 * Add index to parent ID field. |
webmaster@1
|
63 */ |
webmaster@1
|
64 function comment_update_6003() { |
webmaster@1
|
65 $ret = array(); |
webmaster@1
|
66 db_add_index($ret, 'comments', 'pid', array('pid')); |
webmaster@1
|
67 return $ret; |
webmaster@1
|
68 } |
webmaster@1
|
69 |
webmaster@1
|
70 |
webmaster@1
|
71 /** |
webmaster@1
|
72 * Implementation of hook_schema(). |
webmaster@1
|
73 */ |
webmaster@1
|
74 function comment_schema() { |
webmaster@1
|
75 $schema['comments'] = array( |
webmaster@1
|
76 'description' => t('Stores comments and associated data.'), |
webmaster@1
|
77 'fields' => array( |
webmaster@1
|
78 'cid' => array( |
webmaster@1
|
79 'type' => 'serial', |
webmaster@1
|
80 'not null' => TRUE, |
webmaster@1
|
81 'description' => t('Primary Key: Unique comment ID.'), |
webmaster@1
|
82 ), |
webmaster@1
|
83 'pid' => array( |
webmaster@1
|
84 'type' => 'int', |
webmaster@1
|
85 'not null' => TRUE, |
webmaster@1
|
86 'default' => 0, |
webmaster@1
|
87 'description' => t('The {comments}.cid to which this comment is a reply. If set to 0, this comment is not a reply to an existing comment.'), |
webmaster@1
|
88 ), |
webmaster@1
|
89 'nid' => array( |
webmaster@1
|
90 'type' => 'int', |
webmaster@1
|
91 'not null' => TRUE, |
webmaster@1
|
92 'default' => 0, |
webmaster@1
|
93 'description' => t('The {node}.nid to which this comment is a reply.'), |
webmaster@1
|
94 ), |
webmaster@1
|
95 'uid' => array( |
webmaster@1
|
96 'type' => 'int', |
webmaster@1
|
97 'not null' => TRUE, |
webmaster@1
|
98 'default' => 0, |
webmaster@1
|
99 'description' => t('The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.'), |
webmaster@1
|
100 ), |
webmaster@1
|
101 'subject' => array( |
webmaster@1
|
102 'type' => 'varchar', |
webmaster@1
|
103 'length' => 64, |
webmaster@1
|
104 'not null' => TRUE, |
webmaster@1
|
105 'default' => '', |
webmaster@1
|
106 'description' => t('The comment title.'), |
webmaster@1
|
107 ), |
webmaster@1
|
108 'comment' => array( |
webmaster@1
|
109 'type' => 'text', |
webmaster@1
|
110 'not null' => TRUE, |
webmaster@1
|
111 'size' => 'big', |
webmaster@1
|
112 'description' => t('The comment body.'), |
webmaster@1
|
113 ), |
webmaster@1
|
114 'hostname' => array( |
webmaster@1
|
115 'type' => 'varchar', |
webmaster@1
|
116 'length' => 128, |
webmaster@1
|
117 'not null' => TRUE, |
webmaster@1
|
118 'default' => '', |
webmaster@1
|
119 'description' => t("The author's host name."), |
webmaster@1
|
120 ), |
webmaster@1
|
121 'timestamp' => array( |
webmaster@1
|
122 'type' => 'int', |
webmaster@1
|
123 'not null' => TRUE, |
webmaster@1
|
124 'default' => 0, |
webmaster@1
|
125 'description' => t('The time that the comment was created, or last edited by its author, as a Unix timestamp.'), |
webmaster@1
|
126 ), |
webmaster@1
|
127 'status' => array( |
webmaster@1
|
128 'type' => 'int', |
webmaster@1
|
129 'unsigned' => TRUE, |
webmaster@1
|
130 'not null' => TRUE, |
webmaster@1
|
131 'default' => 0, |
webmaster@1
|
132 'size' => 'tiny', |
webmaster@1
|
133 'description' => t('The published status of a comment. (0 = Published, 1 = Not Published)'), |
webmaster@1
|
134 ), |
webmaster@1
|
135 'format' => array( |
webmaster@1
|
136 'type' => 'int', |
webmaster@1
|
137 'size' => 'small', |
webmaster@1
|
138 'not null' => TRUE, |
webmaster@1
|
139 'default' => 0, |
webmaster@1
|
140 'description' => t('The {filter_formats}.format of the comment body.'), |
webmaster@1
|
141 ), |
webmaster@1
|
142 'thread' => array( |
webmaster@1
|
143 'type' => 'varchar', |
webmaster@1
|
144 'length' => 255, |
webmaster@1
|
145 'not null' => TRUE, |
webmaster@1
|
146 'description' => t("The vancode representation of the comment's place in a thread."), |
webmaster@1
|
147 ), |
webmaster@1
|
148 'name' => array( |
webmaster@1
|
149 'type' => 'varchar', |
webmaster@1
|
150 'length' => 60, |
webmaster@1
|
151 'not null' => FALSE, |
webmaster@1
|
152 'description' => t("The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form."), |
webmaster@1
|
153 ), |
webmaster@1
|
154 'mail' => array( |
webmaster@1
|
155 'type' => 'varchar', |
webmaster@1
|
156 'length' => 64, |
webmaster@1
|
157 'not null' => FALSE, |
webmaster@1
|
158 'description' => t("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."), |
webmaster@1
|
159 ), |
webmaster@1
|
160 'homepage' => array( |
webmaster@1
|
161 'type' => 'varchar', |
webmaster@1
|
162 'length' => 255, |
webmaster@1
|
163 'not null' => FALSE, |
webmaster@1
|
164 'description' => t("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."), |
webmaster@1
|
165 ) |
webmaster@1
|
166 ), |
webmaster@1
|
167 'indexes' => array( |
webmaster@1
|
168 'pid' => array('pid'), |
webmaster@1
|
169 'nid' => array('nid'), |
webmaster@1
|
170 'status' => array('status'), // This index is probably unused |
webmaster@1
|
171 ), |
webmaster@1
|
172 'primary key' => array('cid'), |
webmaster@1
|
173 ); |
webmaster@1
|
174 |
webmaster@1
|
175 $schema['node_comment_statistics'] = array( |
webmaster@1
|
176 'description' => t('Maintains statistics of node and comments posts to show "new" and "updated" flags.'), |
webmaster@1
|
177 'fields' => array( |
webmaster@1
|
178 'nid' => array( |
webmaster@1
|
179 'type' => 'int', |
webmaster@1
|
180 'unsigned' => TRUE, |
webmaster@1
|
181 'not null' => TRUE, |
webmaster@1
|
182 'default' => 0, |
webmaster@1
|
183 'description' => t('The {node}.nid for which the statistics are compiled.'), |
webmaster@1
|
184 ), |
webmaster@1
|
185 'last_comment_timestamp' => array( |
webmaster@1
|
186 'type' => 'int', |
webmaster@1
|
187 'not null' => TRUE, |
webmaster@1
|
188 'default' => 0, |
webmaster@1
|
189 'description' => t('The Unix timestamp of the last comment that was posted within this node, from {comments}.timestamp.'), |
webmaster@1
|
190 ), |
webmaster@1
|
191 'last_comment_name' => array( |
webmaster@1
|
192 'type' => 'varchar', |
webmaster@1
|
193 'length' => 60, |
webmaster@1
|
194 'not null' => FALSE, |
webmaster@1
|
195 'description' => t('The name of the latest author to post a comment on this node, from {comments}.name.'), |
webmaster@1
|
196 ), |
webmaster@1
|
197 'last_comment_uid' => array( |
webmaster@1
|
198 'type' => 'int', |
webmaster@1
|
199 'not null' => TRUE, |
webmaster@1
|
200 'default' => 0, |
webmaster@1
|
201 'description' => t('The user ID of the latest author to post a comment on this node, from {comments}.uid.'), |
webmaster@1
|
202 ), |
webmaster@1
|
203 'comment_count' => array( |
webmaster@1
|
204 'type' => 'int', |
webmaster@1
|
205 'unsigned' => TRUE, |
webmaster@1
|
206 'not null' => TRUE, |
webmaster@1
|
207 'default' => 0, |
webmaster@1
|
208 'description' => t('The total number of comments on this node.'), |
webmaster@1
|
209 ), |
webmaster@1
|
210 ), |
webmaster@1
|
211 'primary key' => array('nid'), |
webmaster@1
|
212 'indexes' => array( |
webmaster@1
|
213 'node_comment_timestamp' => array('last_comment_timestamp') |
webmaster@1
|
214 ), |
webmaster@1
|
215 ); |
webmaster@1
|
216 |
webmaster@1
|
217 return $schema; |
webmaster@1
|
218 } |
webmaster@1
|
219 |