diff --git a/modules/comment/comment.admin.inc b/modules/comment/comment.admin.inc index 07e19c7a3df65c03ec0d54f4c7393b2094ef08fa..150d0f71b050752a65ad63e350c62e542325bdd8 100644 --- a/modules/comment/comment.admin.inc +++ b/modules/comment/comment.admin.inc @@ -62,7 +62,7 @@ function comment_admin_overview($form, &$form_state, $arg) { 'subject' => array('data' => t('Subject'), 'field' => 'subject'), 'author' => array('data' => t('Author'), 'field' => 'name'), 'posted_in' => array('data' => t('Posted in'), 'field' => 'node_title'), - 'time' => array('data' => t('Time'), 'field' => 'timestamp', 'sort' => 'desc'), + 'changed' => array('data' => t('Updated'), 'field' => 'changed', 'sort' => 'desc'), 'operations' => array('data' => t('Operations')), ); @@ -72,7 +72,7 @@ function comment_admin_overview($form, &$form_state, $arg) { $query->addField('u', 'name', 'registered_name'); $query->addField('n', 'title', 'node_title'); $result = $query - ->fields('c', array('subject', 'nid', 'cid', 'comment', 'timestamp', 'status', 'name', 'homepage')) + ->fields('c', array('subject', 'nid', 'cid', 'comment', 'changed', 'status', 'name', 'homepage')) ->fields('u', array('uid')) ->condition('c.status', $status) ->limit(50) @@ -89,7 +89,7 @@ function comment_admin_overview($form, &$form_state, $arg) { 'subject' => l($comment->subject, 'comment/' . $comment->cid, array('attributes' => array('title' => truncate_utf8($comment->comment, 128)), 'fragment' => 'comment-' . $comment->cid)), 'author' => theme('username', array('account' => $comment)), 'posted_in' => l($comment->node_title, 'node/' . $comment->nid), - 'time' => format_date($comment->timestamp, 'short'), + 'changed' => format_date($comment->changed, 'short'), 'operations' => l(t('edit'), 'comment/edit/' . $comment->cid, array('query' => $destination)), ); } diff --git a/modules/comment/comment.api.php b/modules/comment/comment.api.php index d7a1ef2c789682e1cc94597582ee95b9c7611132..104562e34c1af2702334ee3f8e5f3bbf65766862 100644 --- a/modules/comment/comment.api.php +++ b/modules/comment/comment.api.php @@ -69,7 +69,7 @@ function hook_comment_load($comments) { */ function hook_comment_view($comment) { // how old is the comment - $comment->time_ago = time() - $comment->timestamp; + $comment->time_ago = time() - $comment->changed; } /** diff --git a/modules/comment/comment.install b/modules/comment/comment.install index 300534544345cf3c520e1315fcb88186ad69a8c2..c5d78e1b3a2261519abd83a47ee9acf6b97d67d5 100644 --- a/modules/comment/comment.install +++ b/modules/comment/comment.install @@ -129,6 +129,35 @@ function comment_update_7006() { db_add_index('node_comment_statistics', 'last_comment_uid', array('last_comment_uid')); } +/** + * Split {comment}.timestamp into {comment}.created and {comment}.changed. + */ +function comment_update_7007() { + // Drop the index associated to timestamp. + db_drop_index('comment', 'comment_num_new'); + + // Create a created column. + db_add_field('comment', 'created', array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + )); + + // Rename the timestamp column to changed. + db_change_field('comment', 'timestamp', 'changed', array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + )); + + // Recreate the index. + db_add_index('comment', 'comment_num_new', array('nid', 'changed', 'status')); + + // Migrate the data. + // @todo db_update() should support this. + db_query('UPDATE {comment} SET created = changed'); +} + /** * @} End of "defgroup updates-6.x-to-7.x" * The next series of updates should start at 8000. @@ -184,11 +213,17 @@ function comment_schema() { 'default' => '', 'description' => "The author's host name.", ), - 'timestamp' => array( + 'created' => array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + 'description' => 'The time that the comment was created, as a Unix timestamp.', + ), + 'changed' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, - 'description' => 'The time that the comment was created, or last edited by its author, as a Unix timestamp.', + 'description' => 'The time that the comment was last edited, as a Unix timestamp.', ), 'status' => array( 'type' => 'int', @@ -232,7 +267,7 @@ function comment_schema() { ), 'indexes' => array( 'comment_status_pid' => array('pid', 'status'), - 'comment_num_new' => array('nid', 'timestamp', 'status'), + 'comment_num_new' => array('nid', 'changed', 'status'), 'comment_uid' => array('uid'), ), 'primary key' => array('cid'), @@ -291,4 +326,4 @@ function comment_schema() { ); return $schema; -} \ No newline at end of file +} diff --git a/modules/comment/comment.module b/modules/comment/comment.module index ea28d541756220cbe1e7530783dcc76a8e0188bd..88795e6861987ba43d0e83f16c95ffed7119dd36 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -382,9 +382,9 @@ function comment_permalink($comment) { * @param integer $number * (optional) The maximum number of comments to find. * @return - * An array of comment objects each containing a nid, - * subject, cid, and timestamp, or an empty array if there are no recent - * comments visible to the current user. + * An array of comment objects each containing a nid, subject, cid, created + * and changed, or an empty array if there are no recent comments visible + * to the current user. */ function comment_get_recent($number = 10) { // Step 1: Select a $number of nodes which have new comments, @@ -399,7 +399,7 @@ function comment_get_recent($number = 10) { $query = db_select('comment', 'c'); $query->innerJoin('node', 'n', 'n.nid = c.nid'); return $query - ->fields('c', array('nid', 'subject', 'cid', 'timestamp')) + ->fields('c', array('nid', 'subject', 'cid', 'created', 'changed')) ->condition('c.nid', $nids, 'IN') ->condition('c.status', COMMENT_PUBLISHED) ->condition('n.status', 1) @@ -445,7 +445,7 @@ function comment_new_page_count($num_comments, $new_replies, $node) { FROM {comment} WHERE nid = :nid AND status = 0 - ORDER BY timestamp DESC) AS thread + ORDER BY changed DESC) AS thread ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1))', 0, $new_replies, array(':nid' => $node->nid))->fetchField(); $thread = substr($result, 0, -1); $count = db_query('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND status = 0 AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array( @@ -473,7 +473,7 @@ function theme_comment_block() { $items = array(); $number = variable_get('comment_block_count', 10); foreach (comment_get_recent($number) as $comment) { - $items[] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)) . '<br />' . t('@time ago', array('@time' => format_interval(REQUEST_TIME - $comment->timestamp))); + $items[] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)) . '<br />' . t('@time ago', array('@time' => format_interval(REQUEST_TIME - $comment->changed))); } if ($items) { @@ -1277,7 +1277,8 @@ function comment_save($comment) { db_update('comment') ->fields(array( 'status' => $comment->status, - 'timestamp' => $comment->timestamp, + 'created' => $comment->created, + 'changed' => $comment->changed, 'subject' => $comment->subject, 'comment' => $comment->comment, 'format' => $comment->comment_format, @@ -1336,8 +1337,12 @@ function comment_save($comment) { } } - if (empty($comment->timestamp)) { - $comment->timestamp = REQUEST_TIME; + if (empty($comment->created)) { + $comment->created = REQUEST_TIME; + } + + if (empty($comment->changed)) { + $comment->changed = $comment->created; } if ($comment->uid === $user->uid && isset($user->name)) { // '===' Need to modify anonymous users as well. @@ -1353,7 +1358,8 @@ function comment_save($comment) { 'comment' => $comment->comment, 'format' => $comment->comment_format, 'hostname' => ip_address(), - 'timestamp' => $comment->timestamp, + 'created' => $comment->created, + 'changed' => $comment->changed, 'status' => $comment->status, 'thread' => $thread, 'name' => $comment->name, @@ -1501,7 +1507,7 @@ protected function attachLoad(&$comments) { foreach ($comments as $key => $comment) { $comment = drupal_unpack($comment); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; - $comment->new = node_mark($comment->nid, $comment->timestamp); + $comment->new = node_mark($comment->nid, $comment->changed); $comment->node_type = 'comment_node_' . $comment->node_type; $comments[$key] = $comment; } @@ -1550,9 +1556,9 @@ function comment_num_new($nid, $timestamp = 0) { $timestamp = ($timestamp > NODE_NEW_LIMIT ? $timestamp : NODE_NEW_LIMIT); // Use the timestamp to retrieve the number of new comments. - return db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND timestamp > :timestamp AND status = :status', array( + return db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND changed > :changed AND status = :status', array( ':nid' => $nid, - ':timestamp' => $timestamp, + ':changed' => $timestamp, ':status' => COMMENT_PUBLISHED, ))->fetchField(); } @@ -1676,7 +1682,7 @@ function comment_form($form, &$form_state, $comment) { $date = $comment->date; } else { - $date = format_date($comment->timestamp, 'custom', 'Y-m-d H:i O'); + $date = format_date($comment->changed, 'custom', 'Y-m-d H:i O'); } $form['admin'] = array( @@ -1921,7 +1927,8 @@ function comment_preview($comment) { $comment->name = variable_get('anonymous', t('Anonymous')); } - $comment->timestamp = !empty($comment->timestamp) ? $comment->timestamp : REQUEST_TIME; + $comment->created = !empty($comment->created) ? $comment->created : REQUEST_TIME; + $comment->changed = REQUEST_TIME; $comment->in_preview = TRUE; $comment_build = comment_build($comment, $node); $comment_build += array( @@ -2017,7 +2024,9 @@ function comment_submit($comment) { $comment['date'] = 'now'; } - $comment['timestamp'] = strtotime($comment['date']); + $comment['created'] = strtotime($comment['date']); + $comment['changed'] = REQUEST_TIME; + if (isset($comment['author'])) { $account = user_load_by_name($comment['author']); $comment['uid'] = $account->uid; @@ -2105,7 +2114,9 @@ function template_preprocess_comment(&$variables) { $variables['comment'] = $comment; $variables['node'] = $node; $variables['author'] = theme('username', array('account' => $comment)); - $variables['date'] = format_date($comment->timestamp); + $variables['created'] = format_date($comment->created); + $variables['changed'] = format_date($comment->changed); + $variables['new'] = !empty($comment->new) ? t('new') : ''; $variables['picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', array('account' => $comment)) : ''; $variables['signature'] = $comment->signature; @@ -2237,14 +2248,14 @@ function _comment_update_node_statistics($nid) { if ($count > 0) { // Comments exist. - $last_reply = db_query_range('SELECT cid, name, timestamp, uid FROM {comment} WHERE nid = :nid AND status = :status ORDER BY cid DESC', 0, 1, array( + $last_reply = db_query_range('SELECT cid, name, changed, uid FROM {comment} WHERE nid = :nid AND status = :status ORDER BY cid DESC', 0, 1, array( ':nid' => $nid, ':status' => COMMENT_PUBLISHED, ))->fetchObject(); db_update('node_comment_statistics') ->fields( array( 'comment_count' => $count, - 'last_comment_timestamp' => $last_reply->timestamp, + 'last_comment_timestamp' => $last_reply->changed, 'last_comment_name' => $last_reply->uid ? '' : $last_reply->name, 'last_comment_uid' => $last_reply->uid, )) diff --git a/modules/comment/comment.tokens.inc b/modules/comment/comment.tokens.inc index 05b060a6a402ba9d0b174fc7ee2c12261a1794a4..3f5590ee6dfa81182938f9df342a3778acff9896 100644 --- a/modules/comment/comment.tokens.inc +++ b/modules/comment/comment.tokens.inc @@ -200,7 +200,11 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = break; case 'created': - $replacements[$original] = format_date($comment->timestamp, 'medium', '', NULL, $language_code); + $replacements[$original] = format_date($comment->created, 'medium', '', NULL, $language_code); + break; + + case 'changed': + $replacements[$original] = format_date($comment->changed, 'medium', '', NULL, $language_code); break; case 'node': @@ -217,7 +221,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = } if ($date_tokens = token_find_with_prefix($tokens, 'created')) { - $replacements += token_generate('date', $date_tokens, array('date' => $comment->timestamp), $options); + $replacements += token_generate('date', $date_tokens, array('date' => $comment->created), $options); } if (($parent_tokens = token_find_with_prefix($tokens, 'parent')) && $parent = comment_load($comment->pid)) { diff --git a/modules/comment/comment.tpl.php b/modules/comment/comment.tpl.php index e777855906e865255c9e1e343c7d308c0db1fffe..7b489aadec5da1e3a4c43342eb02cb628f13d6a9 100644 --- a/modules/comment/comment.tpl.php +++ b/modules/comment/comment.tpl.php @@ -11,7 +11,8 @@ * print a subset such as render($content['field_example']). Use * hide($content['field_example']) to temporarily suppress the printing of a * given element. - * - $date: Date and time of posting. + * - $created: Date and time this comment was created. + * - $changed: Date and time this comment was changed. * - $new: New comment marker. * - $picture: Authors picture. * - $signature: Authors signature. @@ -56,7 +57,7 @@ <div class="submitted"> <?php print t('Submitted by !username on @datetime.', - array('!username' => $author, '@datetime' => $date)); + array('!username' => $author, '@datetime' => $created)); ?> </div> diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module index e80e2f41e18d5c3906c0310b81303245696a358b..88f5dbddc6750e35dc7ae2f54d8758c064d0afd0 100644 --- a/modules/tracker/tracker.module +++ b/modules/tracker/tracker.module @@ -198,21 +198,21 @@ function tracker_comment_update($comment) { * comment_save() calls hook_comment_publish() for all published comments. */ function tracker_comment_publish($comment) { - _tracker_add($comment->nid, $comment->uid, $comment->timestamp); + _tracker_add($comment->nid, $comment->uid, $comment->changed); } /** * Implement hook_comment_unpublish(). */ function tracker_comment_unpublish($comment) { - _tracker_remove($comment->nid, $comment->uid, $comment->timestamp); + _tracker_remove($comment->nid, $comment->uid, $comment->changed); } /** * Implement hook_comment_delete(). */ function tracker_comment_delete($comment) { - _tracker_remove($comment->nid, $comment->uid, $comment->timestamp); + _tracker_remove($comment->nid, $comment->uid, $comment->changed); } /** @@ -266,12 +266,12 @@ function _tracker_add($nid, $uid, $changed) { */ function _tracker_calculate_changed($nid) { $changed = db_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField(); - $latest_comment = db_query_range('SELECT cid, timestamp FROM {comment} WHERE nid = :nid AND status = :status ORDER BY timestamp DESC', 0, 1, array( + $latest_comment = db_query_range('SELECT cid, changed FROM {comment} WHERE nid = :nid AND status = :status ORDER BY changed DESC', 0, 1, array( ':nid' => $nid, ':status' => COMMENT_PUBLISHED, ))->fetchObject(); - if ($latest_comment && $latest_comment->timestamp > $changed) { - $changed = $latest_comment->timestamp; + if ($latest_comment && $latest_comment->changed > $changed) { + $changed = $latest_comment->changed; } return $changed; } diff --git a/themes/garland/comment.tpl.php b/themes/garland/comment.tpl.php index 9a8959cc56172fa6304bf5d3a3ede025ca03cb53..dae3d1584aacb166ff22d7fdeb30cb1c0657f725 100644 --- a/themes/garland/comment.tpl.php +++ b/themes/garland/comment.tpl.php @@ -5,7 +5,7 @@ <div class="clearfix"> - <span class="submitted"><?php print $date; ?> — <?php print $author; ?></span> + <span class="submitted"><?php print $created; ?> — <?php print $author; ?></span> <?php if ($new) : ?> <span class="new"><?php print drupal_ucfirst($new) ?></span>