Commit 78664846 authored by Alex Pott's avatar Alex Pott
Browse files

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

parent 2af2fb45
Loading
Loading
Loading
Loading
+11 −8
Changes for core/modules/comment/src/CommentStorage.php: 11 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -264,13 +264,6 @@ public function getChildCids(array $comments) {
   */
  public function loadThread(EntityInterface $entity, $field_name, $mode, $comments_per_page = 0, $pager_id = 0) {
    $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
      ->condition('c.entity_id', $entity->id())
@@ -283,6 +276,13 @@ public function loadThread(EntityInterface $entity, $field_name, $mode, $comment
      ->addMetaData('entity', $entity)
      ->addMetaData('field_name', $field_name);

    if ($comments_per_page) {
      $query = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')
        ->limit($comments_per_page);
      if ($pager_id) {
        $query->element($pager_id);
      }

      $count_query = $this->database->select('comment_field_data', 'c');
      $count_query->addExpression('COUNT(*)');
      $count_query
@@ -295,11 +295,15 @@ public function loadThread(EntityInterface $entity, $field_name, $mode, $comment
        ->addMetaData('base_table', 'comment')
        ->addMetaData('entity', $entity)
        ->addMetaData('field_name', $field_name);
      $query->setCountQuery($count_query);
    }

    if (!$this->currentUser->hasPermission('administer comments')) {
      $query->condition('c.status', CommentInterface::PUBLISHED);
      if ($comments_per_page) {
        $count_query->condition('c.status', CommentInterface::PUBLISHED);
      }
    }
    if ($mode == CommentManagerInterface::COMMENT_MODE_FLAT) {
      $query->orderBy('c.cid', 'ASC');
    }
@@ -311,7 +315,6 @@ public function loadThread(EntityInterface $entity, $field_name, $mode, $comment
      $query->orderBy('torder', 'ASC');
    }

    $query->setCountQuery($count_query);
    $cids = $query->execute()->fetchCol();

    $comments = array();
+6 −0
Changes for core/modules/comment/src/Tests/CommentPagerTest.php: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -86,6 +86,12 @@ function testCommentPaging() {
    $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.');

    // 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();
  }