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