Skip to content

Commit

Permalink
Bug #201: Fixed infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
np25071984 authored and samdark committed Jan 17, 2019
1 parent 0c2fa9f commit aa22ffd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 8 additions & 8 deletions ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ protected function prepareModels()
}

$query = clone $this->query;

$results = $query->search($this->db);
$this->setQueryResults(is_array($results) ? $results : []);

if (($pagination = $this->getPagination()) !== false) {
// pagination fails to validate page number, because total count is unknown at this stage
$pagination->validatePage = false;
Expand All @@ -95,15 +99,11 @@ protected function prepareModels()
$query->addOrderBy($sort->getOrders());
}

if (is_array(($results = $query->search($this->db)))) {
$this->setQueryResults($results);
if ($pagination !== false) {
$pagination->totalCount = $this->getTotalCount();
}
return $results['hits']['hits'];
if ($pagination !== false) {
$pagination->totalCount = $this->getTotalCount();
}
$this->setQueryResults([]);
return [];

return $results['hits']['hits'];
}

/**
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Yii Framework 2 elasticsearch extension Change Log
2.0.6 under development
-----------------------

- Bug #201: Fixed infinite loop (GHopperMSK)
- Bug #180: Fixed `count()` compatibility with PHP 7.2 to not call it on scalar values (cebe)


Expand Down

3 comments on commit aa22ffd

@fcaldarelli
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used a different approach: fcaldarelli@9e85235

@reynholm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix created a new bug.
If you make $query->search() before $query->limit() then limit does not affected query.

@machour
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reynholm if you're noticing an issue with current master, please open a issue at https://github.com/yiisoft/yii2-elasticsearch/issues

Please sign in to comment.