diff --git a/src/ActiveDataProvider.php b/src/ActiveDataProvider.php index bb89f649..74271f09 100644 --- a/src/ActiveDataProvider.php +++ b/src/ActiveDataProvider.php @@ -53,6 +53,17 @@ public function getQueryResults() return $this->_queryResults; } + /** + * @inheritdoc + */ + public function prepare($forcePrepare = false) + { + if ($forcePrepare) { + $this->setTotalCount(null); + } + parent::prepare($forcePrepare); + } + /** * @return array all aggregations results */ @@ -122,6 +133,9 @@ 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([]); diff --git a/src/ElasticsearchTarget.php b/src/ElasticsearchTarget.php index 3113668f..e85c841f 100644 --- a/src/ElasticsearchTarget.php +++ b/src/ElasticsearchTarget.php @@ -139,6 +139,7 @@ public function collect($messages, $final) public function prepareMessage($message) { list($text, $level, $category, $timestamp) = $message; + $timestamp = (int)round($timestamp); $result = [ 'category' => $category, diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 806daca7..f51828f5 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -150,11 +150,15 @@ public function testTotalCountAfterSearch() ]); $pagination = $provider->getPagination(); + $this->assertEquals(0, $pagination->getPageCount()); + $this->assertCount(2, $provider->getModels()); $this->assertEquals(2, $pagination->getPageCount()); - $this->assertEquals(3, $pagination->getTotalCount()); + $this->assertEquals(3, $provider->getTotalCount()); $query->andWhere(['name' => 'user2']); + $provider->prepare(true); + $this->assertCount(1, $provider->getModels()); $this->assertEquals(1, $pagination->getPageCount()); - $this->assertEquals(1, $pagination->getTotalCount()); + $this->assertEquals(1, $provider->getTotalCount()); } }