Code coverage for /20081101/modules/comment/comment.install

Line #Times calledCode
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
 */
712
function comment_enable() {
8
  // Insert records into the node_comment_statistics for nodes that are
missing.
9134
  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");
10134
}
11
12
/**
13
 * Changed node_comment_statistics to use node->changed to avoid future
timestamps.
14
 */
1512
function comment_update_1() {
16
  // Change any future last comment timestamps to current time.
170
  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.
200
  if (($last = variable_get('node_cron_last', FALSE)) !== FALSE) {
210
    variable_set('node_cron_last', min(REQUEST_TIME, $last));
220
  }
23
240
  return array();
250
}
26
27
/**
28
 * @defgroup updates-5.x-to-6.x Comment updates from 5.x to 6.x
29
 * @{
30
 */
31
3212
function comment_update_6001() {
330
  $ret[] = update_sql("ALTER TABLE {comments} DROP score");
340
  $ret[] = update_sql("ALTER TABLE {comments} DROP users");
35
360
  return $ret;
370
}
38
39
/**
40
 * Changed comment settings from global to per-node -- copy global
41
 * settings to all node types.
42
 */
4312
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.
460
  drupal_load('module', 'comment');
47
  $settings = array(
480
    'comment_default_mode' => COMMENT_MODE_THREADED_EXPANDED,
490
    'comment_default_order' => COMMENT_ORDER_NEWEST_FIRST,
500
    'comment_default_per_page' => 50,
510
    'comment_controls' => COMMENT_CONTROLS_HIDDEN,
520
    'comment_anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT,
530
    'comment_subject_field' => 1,
540
    'comment_preview' => COMMENT_PREVIEW_REQUIRED,
550
    'comment_form_location' => COMMENT_FORM_SEPARATE_PAGE,
560
  );
570
  $types = node_get_types();
580
  foreach ($settings as $setting => $default) {
590
    $value = variable_get($setting, $default);
600
    foreach ($types as $type => $object) {
610
      variable_set($setting . '_' . $type, $value);
620
    }
630
    variable_del($setting);
640
  }
