Skip to content

Commit

Permalink
Fix #350: Remove deprecated code, set $pagination->totalCount
Browse files Browse the repository at this point in the history
  • Loading branch information
lav45 authored Jun 19, 2024
1 parent dec1ea0 commit 498a28d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Yii Framework 2 Elasticsearch extension Change Log
-----------------------

- Bug #344: Disabled JSON pretty print for ElasticSearch bulk API (rhertogh)
- Bug #350: Remove deprecated code, set $pagination->totalCount (lav45)


2.1.4 May 22, 2023
Expand Down
3 changes: 0 additions & 3 deletions src/ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ protected function prepareModels()

if (is_array(($results = $query->search($this->db)))) {
$this->setQueryResults($results);
if ($pagination !== false) {
$pagination->totalCount = $this->getTotalCount();
}
return $results['hits']['hits'];
}
$this->setQueryResults([]);
Expand Down
19 changes: 19 additions & 0 deletions tests/ActiveDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,23 @@ public function testRefresh()
$dataProvider->refresh();
$this->assertEquals(1, $dataProvider->getTotalCount());
}

public function testTotalCountAfterSearch()
{
$query = Customer::find();
$provider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 2,
],
]);

$pagination = $provider->getPagination();
$this->assertEquals(2, $pagination->getPageCount());
$this->assertEquals(3, $pagination->getTotalCount());

$query->andWhere(['name' => 'user2']);
$this->assertEquals(1, $pagination->getPageCount());
$this->assertEquals(1, $pagination->getTotalCount());
}
}

0 comments on commit 498a28d

Please sign in to comment.