web/drupal/modules/comment/comment.install
branchdrupal
changeset 74 0ff3ba646492
equal deleted inserted replaced
73:fcf75e232c5b 74:0ff3ba646492
       
     1 <?php
       
     2 // $Id: comment.install,v 1.19.2.1 2009/01/06 15:46:36 goba 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   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     'description' => 'Stores comments and associated data.',
       
    77     'fields' => array(
       
    78       'cid' => array(
       
    79         'type' => 'serial',
       
    80         'not null' => TRUE,
       
    81         'description' => 'Primary Key: Unique comment ID.',
       
    82       ),
       
    83       'pid' => array(
       
    84         'type' => 'int',
       
    85         'not null' => TRUE,
       
    86         'default' => 0,
       
    87         '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.',
       
    88       ),
       
    89       'nid' => array(
       
    90         'type' => 'int',
       
    91         'not null' => TRUE,
       
    92         'default' => 0,
       
    93         'description' => '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' => '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' => 'The comment title.',
       
   107       ),
       
   108       'comment' => array(
       
   109         'type' => 'text',
       
   110         'not null' => TRUE,
       
   111         'size' => 'big',
       
   112         'description' => 'The comment body.',
       
   113       ),
       
   114       'hostname' => array(
       
   115         'type' => 'varchar',
       
   116         'length' => 128,
       
   117         'not null' => TRUE,
       
   118         'default' => '',
       
   119         'description' => "The author's host name.",
       
   120       ),
       
   121       'timestamp' => array(
       
   122         'type' => 'int',
       
   123         'not null' => TRUE,
       
   124         'default' => 0,
       
   125         'description' => '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' => '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' => 'The {filter_formats}.format of the comment body.',
       
   141       ),
       
   142       'thread' => array(
       
   143         'type' => 'varchar',
       
   144         'length' => 255,
       
   145         'not null' => TRUE,
       
   146         'description' => "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' => "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' => "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' => "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       'status' => array('status'), // This index is probably unused
       
   171     ),
       
   172     'primary key' => array('cid'),
       
   173   );
       
   174 
       
   175   $schema['node_comment_statistics'] = array(
       
   176     'description' => 'Maintains statistics of node and comments posts to show "new" and "updated" flags.',
       
   177     'fields' => array(
       
   178       'nid' => array(
       
   179         'type' => 'int',
       
   180         'unsigned' => TRUE,
       
   181         'not null' => TRUE,
       
   182         'default' => 0,
       
   183         'description' => 'The {node}.nid for which the statistics are compiled.',
       
   184       ),
       
   185       'last_comment_timestamp' => array(
       
   186         'type' => 'int',
       
   187         'not null' => TRUE,
       
   188         'default' => 0,
       
   189         'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comments}.timestamp.',
       
   190       ),
       
   191       'last_comment_name' => array(
       
   192         'type' => 'varchar',
       
   193         'length' => 60,
       
   194         'not null' => FALSE,
       
   195         'description' => 'The name of the latest author to post a comment on this node, from {comments}.name.',
       
   196       ),
       
   197       'last_comment_uid' => array(
       
   198         'type' => 'int',
       
   199         'not null' => TRUE,
       
   200         'default' => 0,
       
   201         'description' => 'The user ID of the latest author to post a comment on this node, from {comments}.uid.',
       
   202       ),
       
   203       'comment_count' => array(
       
   204         'type' => 'int',
       
   205         'unsigned' => TRUE,
       
   206         'not null' => TRUE,
       
   207         'default' => 0,
       
   208         'description' => 'The total number of comments on this node.',
       
   209       ),
       
   210     ),
       
   211     'primary key' => array('nid'),
       
   212     'indexes' => array(
       
   213       'node_comment_timestamp' => array('last_comment_timestamp')
       
   214     ),
       
   215   );
       
   216 
       
   217   return $schema;
       
   218 }
       
   219