summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcatch2012-04-28 01:09:31 (GMT)
committercatch2012-04-28 01:09:31 (GMT)
commitc7c6b79d315aa8ffa32070ebd4ffb95b5f9aafcf (patch)
tree29a3ef0f31b2c9903281360be998766a7647ced2
parent3d4d9505551ec9f321dd6fcc2795633b56575616 (diff)
Issue #1490150 by duellj, catch: Fixed EntityFieldQuery::pager(0) generates PHP error 'divide by zero'.
-rw-r--r--core/modules/entity/entity.query.inc7
-rw-r--r--core/modules/entity/tests/entity_query.test22
2 files changed, 25 insertions, 4 deletions
diff --git a/core/modules/entity/entity.query.inc b/core/modules/entity/entity.query.inc
index 6d312ea..840108a 100644
--- a/core/modules/entity/entity.query.inc
+++ b/core/modules/entity/entity.query.inc
@@ -873,12 +873,11 @@ class EntityFieldQuery {
/**
* Gets 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();
diff --git a/core/modules/entity/tests/entity_query.test b/core/modules/entity/tests/entity_query.test
index fb5dc14..625e61d 100644
--- a/core/modules/entity/tests/entity_query.test
+++ b/core/modules/entity/tests/entity_query.test
@@ -10,6 +10,7 @@
*/
class EntityFieldQueryTestCase extends DrupalWebTestCase {
+
public static function getInfo() {
return array(
'name' => 'Entity query',
@@ -1323,6 +1324,27 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
}
/**
+ * Tests the 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),
+ ), t('Test disabling pager in propertyQuery.'), TRUE);
+ }
+
+ /**
* Tests the TableSort integration of EntityFieldQuery.
*/
function testEntityFieldQueryTableSort() {