Skip to content
Open
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
14 changes: 14 additions & 0 deletions src/ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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([]);
Expand Down
1 change: 1 addition & 0 deletions src/ElasticsearchTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions tests/ActiveDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}