? 8389 ? Unsaved Document 1 ? cache_42_0.patch ? cache_get_multiple-333171-39.patch.1 ? cache_get_multiple-333171-39.patch.2 ? cache_shutdown.patch ? cache_shutdown.png ? comment.diff ? comment_load_multiple.patch ? comment_load_multiple.patch.1 ? comment_paging_24.patch.1 ? comment_paging_24.patch.2 ? comment_paging_7.patch.1 ? comments.png ? comments_as_tab.patch ? comments_as_tab.patch.1 ? comments_as_tab_0.patch ? content.png ? d7.sql ? d7ux_header_jun14.tar ? diff.txt ? drupal-split-total2.patch.1 ? enable_search.patch ? fieldset.png ? hide_operations_0.patch ? link.png ? menu.module_12.patch ? menu_empty_text1.patch ? modules (2) ? no-link.png ? panels.patch ? registry.png ? remove_primary_secondary.patch ? search_index_content.patch ? search_index_content.patch.1 ? semantic_but_ugly.png ? taxonomy_term.patch ? taxonomy_term.patch.1 ? uninstall.patch ? user_modules_uninstalled.patch ? user_modules_uninstalled_0.patch ? user_modules_uninstalled_with_tests_9.patch ? misc/operations.js ? modules/comments_as_tab.patch ? modules/comment/.comment.test.rej.swp ? modules/comment/comment_paging.patch ? modules/field/field.autoload.inc ? modules/system/system.actions.inc ? modules/system/system.autoload.inc ? modules/system/system.block.inc ? modules/system/system.build.inc ? modules/system/system.cron.inc ? modules/system/system.file.inc ? modules/system/system.form.inc ? modules/system/system.mail.inc ? modules/system/system.registry.inc ? modules/system/system.update ? modules/user/user.autoload.inc ? scripts/generate-autoload.pl ? scripts/generate-autoload.sh ? sites/all/modules/contrib ? sites/default/files ? sites/default/settings.php ? sites/default/settings.php.back Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.729 diff -u -p -r1.729 comment.module --- modules/comment/comment.module 27 Jun 2009 10:13:28 -0000 1.729 +++ modules/comment/comment.module 28 Jun 2009 02:07:22 -0000 @@ -1147,22 +1147,9 @@ function comment_render($node, $cid = 0) $comments_per_page = _comment_get_display_setting('comments_per_page', $node); if ($cid && is_numeric($cid)) { + $comment = current(comment_load_multiple(array('cid' => $cid, 'status' => COMMENT_PUBLISHED))); // Single comment view. - $query = db_select('comment', 'c'); - $query->addField('u', 'name', 'registered_name'); - $query->innerJoin('users', 'u', 'c.uid = u.uid'); - $query - ->fields('c', array('cid', 'nid', 'pid', 'comment', 'subject', 'format', 'timestamp', 'name', 'mail', 'homepage', 'status')) - ->fields('u', array( 'uid', 'signature', 'picture', 'data', 'status')) - ->condition('c.cid', $cid); - - if (!user_access('administer comments')) { - $query->condition('c.status', COMMENT_PUBLISHED); - } - - $result = $query->execute(); - - if ($comment = $result->fetchObject()) { + if ($comment) { $comment->name = $comment->uid ? $comment->registered_name : $comment->name; $links = module_invoke_all('link', 'comment', $comment, 1); drupal_alter('link', $links, $node); @@ -1177,11 +1164,8 @@ function comment_render($node, $cid = 0) // Multiple comment view. $query = db_select('comment', 'c')->extend('PagerDefault'); - $query->join('users', 'u', 'c.uid = u.uid'); - $query->addField('u', 'name', 'registered_name'); + $query->addField('c', 'cid'); $query - ->fields('c', array('cid', 'pid', 'nid', 'subject', 'comment', 'format', 'timestamp', 'name', 'mail', 'homepage', 'thread', 'status')) - ->fields('u', array('uid', 'signature', 'picture', 'data')) ->condition('c.nid', $nid) ->addTag('node_access') ->limit($comments_per_page); @@ -1207,13 +1191,14 @@ function comment_render($node, $cid = 0) } $query->setCountQuery($count_query); - $result = $query->execute(); + $cids = $query->execute()->fetchCol(); $divs = 0; $num_rows = FALSE; - $comments = ''; + $render = ''; + $comments = comment_load_multiple($cids); drupal_add_css(drupal_get_path('module', 'comment') . '/comment.css'); - foreach ($result as $comment) { + foreach ($comments as $comment) { $comment = drupal_unpack($comment); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; $comment->depth = count(explode('.', $comment->thread)) - 1; @@ -1221,34 +1206,34 @@ function comment_render($node, $cid = 0) if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) { if ($comment->depth > $divs) { $divs++; - $comments .= '
'; + $render .= '
'; } else { while ($comment->depth < $divs) { $divs--; - $comments .= '
'; + $render .= '
'; } } } if ($mode == COMMENT_MODE_FLAT_COLLAPSED) { - $comments .= theme('comment_flat_collapsed', $comment, $node); + $render .= theme('comment_flat_collapsed', $comment, $node); } elseif ($mode == COMMENT_MODE_FLAT_EXPANDED) { - $comments .= theme('comment_flat_expanded', $comment, $node); + $render .= theme('comment_flat_expanded', $comment, $node); } elseif ($mode == COMMENT_MODE_THREADED_COLLAPSED) { - $comments .= theme('comment_thread_collapsed', $comment, $node); + $render .= theme('comment_thread_collapsed', $comment, $node); } elseif ($mode == COMMENT_MODE_THREADED_EXPANDED) { - $comments .= theme('comment_thread_expanded', $comment, $node); + $render .= theme('comment_thread_expanded', $comment, $node); } $num_rows = TRUE; } while ($divs-- > 0) { - $comments .= ''; + $render .= ''; } - $output .= $comments; + $output .= $render; $output .= theme('pager', NULL); } @@ -1299,8 +1284,47 @@ function comment_operations($action = NU } /** - * Begin the misc functions: helpers, privates, history. + * Load comments from the database. + * + * @param $cids + * An array of comment IDs. + * @param $conditions + * An array of conditions to match against the {comments} table. These + * should be supplied in the form array('field_name' => 'field_value'). + * @return + * An array of comment objects, indexed by comment ID. */ +function comment_load_multiple($cids = array(), $conditions = array()) { + $query = db_select('comment', 'c'); + $query->innerJoin('users', 'u', 'c.uid = u.uid'); + $query->addField('u', 'name', 'registered_name'); + $query + ->fields('c', array('cid', 'nid', 'pid', 'comment', 'subject', 'format', 'timestamp', 'name', 'mail', 'homepage', 'status', 'thread')) + ->fields('u', array( 'uid', 'signature', 'picture', 'data', 'status')); + + // If the $fids array is populated, add those to the query. + if ($cids) { + $query->condition('c.cid', $cids, 'IN'); + } + + // If the conditions array is populated, add those to the query. + if ($conditions) { + foreach ($conditions as $field => $value) { + $query->condition('c.' . $field, $value); + } + } + $comments = $query->execute()->fetchAllAssoc('cid'); + + // Invoke hook_comment_load() on the comments loaded from the database. + if (!empty($files)) { + foreach (module_implements('comment_load') as $module) { + $function = $module . '_comment_load'; + $function($comments); + } + } + return $comments; +} + /** * Load the entire comment by cid. @@ -1311,7 +1335,7 @@ function comment_operations($action = NU * The comment object. */ function comment_load($cid) { - return db_query('SELECT * FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchObject(); + return reset(comment_load_multiple(array($cid))); } /** Index: modules/comment/comment.test =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v retrieving revision 1.34 diff -u -p -r1.34 comment.test --- modules/comment/comment.test 27 Jun 2009 10:13:28 -0000 1.34 +++ modules/comment/comment.test 28 Jun 2009 02:07:23 -0000 @@ -342,6 +342,7 @@ class CommentInterfaceTest extends Comme $this->drupalGet('node/' . $this->node->nid); $this->assertFalse($this->commentExists($comment), t('Comment not found.')); $this->assertFalse($this->commentExists($reply, TRUE), t('Reply not found.')); + $this->assertFalse(db_query('SELECT cid FROM comment WHERE cid = :cid', array(':cid' => $reply->id))->fetchField()); // Enabled comment form on node page. $this->drupalLogin($this->admin_user);