[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/modules/comment/ -> comment.install (source)

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7