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

Line #Times calledCode
1
<?php
2
// $Id: comment.install,v 1.24 2008/08/02 20:29:43 dries Exp $
3
4
/**
5
 * Implementation of hook_enable().
6
 */
780
function comment_enable() {
8
  // Insert records into the node_comment_statistics for nodes that are
missing.
962
  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");
1062
}
11
12
/**
13
 * Changed node_comment_statistics to use node->changed to avoid future
timestamps.
14
 */
1580
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', time(), 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(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
3280
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
 */
4380
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
 */
7180
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
 */
9180
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
 */
10280
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
 */
11980
function comment_schema() {
12077
  $schema['comments'] = array(
12177
    'description' => t('Stores comments and associated data.'),
122
    'fields' => array(
123
      'cid' => array(
12477
        'type' => 'serial',
12577
        'not null' => TRUE,
12677
        'description' => t('Primary Key: Unique comment ID.'),
12777
      ),
128
      'pid' => array(
12977
        'type' => 'int',
13077
        'not null' => TRUE,
13177
        'default' => 0,
13277
        '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.'),
13377
      ),
134
      'nid' => array(
13577
        'type' => 'int',
13677
        'not null' => TRUE,
13777
        'default' => 0,
13877
        'description' => t('The {node}.nid to which this comment is a
reply.'),
13977
      ),
140
      'uid' => array(
14177
        'type' => 'int',
14277
        'not null' => TRUE,
14377
        'default' => 0,
14477
        'description' => t('The {users}.uid who authored the comment. If
set to 0, this comment was created by an anonymous user.'),
14577
      ),
146
      'subject' => array(
14777
        'type' => 'varchar',
14877
        'length' => 64,
14977
        'not null' => TRUE,
15077
        'default' => '',
15177
        'description' => t('The comment title.'),
15277
      ),
153
      'comment' => array(
15477
        'type' => 'text',
15577
        'not null' => TRUE,
15677
        'size' => 'big',
15777
        'description' => t('The comment body.'),
15877
      ),
159
      'hostname' => array(
16077
        'type' => 'varchar',
16177
        'length' => 128,
16277
        'not null' => TRUE,
16377
        'default' => '',
16477
        'description' => t("The author's host name."),
16577
      ),
166
      'timestamp' => array(
16777
        'type' => 'int',
16877
        'not null' => TRUE,
16977
        'default' => 0,
17077
        'description' => t('The time that the comment was created, or last
edited by its author, as a Unix timestamp.'),
17177
      ),
172
      'status' => array(
17377
        'type' => 'int',
17477
        'unsigned' => TRUE,
17577
        'not null' => TRUE,
17677
        'default' => 1,
17777
        'size' => 'tiny',
17877
        'description' => t('The published status of a comment. (0 = Not
Published, 1 = Published)'),
17977
      ),
180
      'format' => array(
18177
        'type' => 'int',
18277
        'size' => 'small',
18377
        'not null' => TRUE,
18477
        'default' => 0,
18577
        'description' => t('The {filter_formats}.format of the comment
body.'),
18677
      ),
187
      'thread' => array(
18877
        'type' => 'varchar',
18977
        'length' => 255,
19077
        'not null' => TRUE,
19177
        'description' => t("The vancode representation of the comment's
place in a thread."),
19277
      ),
193
      'name' => array(
19477
        'type' => 'varchar',
19577
        'length' => 60,
19677
        'not null' => FALSE,
19777
        '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."),
19877
      ),
199
      'mail' => array(
20077
        'type' => 'varchar',
20177
        'length' => 64,
20277
        'not null' => FALSE,
20377
        '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."),
20477
      ),
205
      'homepage' => array(
20677
        'type' => 'varchar',
20777
        'length' => 255,
20877
        'not null' => FALSE,
20977
        '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
      )
21177
    ),
212
    'indexes' => array(
21377
      'pid' => array('pid'),
21477
      'nid' => array('nid'),
215
      // This index is probably unused.
21677
      'status' => array('status'),
21777
    ),
21877
    'primary key' => array('cid'),
219
  );
220
22177
  $schema['node_comment_statistics'] = array(
22277
    'description' => t('Maintains statistics of node and comments posts to
show "new" and "updated" flags.'),
223
    'fields' => array(
224
      'nid' => array(
22577
        'type' => 'int',
22677
        'unsigned' => TRUE,
22777
        'not null' => TRUE,
22877
        'default' => 0,
22977
        'description' => t('The {node}.nid for which the statistics are
compiled.'),
23077
      ),
231
      'last_comment_timestamp' => array(
23277
        'type' => 'int',
23377
        'not null' => TRUE,
23477
        'default' => 0,
23577
        'description' => t('The Unix timestamp of the last comment that was
posted within this node, from {comments}.timestamp.'),
23677
      ),
237
      'last_comment_name' => array(
23877
        'type' => 'varchar',
23977
        'length' => 60,
24077
        'not null' => FALSE,
24177
        'description' => t('The name of the latest author to post a comment
on this node, from {comments}.name.'),
24277
      ),
243
      'last_comment_uid' => array(
24477
        'type' => 'int',
24577
        'not null' => TRUE,
24677
        'default' => 0,
24777
        'description' => t('The user ID of the latest author to post a
comment on this node, from {comments}.uid.'),
24877
      ),
249
      'comment_count' => array(
25077
        'type' => 'int',
25177
        'unsigned' => TRUE,
25277
        'not null' => TRUE,
25377
        'default' => 0,
25477
        'description' => t('The total number of comments on this node.'),
25577
      ),
25677
    ),
25777
    'primary key' => array('nid'),
258
    'indexes' => array(
25977
      'node_comment_timestamp' => array('last_comment_timestamp'),
26077
    ),
261
  );
262
26377
  return $schema;
2640
}
26580