Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix yiisoft/yii2#20202 #350

Merged
merged 6 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}