Skip to content

Commit 4273cc3

Browse files
committed
Fix getTotalCount()
1 parent acfc056 commit 4273cc3

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/ActiveDataProvider.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ public function getQueryResults()
5353
return $this->_queryResults;
5454
}
5555

56+
/**
57+
* @inheritdoc
58+
*/
59+
public function prepare($forcePrepare = false)
60+
{
61+
if ($forcePrepare) {
62+
$this->setTotalCount(null);
63+
}
64+
parent::prepare($forcePrepare);
65+
}
66+
5667
/**
5768
* @return array all aggregations results
5869
*/
@@ -122,6 +133,9 @@ protected function prepareModels()
122133

123134
if (is_array(($results = $query->search($this->db)))) {
124135
$this->setQueryResults($results);
136+
if ($pagination !== false) {
137+
$pagination->totalCount = $this->getTotalCount();
138+
}
125139
return $results['hits']['hits'];
126140
}
127141
$this->setQueryResults([]);

src/ElasticsearchTarget.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function collect($messages, $final)
139139
public function prepareMessage($message)
140140
{
141141
list($text, $level, $category, $timestamp) = $message;
142+
$timestamp = (int)round($timestamp);
142143

143144
$result = [
144145
'category' => $category,

tests/ActiveDataProviderTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,15 @@ public function testTotalCountAfterSearch()
150150
]);
151151

152152
$pagination = $provider->getPagination();
153+
$this->assertEquals(0, $pagination->getPageCount());
154+
$this->assertCount(2, $provider->getModels());
153155
$this->assertEquals(2, $pagination->getPageCount());
154-
$this->assertEquals(3, $pagination->getTotalCount());
156+
$this->assertEquals(3, $provider->getTotalCount());
155157

156158
$query->andWhere(['name' => 'user2']);
159+
$provider->prepare(true);
160+
$this->assertCount(1, $provider->getModels());
157161
$this->assertEquals(1, $pagination->getPageCount());
158-
$this->assertEquals(1, $pagination->getTotalCount());
162+
$this->assertEquals(1, $provider->getTotalCount());
159163
}
160164
}

0 commit comments

Comments
 (0)