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