Issue #2346119 by marvil07, roderik: Fix call to undefined method Select::setCountQuery()

8.0.x
Alex Pott 2015-02-21 14:31:45 +00:00
parent 2af2fb45f4
commit 78664846f9
2 changed files with 30 additions and 21 deletions

View File

@ -264,13 +264,6 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
*/ */
public function loadThread(EntityInterface $entity, $field_name, $mode, $comments_per_page = 0, $pager_id = 0) { public function loadThread(EntityInterface $entity, $field_name, $mode, $comments_per_page = 0, $pager_id = 0) {
$query = $this->database->select('comment_field_data', 'c'); $query = $this->database->select('comment_field_data', 'c');
if ($comments_per_page) {
$query = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')
->limit($comments_per_page);
if ($pager_id) {
$query->element($pager_id);
}
}
$query->addField('c', 'cid'); $query->addField('c', 'cid');
$query $query
->condition('c.entity_id', $entity->id()) ->condition('c.entity_id', $entity->id())
@ -283,22 +276,33 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
->addMetaData('entity', $entity) ->addMetaData('entity', $entity)
->addMetaData('field_name', $field_name); ->addMetaData('field_name', $field_name);
$count_query = $this->database->select('comment_field_data', 'c'); if ($comments_per_page) {
$count_query->addExpression('COUNT(*)'); $query = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')
$count_query ->limit($comments_per_page);
->condition('c.entity_id', $entity->id()) if ($pager_id) {
->condition('c.entity_type', $entity->getEntityTypeId()) $query->element($pager_id);
->condition('c.field_name', $field_name) }
->condition('c.default_langcode', 1)
->addTag('entity_access') $count_query = $this->database->select('comment_field_data', 'c');
->addTag('comment_filter') $count_query->addExpression('COUNT(*)');
->addMetaData('base_table', 'comment') $count_query
->addMetaData('entity', $entity) ->condition('c.entity_id', $entity->id())
->addMetaData('field_name', $field_name); ->condition('c.entity_type', $entity->getEntityTypeId())
->condition('c.field_name', $field_name)
->condition('c.default_langcode', 1)
->addTag('entity_access')
->addTag('comment_filter')
->addMetaData('base_table', 'comment')
->addMetaData('entity', $entity)
->addMetaData('field_name', $field_name);
$query->setCountQuery($count_query);
}
if (!$this->currentUser->hasPermission('administer comments')) { if (!$this->currentUser->hasPermission('administer comments')) {
$query->condition('c.status', CommentInterface::PUBLISHED); $query->condition('c.status', CommentInterface::PUBLISHED);
$count_query->condition('c.status', CommentInterface::PUBLISHED); if ($comments_per_page) {
$count_query->condition('c.status', CommentInterface::PUBLISHED);
}
} }
if ($mode == CommentManagerInterface::COMMENT_MODE_FLAT) { if ($mode == CommentManagerInterface::COMMENT_MODE_FLAT) {
$query->orderBy('c.cid', 'ASC'); $query->orderBy('c.cid', 'ASC');
@ -311,7 +315,6 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
$query->orderBy('torder', 'ASC'); $query->orderBy('torder', 'ASC');
} }
$query->setCountQuery($count_query);
$cids = $query->execute()->fetchCol(); $cids = $query->execute()->fetchCol();
$comments = array(); $comments = array();

View File

@ -86,6 +86,12 @@ class CommentPagerTest extends CommentTestBase {
$this->drupalGet('node/' . $node->id(), array('query' => array('page' => 0))); $this->drupalGet('node/' . $node->id(), array('query' => array('page' => 0)));
$this->assertFalse($this->commentExists($reply2, TRUE), 'In threaded mode where # replies > # comments per page, the newest reply does not appear on page 1.'); $this->assertFalse($this->commentExists($reply2, TRUE), 'In threaded mode where # replies > # comments per page, the newest reply does not appear on page 1.');
// Test that the page build process does not somehow generate errors when
// # comments per page is set to 0.
$this->setCommentsPerPage(0);
$this->drupalGet('node/' . $node->id(), array('query' => array('page' => 0)));
$this->assertFalse($this->commentExists($reply2, TRUE), 'Threaded mode works correctly when comments per page is 0.');
$this->drupalLogout(); $this->drupalLogout();
} }