Issue #1490150 by xjm, duellj, tim.plunkett: Fixed EntityFieldQuery::pager(0) generates PHP error 'divide by zero'.
parent
060eb35f0a
commit
a7d43f3460
|
@ -1263,12 +1263,11 @@ class EntityFieldQuery {
|
|||
/**
|
||||
* Get the total number of results and initialize a pager for the query.
|
||||
*
|
||||
* This query can be detected by checking for ($this->pager && $this->count),
|
||||
* which allows a driver to return 0 from the count query and disable
|
||||
* the pager.
|
||||
* The pager can be disabled by either setting the pager limit to 0, or by
|
||||
* setting this query to be a count query.
|
||||
*/
|
||||
function initializePager() {
|
||||
if ($this->pager && !$this->count) {
|
||||
if ($this->pager && !empty($this->pager['limit']) && !$this->count) {
|
||||
$page = pager_find_page($this->pager['element']);
|
||||
$count_query = clone $this;
|
||||
$this->pager['total'] = $count_query->count()->execute();
|
||||
|
|
|
@ -1408,6 +1408,27 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
|
|||
unset($_GET['page']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests disabling the pager in EntityFieldQuery.
|
||||
*/
|
||||
function testEntityFieldQueryDisablePager() {
|
||||
// Test enabling a pager and then disabling it.
|
||||
$query = new EntityFieldQuery();
|
||||
$query
|
||||
->entityCondition('entity_type', 'test_entity_bundle_key')
|
||||
->propertyOrderBy('ftid', 'ASC')
|
||||
->pager(1)
|
||||
->pager(0);
|
||||
$this->assertEntityFieldQuery($query, array(
|
||||
array('test_entity_bundle_key', 1),
|
||||
array('test_entity_bundle_key', 2),
|
||||
array('test_entity_bundle_key', 3),
|
||||
array('test_entity_bundle_key', 4),
|
||||
array('test_entity_bundle_key', 5),
|
||||
array('test_entity_bundle_key', 6),
|
||||
), 'All test entities are listed when the pager is enabled and then disabled.', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the TableSort integration of EntityFieldQuery.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue