From 2d9fd20acc7c9e668c0f04e1486771227205a41e Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Thu, 24 Jun 2010 17:24:40 +0000 Subject: #834842 by Damien Tournoud, chx: Fixed oversight in field query routing API, and added tests. --- includes/entity.inc | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'includes') diff --git a/includes/entity.inc b/includes/entity.inc index 231d36055..95e7c6b1c 100644 --- a/includes/entity.inc +++ b/includes/entity.inc @@ -763,14 +763,38 @@ class EntityFieldQuery { * @endcode */ public function execute() { + // Give a chance to other modules to alter the query. drupal_alter('entity_query', $this); + + // Execute the query using the correct callback. + $result = call_user_func($this->queryCallback(), $this); + + // Sanity checks. + if (!empty($this->propertyConditions)) { + throw new EntityFieldQueryException(t('Property query conditions were not handled in !function.', array('!function' => $function))); + } + if (!empty($this->propertyOrderBy)) { + throw new EntityFieldQueryException(t('Property query order by was not handled in !function.', array('!function' => $function))); + } + return $result; + } + + /** + * Determines the query callback to use for this entity query. + * + * @return + * A callback that can be used with call_user_func(). + */ + public function queryCallback() { + // Use the override from $this->executeCallback. It can be set either + // while building the query, or using hook_entity_query_alter(). if (function_exists($this->executeCallback)) { - return $this->executeCallback($this); + return $this->executeCallback; } // If there are no field conditions and sorts, and no execute callback // then we default to querying entity tables in SQL. if (empty($this->fields)) { - return $this->propertyQuery(); + return array($this, 'propertyQuery'); } // If no override, find the storage engine to be used. foreach ($this->fields as $field) { @@ -781,18 +805,13 @@ class EntityFieldQuery { throw new EntityFieldQueryException(t("Can't handle more than one field storage engine")); } } - if (empty($storage)) { - throw new EntityFieldQueryException(t("Field storage engine not found.")); - } - $function = $storage . '_field_storage_query'; - $result = $function($this); - if (!empty($this->propertyConditions)) { - throw new EntityFieldQueryException(t('Property query conditions were not handled in !function.', array('!function' => $function))); + if ($storage) { + // Use hook_field_storage_query() from the field storage. + return $storage . '_field_storage_query'; } - if (!empty($this->propertyOrderBy)) { - throw new EntityFieldQueryException(t('Property query order by was not handled in !function.', array('!function' => $function))); + else { + throw new EntityFieldQueryException(t("Field storage engine not found.")); } - return $result; } /** -- cgit v1.2.3