650
  return array(array('success' => TRUE, 'query' => 'Global comment settings
copied to all node types.'));
660
}
67
68
/**
69
 * Add index to parent ID field.
70
 */
7112
function comment_update_6003() {
720
  $ret = array();
730
  db_add_index($ret, 'comments', 'pid', array('pid'));
74
750
  return $ret;
760
}
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
 */
9112
function comment_update_7000() {
920
  $types = node_get_types();
930
  foreach ($types as $type => $object) {
940
    variable_del('comment_default_order' . $type);
950
  }
960
  return array(array('success' => TRUE, 'query' => 'Comment order settings
removed.'));
970
}
98
99
/**
100
 * Change comment status from published being 0 to being 1
101
 */
10212
function comment_update_7001() {
1030
  $ret = array();
1040
  $ret[] = update_sql("UPDATE {comments} SET status = 3 WHERE status = 0");
1050
  $ret[] = update_sql("UPDATE {comments} SET status = 0 WHERE status = 1");
1060
  $ret[] = update_sql("UPDATE {comments} SET status = 1 WHERE status = 3");
107
1080
  return $ret;
1090
}
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
 */
11912
function comment_schema() {
120134
  $schema['comments'] = array(
121134
    'description' => t('Stores comments and associated data.'),
122
    'fields' => array(
123
      'cid' => array(
124134
        'type' => 'serial',
125134
        'not null' => TRUE,
126134
        'description' => t('Primary Key: Unique comment ID.'),
127134
      ),
128
      'pid' => array(
129134
        'type' => 'int',
130134
        'not null' => TRUE,
131134
        'default' => 0,
132134
        '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.'),
133134
      ),
134
      'nid' => array(
135134
        'type' => 'int',
136134
        'not null' => TRUE,
137134
        'default' => 0,
138134
        'description' => t('The {node}.nid to which this comment is a
reply.'),
139134
      ),
140
      'uid' => array(
141134
        'type' => 'int',
142134
        'not null' => TRUE,
143134
        'default' => 0,
144134
        'description' => t('The {users}.uid who authored the comment. If
set to 0, this comment was created by an anonymous user.'),
145134
      ),
146
      'subject' => array(
147134
        'type' => 'varchar',
148134
        'length' => 64,
149134
        'not null' => TRUE,
150134
        'default' => '',
151134
        'description' => t('The comment title.'),
152134
      ),
153
      'comment' => array(
154134
        'type' => 'text',
155134
        'not null' => TRUE,
156134
        'size' => 'big',
157134
        'description' => t('The comment body.'),
158134
      ),
159
      'hostname' => array(
160134
        'type' => 'varchar',
161134
        'length' => 128,
162134
        'not null' => TRUE,
163134
        'default' => '',
164134
        'description' => t("The author's host name."),
165134
      ),
166
      'timestamp' => array(
167134
        'type' => 'int',
168134
        'not null' => TRUE,
169134
        'default' => 0,
170134
        'description' => t('The time that the comment was created, or last
edited by its author, as a Unix timestamp.'),
171134
      ),
172
      'status' => array(
173134
        'type' => 'int',
174134
        'unsigned' => TRUE,
175134
        'not null' => TRUE,
176134
        'default' => 1,
177134
        'size' => 'tiny',
178134
        'description' => t('The published status of a comment. (0 = Not
Published, 1 = Published)'),
179134
      ),
180
      'format' => array(
181134
        'type' => 'int',
182134
        'size' => 'small',
183134
        'not null' => TRUE,
184134
        'default' => 0,
185134
        'description' => t('The {filter_formats}.format of the comment
body.'),
186134
      ),
187
      'thread' => array(
188134
        'type' => 'varchar',
189134
        'length' => 255,
190134
        'not null' => TRUE,
191134
        'description' => t("The vancode representation of the comment's
place in a thread."),
192134
      ),
193
      'name' => array(
194134
        'type' => 'varchar',
195134
        'length' => 60,
196134
        'not null' => FALSE,
197134
        '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."),
198134
      ),
199
      'mail' => array(
200134
        'type' => 'varchar',
201134
        'length' => 64,
202134
        'not null' => FALSE,
203134
        '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."),
204134
      ),
205
      'homepage' => array(
206134
        'type' => 'varchar',
207134
        'length' => 255,
208134
        'not null' => FALSE,
209134
        '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
      )
211134
    ),
212
    'indexes' => array(
213134
      'pid' => array('pid'),
214134
      'nid' => array('nid'),
215
      // This index is probably unused.
216134
      'status' => array('status'),
217134
    ),
218134
    'primary key' => array('cid'),
219
  );
220
221134
  $schema['node_comment_statistics'] = array(
222134
    'description' => t('Maintains statistics of node and comments posts to
show "new" and "updated" flags.'),
223
    'fields' => array(
224
      'nid' => array(
225134
        'type' => 'int',
226134
        'unsigned' => TRUE,
227134
        'not null' => TRUE,
228134
        'default' => 0,
229134
        'description' => t('The {node}.nid for which the statistics are
compiled.'),
230134
      ),
231
      'last_comment_timestamp' => array(
232134
        'type' => 'int',
233134
        'not null' => TRUE,
234134
        'default' => 0,
235134
        'description' => t('The Unix timestamp of the last comment that was
posted within this node, from {comments}.timestamp.'),
236134
      ),
237
      'last_comment_name' => array(
238134
        'type' => 'varchar',
239134
        'length' => 60,
240134
        'not null' => FALSE,
241134
        'description' => t('The name of the latest author to post a comment
on this node, from {comments}.name.'),
242134
      ),
243
      'last_comment_uid' => array(
244134
        'type' => 'int',
245134
        'not null' => TRUE,
246134
        'default' => 0,
247134
        'description' => t('The user ID of the latest author to post a
comment on this node, from {comments}.uid.'),
248134
      ),
249
      'comment_count' => array(
250134
        'type' => 'int',
251134
        'unsigned' => TRUE,
252134
        'not null' => TRUE,
253134
        'default' => 0,
254134
        'description' => t('The total number of comments on this node.'),
255134
      ),
256134
    ),
257134
    'primary key' => array('nid'),
258
    'indexes' => array(
259134
      'node_comment_timestamp' => array('last_comment_timestamp'),
260134
    ),
261
  );
262
263134
  return $schema;
2640
}
26512