Skip to content

Commit 498a28d

Browse files
authored
Fix #350: Remove deprecated code, set $pagination->totalCount
1 parent dec1ea0 commit 498a28d

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Yii Framework 2 Elasticsearch extension Change Log
55
-----------------------
66

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

910

1011
2.1.4 May 22, 2023

src/ActiveDataProvider.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ protected function prepareModels()
122122

123123
if (is_array(($results = $query->search($this->db)))) {
124124
$this->setQueryResults($results);
125-
if ($pagination !== false) {
126-
$pagination->totalCount = $this->getTotalCount();
127-
}
128125
return $results['hits']['hits'];
129126
}
130127
$this->setQueryResults([]);

tests/ActiveDataProviderTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,23 @@ public function testRefresh()
138138
$dataProvider->refresh();
139139
$this->assertEquals(1, $dataProvider->getTotalCount());
140140
}
141+
142+
public function testTotalCountAfterSearch()
143+
{
144+
$query = Customer::find();
145+
$provider = new ActiveDataProvider([
146+
'query' => $query,
147+
'pagination' => [
148+
'pageSize' => 2,
149+
],
150+
]);
151+
152+
$pagination = $provider->getPagination();
153+
$this->assertEquals(2, $pagination->getPageCount());
154+
$this->assertEquals(3, $pagination->getTotalCount());
155+
156+
$query->andWhere(['name' => 'user2']);
157+
$this->assertEquals(1, $pagination->getPageCount());
158+
$this->assertEquals(1, $pagination->getTotalCount());
159+
}
141160
}

0 commit comments

Comments
 (0)