Commit 64625f90 authored by catch's avatar catch

Issue #1184272 by Berdir, corvus_ch, sun: Remove deprecated $conditions...

Issue #1184272 by Berdir, corvus_ch, sun: Remove deprecated $conditions support from entity controller.
parent a1d60148
...@@ -580,27 +580,19 @@ function file_save_htaccess($directory, $private = TRUE) { ...@@ -580,27 +580,19 @@ function file_save_htaccess($directory, $private = TRUE) {
/** /**
* Loads file entities from the database. * Loads file entities from the database.
* *
* @param array|bool $fids * @param array $fids
* An array of file IDs, or FALSE to load all files. * (optional) An array of entity IDs. If omitted, all entities are loaded.
* @param array $conditions
* (deprecated) An associative array of conditions on the {file_managed}
* table, where the keys are the database fields and the values are the
* values those fields must have. Instead, it is preferable to use
* Drupal\entity\EntityFieldQuery to retrieve a list of entity IDs
* loadable by this function.
* *
* @return array * @return array
* An array of file entities, indexed by fid. * An array of file entities, indexed by fid.
* *
* @todo Remove $conditions in Drupal 8.
*
* @see hook_file_load() * @see hook_file_load()
* @see file_load() * @see file_load()
* @see entity_load() * @see entity_load()
* @see Drupal\entity\EntityFieldQuery * @see Drupal\entity\EntityFieldQuery
*/ */
function file_load_multiple($fids = array(), array $conditions = array()) { function file_load_multiple(array $fids = NULL) {
return entity_load_multiple('file', $fids, $conditions); return entity_load_multiple('file', $fids);
} }
/** /**
...@@ -616,7 +608,7 @@ function file_load_multiple($fids = array(), array $conditions = array()) { ...@@ -616,7 +608,7 @@ function file_load_multiple($fids = array(), array $conditions = array()) {
* @see file_load_multiple() * @see file_load_multiple()
*/ */
function file_load($fid) { function file_load($fid) {
$files = file_load_multiple(array($fid), array()); $files = file_load_multiple(array($fid));
return reset($files); return reset($files);
} }
...@@ -803,7 +795,7 @@ function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_REN ...@@ -803,7 +795,7 @@ function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_REN
$file->filename = drupal_basename($uri); $file->filename = drupal_basename($uri);
// If we are replacing an existing file re-use its database record. // If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = file_load_multiple(array(), array('uri' => $uri)); $existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) { if (count($existing_files)) {
$existing = reset($existing_files); $existing = reset($existing_files);
$file->fid = $existing->fid; $file->fid = $existing->fid;
...@@ -1052,7 +1044,7 @@ function file_move(File $source, $destination = NULL, $replace = FILE_EXISTS_REN ...@@ -1052,7 +1044,7 @@ function file_move(File $source, $destination = NULL, $replace = FILE_EXISTS_REN
$file->uri = $uri; $file->uri = $uri;
// If we are replacing an existing file re-use its database record. // If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = file_load_multiple(array(), array('uri' => $uri)); $existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) { if (count($existing_files)) {
$existing = reset($existing_files); $existing = reset($existing_files);
$delete_source = TRUE; $delete_source = TRUE;
...@@ -1565,7 +1557,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, ...@@ -1565,7 +1557,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE,
// If we are replacing an existing file re-use its database record. // If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = file_load_multiple(array(), array('uri' => $file->uri)); $existing_files = entity_load_multiple_by_properties('file', array('uri' => $file->uri));
if (count($existing_files)) { if (count($existing_files)) {
$existing = reset($existing_files); $existing = reset($existing_files);
$file->fid = $existing->fid; $file->fid = $existing->fid;
...@@ -1858,7 +1850,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM ...@@ -1858,7 +1850,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
)); ));
// If we are replacing an existing file re-use its database record. // If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = file_load_multiple(array(), array('uri' => $uri)); $existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) { if (count($existing_files)) {
$existing = reset($existing_files); $existing = reset($existing_files);
$file->fid = $existing->fid; $file->fid = $existing->fid;
......
...@@ -4638,7 +4638,8 @@ function _form_set_class(&$element, $class = array()) { ...@@ -4638,7 +4638,8 @@ function _form_set_class(&$element, $class = array()) {
* // 1 (or no value explicitly set) means the operation is finished * // 1 (or no value explicitly set) means the operation is finished
* // and the batch processing can continue to the next operation. * // and the batch processing can continue to the next operation.
* *
* $node = node_load(array('uid' => $uid, 'type' => $type)); * $nodes = entity_load_multiple_by_properties('node', array('uid' => $uid, 'type' => $type));
* $node = reset($nodes);
* $context['results'][] = $node->nid . ' : ' . check_plain($node->label()); * $context['results'][] = $node->nid . ' : ' . check_plain($node->label());
* $context['message'] = check_plain($node->label()); * $context['message'] = check_plain($node->label());
* } * }
...@@ -4658,7 +4659,7 @@ function _form_set_class(&$element, $class = array()) { ...@@ -4658,7 +4659,7 @@ function _form_set_class(&$element, $class = array()) {
* ->range(0, $limit) * ->range(0, $limit)
* ->execute(); * ->execute();
* foreach ($result as $row) { * foreach ($result as $row) {
* $node = node_load($row->nid, NULL, TRUE); * $node = node_load($row->nid, TRUE);
* $context['results'][] = $node->nid . ' : ' . check_plain($node->label()); * $context['results'][] = $node->nid . ' : ' . check_plain($node->label());
* $context['sandbox']['progress']++; * $context['sandbox']['progress']++;
* $context['sandbox']['current_node'] = $node->nid; * $context['sandbox']['current_node'] = $node->nid;
......
...@@ -1267,7 +1267,7 @@ function book_export_traverse($tree, $visit_func) { ...@@ -1267,7 +1267,7 @@ function book_export_traverse($tree, $visit_func) {
foreach ($tree as $data) { foreach ($tree as $data) {
// Note- access checking is already performed when building the tree. // Note- access checking is already performed when building the tree.
if ($node = node_load($data['link']['nid'], FALSE)) { if ($node = node_load($data['link']['nid'])) {
$children = ''; $children = '';
if ($data['below']) { if ($data['below']) {
......
...@@ -358,7 +358,7 @@ function testBookDelete() { ...@@ -358,7 +358,7 @@ function testBookDelete() {
$this->drupalGet('node/' . $this->book->nid . '/outline/remove'); $this->drupalGet('node/' . $this->book->nid . '/outline/remove');
$this->assertResponse('403', t('Deleting top-level book node properly forbidden.')); $this->assertResponse('403', t('Deleting top-level book node properly forbidden.'));
$this->drupalPost('node/' . $nodes[4]->nid . '/outline/remove', $edit, t('Remove')); $this->drupalPost('node/' . $nodes[4]->nid . '/outline/remove', $edit, t('Remove'));
$node4 = node_load($nodes[4]->nid, NULL, TRUE); $node4 = node_load($nodes[4]->nid, TRUE);
$this->assertTrue(empty($node4->book), t('Deleting child book node properly allowed.')); $this->assertTrue(empty($node4->book), t('Deleting child book node properly allowed.'));
// Delete all child book nodes and retest top-level node deletion. // Delete all child book nodes and retest top-level node deletion.
...@@ -367,7 +367,7 @@ function testBookDelete() { ...@@ -367,7 +367,7 @@ function testBookDelete() {
} }
node_delete_multiple($nids); node_delete_multiple($nids);
$this->drupalPost('node/' . $this->book->nid . '/outline/remove', $edit, t('Remove')); $this->drupalPost('node/' . $this->book->nid . '/outline/remove', $edit, t('Remove'));
$node = node_load($this->book->nid, NULL, TRUE); $node = node_load($this->book->nid, TRUE);
$this->assertTrue(empty($node->book), t('Deleting childless top-level book node properly allowed.')); $this->assertTrue(empty($node->book), t('Deleting childless top-level book node properly allowed.'));
} }
} }
......
...@@ -1443,7 +1443,7 @@ function comment_node_search_result(Node $node) { ...@@ -1443,7 +1443,7 @@ function comment_node_search_result(Node $node) {
function comment_user_cancel($edit, $account, $method) { function comment_user_cancel($edit, $account, $method) {
switch ($method) { switch ($method) {
case 'user_cancel_block_unpublish': case 'user_cancel_block_unpublish':
$comments = comment_load_multiple(array(), array('uid' => $account->uid)); $comments = entity_load_multiple_by_properties('comment', array('uid' => $account->uid));
foreach ($comments as $comment) { foreach ($comments as $comment) {
$comment->status = 0; $comment->status = 0;
comment_save($comment); comment_save($comment);
...@@ -1451,7 +1451,7 @@ function comment_user_cancel($edit, $account, $method) { ...@@ -1451,7 +1451,7 @@ function comment_user_cancel($edit, $account, $method) {
break; break;
case 'user_cancel_reassign': case 'user_cancel_reassign':
$comments = comment_load_multiple(array(), array('uid' => $account->uid)); $comments = entity_load_multiple_by_properties('comment', array('uid' => $account->uid));
foreach ($comments as $comment) { foreach ($comments as $comment) {
$comment->uid = 0; $comment->uid = 0;
comment_save($comment); comment_save($comment);
...@@ -1526,16 +1526,10 @@ function comment_delete_multiple($cids) { ...@@ -1526,16 +1526,10 @@ function comment_delete_multiple($cids) {
} }
/** /**
* Loads comments from the database. * Loads comment entities from the database.
* *
* @param array|bool $cids * @param array $cids
* An array of comment IDs, or FALSE to load all comments. * (optional) An array of entity IDs. If omitted, all entities are loaded.
* @param array $conditions
* (deprecated) An associative array of conditions on the {comments}
* table, where the keys are the database fields and the values are the
* values those fields must have. Instead, it is preferable to use
* Drupal\entity\EntityFieldQuery to retrieve a list of entity IDs
* loadable by this function.
* @param bool $reset * @param bool $reset
* Whether to reset the internal static entity cache. Note that the static * Whether to reset the internal static entity cache. Note that the static
* cache is disabled in comment_entity_info() by default. * cache is disabled in comment_entity_info() by default.
...@@ -1543,13 +1537,11 @@ function comment_delete_multiple($cids) { ...@@ -1543,13 +1537,11 @@ function comment_delete_multiple($cids) {
* @return array * @return array
* An array of comment objects, indexed by comment ID. * An array of comment objects, indexed by comment ID.
* *
* @todo Remove $conditions in Drupal 8.
*
* @see entity_load() * @see entity_load()
* @see Drupal\entity\EntityFieldQuery * @see Drupal\entity\EntityFieldQuery
*/ */
function comment_load_multiple($cids = array(), array $conditions = array(), $reset = FALSE) { function comment_load_multiple(array $cids = NULL, $reset = FALSE) {
return entity_load_multiple('comment', $cids, $conditions, $reset); return entity_load_multiple('comment', $cids, $reset);
} }
/** /**
...@@ -1722,9 +1714,9 @@ function comment_preview(Comment $comment) { ...@@ -1722,9 +1714,9 @@ function comment_preview(Comment $comment) {
if ($comment->pid) { if ($comment->pid) {
$build = array(); $build = array();
if ($comments = comment_load_multiple(array($comment->pid), array('status' => COMMENT_PUBLISHED))) { $comment = comment_load($comment->pid);
$parent_comment = $comments[$comment->pid]; if ($comment && $comment->status == COMMENT_PUBLISHED) {
$build = comment_view($parent_comment, $node); $build = comment_view($comment, $node);
} }
} }
else { else {
......
...@@ -27,8 +27,8 @@ class CommentStorageController extends DatabaseStorageController { ...@@ -27,8 +27,8 @@ class CommentStorageController extends DatabaseStorageController {
/** /**
* Overrides Drupal\entity\DatabaseStorageController::buildQuery(). * Overrides Drupal\entity\DatabaseStorageController::buildQuery().
*/ */
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) { protected function buildQuery($ids, $revision_id = FALSE) {
$query = parent::buildQuery($ids, $conditions, $revision_id); $query = parent::buildQuery($ids, $revision_id);
// Specify additional fields from the user and node tables. // Specify additional fields from the user and node tables.
$query->innerJoin('node', 'n', 'base.nid = n.nid'); $query->innerJoin('node', 'n', 'base.nid = n.nid');
$query->addField('n', 'type', 'node_type'); $query->addField('n', 'type', 'node_type');
...@@ -41,7 +41,7 @@ protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) ...@@ -41,7 +41,7 @@ protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE)
/** /**
* Overrides Drupal\entity\DatabaseStorageController::attachLoad(). * Overrides Drupal\entity\DatabaseStorageController::attachLoad().
*/ */
protected function attachLoad(&$comments, $revision_id = FALSE) { protected function attachLoad(&$comments, $load_revision = FALSE) {
// Set up standard comment properties. // Set up standard comment properties.
foreach ($comments as $key => $comment) { foreach ($comments as $key => $comment) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name; $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
...@@ -49,7 +49,7 @@ protected function attachLoad(&$comments, $revision_id = FALSE) { ...@@ -49,7 +49,7 @@ protected function attachLoad(&$comments, $revision_id = FALSE) {
$comment->node_type = 'comment_node_' . $comment->node_type; $comment->node_type = 'comment_node_' . $comment->node_type;
$comments[$key] = $comment; $comments[$key] = $comment;
} }
parent::attachLoad($comments, $revision_id); parent::attachLoad($comments, $load_revision);
} }
/** /**
......
...@@ -363,7 +363,7 @@ function testCommentNodeCommentStatistics() { ...@@ -363,7 +363,7 @@ function testCommentNodeCommentStatistics() {
// Checks the new values of node comment statistics with comment #1. // Checks the new values of node comment statistics with comment #1.
// The node needs to be reloaded with a node_load_multiple cache reset. // The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, NULL, TRUE); $node = node_load($this->node->nid, TRUE);
$this->assertEqual($node->last_comment_name, NULL, t('The value of node last_comment_name is NULL.')); $this->assertEqual($node->last_comment_name, NULL, t('The value of node last_comment_name is NULL.'));
$this->assertEqual($node->last_comment_uid, $this->web_user2->uid, t('The value of node last_comment_uid is the comment #1 uid.')); $this->assertEqual($node->last_comment_uid, $this->web_user2->uid, t('The value of node last_comment_uid is the comment #1 uid.'));
$this->assertEqual($node->comment_count, 1, t('The value of node comment_count is 1.')); $this->assertEqual($node->comment_count, 1, t('The value of node comment_count is 1.'));
...@@ -388,7 +388,7 @@ function testCommentNodeCommentStatistics() { ...@@ -388,7 +388,7 @@ function testCommentNodeCommentStatistics() {
// Checks the new values of node comment statistics with comment #2 and // Checks the new values of node comment statistics with comment #2 and
// ensure they haven't changed since the comment has not been moderated. // ensure they haven't changed since the comment has not been moderated.
// The node needs to be reloaded with a node_load_multiple cache reset. // The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, NULL, TRUE); $node = node_load($this->node->nid, TRUE);
$this->assertEqual($node->last_comment_name, NULL, t('The value of node last_comment_name is still NULL.')); $this->assertEqual($node->last_comment_name, NULL, t('The value of node last_comment_name is still NULL.'));
$this->assertEqual($node->last_comment_uid, $this->web_user2->uid, t('The value of node last_comment_uid is still the comment #1 uid.')); $this->assertEqual($node->last_comment_uid, $this->web_user2->uid, t('The value of node last_comment_uid is still the comment #1 uid.'));
$this->assertEqual($node->comment_count, 1, t('The value of node comment_count is still 1.')); $this->assertEqual($node->comment_count, 1, t('The value of node comment_count is still 1.'));
...@@ -409,7 +409,7 @@ function testCommentNodeCommentStatistics() { ...@@ -409,7 +409,7 @@ function testCommentNodeCommentStatistics() {
// Checks the new values of node comment statistics with comment #3. // Checks the new values of node comment statistics with comment #3.
// The node needs to be reloaded with a node_load_multiple cache reset. // The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, NULL, TRUE); $node = node_load($this->node->nid, TRUE);
$this->assertEqual($node->last_comment_name, $comment_loaded->name, t('The value of node last_comment_name is the name of the anonymous user.')); $this->assertEqual($node->last_comment_name, $comment_loaded->name, t('The value of node last_comment_name is the name of the anonymous user.'));
$this->assertEqual($node->last_comment_uid, 0, t('The value of node last_comment_uid is zero.')); $this->assertEqual($node->last_comment_uid, 0, t('The value of node last_comment_uid is zero.'));
$this->assertEqual($node->comment_count, 2, t('The value of node comment_count is 2.')); $this->assertEqual($node->comment_count, 2, t('The value of node comment_count is 2.'));
......
...@@ -141,7 +141,7 @@ function entity_info_cache_clear() { ...@@ -141,7 +141,7 @@ function entity_info_cache_clear() {
* @param bool $reset * @param bool $reset
* Whether to reset the internal cache for the requested entity type. * Whether to reset the internal cache for the requested entity type.
* *
* @return object * @return Drupal\entity\EntityInterface
* The entity object, or FALSE if there is no entity with the given id. * The entity object, or FALSE if there is no entity with the given id.
* *
* @see hook_entity_info() * @see hook_entity_info()
...@@ -151,10 +151,30 @@ function entity_info_cache_clear() { ...@@ -151,10 +151,30 @@ function entity_info_cache_clear() {
* @see Drupal\entity\EntityFieldQuery * @see Drupal\entity\EntityFieldQuery
*/ */
function entity_load($entity_type, $id, $reset = FALSE) { function entity_load($entity_type, $id, $reset = FALSE) {
$entities = entity_load_multiple($entity_type, array($id), array(), $reset); $entities = entity_load_multiple($entity_type, array($id), $reset);
return isset($entities[$id]) ? $entities[$id] : FALSE; return isset($entities[$id]) ? $entities[$id] : FALSE;
} }
/**
* Loads an entity from the database.
*
* @param string $entity_type
* The entity type to load, e.g. node or user.
* @param int $revision_id
* The id of the entity to load.
*
* @return Drupal\entity\EntityInterface
* The entity object, or FALSE if there is no entity with the given revision
* id.
*
* @see hook_entity_info()
* @see Drupal\entity\EntityStorageControllerInterface
* @see Drupal\entity\DatabaseStorageController
*/
function entity_revision_load($entity_type, $revision_id) {
return entity_get_controller($entity_type)->loadRevision($revision_id);
}
/** /**
* Loads an entity by UUID. * Loads an entity by UUID.
* *
...@@ -174,9 +194,6 @@ function entity_load($entity_type, $id, $reset = FALSE) { ...@@ -174,9 +194,6 @@ function entity_load($entity_type, $id, $reset = FALSE) {
* Thrown in case the requested entity type does not support UUIDs. * Thrown in case the requested entity type does not support UUIDs.
* *
* @see hook_entity_info() * @see hook_entity_info()
*
* @todo D8: Make it easier to query entities by property; e.g., enhance
* EntityStorageControllerInterface with a ::loadByProperty() method.
*/ */
function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) { function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
$entity_info = entity_get_info($entity_type); $entity_info = entity_get_info($entity_type);
...@@ -185,25 +202,12 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) { ...@@ -185,25 +202,12 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
} }
$uuid_key = $entity_info['entity keys']['uuid']; $uuid_key = $entity_info['entity keys']['uuid'];
// Look up the entity ID for the given UUID.
$entity_query = new EntityFieldQuery();
$result = $entity_query
->entityCondition('entity_type', $entity_type)
->propertyCondition($uuid_key, $uuid)
->range(0, 1)
->execute();
if (empty($result[$entity_type])) {
return FALSE;
}
$controller = entity_get_controller($entity_type); $controller = entity_get_controller($entity_type);
if ($reset) { if ($reset) {
$controller->resetCache(); $controller->resetCache();
} }
$id = key($result[$entity_type]); $entities = $controller->loadByProperties(array($uuid_key => $uuid));
$entities = $controller->load(array($id)); return reset($entities);
return isset($entities[$id]) ? $entities[$id] : FALSE;
} }
/** /**
...@@ -225,31 +229,40 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) { ...@@ -225,31 +229,40 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
* *
* @param string $entity_type * @param string $entity_type
* The entity type to load, e.g. node or user. * The entity type to load, e.g. node or user.
* @param array|bool $ids * @param array $ids
* An array of entity IDs, or FALSE to load all entities. * (optional) An array of entity IDs. If omitted, all entities are loaded.
* @param array $conditions
* (deprecated) An associative array of conditions on the base table, where
* the keys are the database fields and the values are the values those
* fields must have. Instead, it is preferable to use EntityFieldQuery to
* retrieve a list of entity IDs loadable by this function.
* @param bool $reset * @param bool $reset
* Whether to reset the internal cache for the requested entity type. * Whether to reset the internal cache for the requested entity type.
* *
* @return array * @return array
* An array of entity objects indexed by their ids. * An array of entity objects indexed by their ids.
* *
* @todo Remove $conditions in Drupal 8.
*
* @see hook_entity_info() * @see hook_entity_info()
* @see Drupal\entity\EntityStorageControllerInterface * @see Drupal\entity\EntityStorageControllerInterface
* @see Drupal\entity\DatabaseStorageController * @see Drupal\entity\DatabaseStorageController
* @see Drupal\entity\EntityFieldQuery * @see Drupal\entity\EntityFieldQuery
*/ */
function entity_load_multiple($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE) { function entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE) {
if ($reset) { if ($reset) {
entity_get_controller($entity_type)->resetCache(); entity_get_controller($entity_type)->resetCache();
} }
return entity_get_controller($entity_type)->load($ids, $conditions); return entity_get_controller($entity_type)->load($ids);
}
/**
* Load entities by their property values.
*
* @param string $entity_type
* The entity type to load, e.g. node or user.
* @param array $values
* An associative array where the keys are the property names and the
* values are the values those properties must have.
*
* @return array
* An array of entity objects indexed by their ids.
*/
function entity_load_multiple_by_properties($entity_type, array $values) {
return entity_get_controller($entity_type)->loadByProperties($values);
} }
/** /**
......
...@@ -144,19 +144,9 @@ public function resetCache(array $ids = NULL) { ...@@ -144,19 +144,9 @@ public function resetCache(array $ids = NULL) {
/** /**
* Implements Drupal\entity\EntityStorageControllerInterface::load(). * Implements Drupal\entity\EntityStorageControllerInterface::load().
*/ */
public function load($ids = array(), $conditions = array()) { public function load(array $ids = NULL) {
$entities = array(); $entities = array();
// Revisions are not statically cached, and require a different query to
// other conditions, so separate the revision id into its own variable.
if ($this->revisionKey && isset($conditions[$this->revisionKey])) {
$revision_id = $conditions[$this->revisionKey];
unset($conditions[$this->revisionKey]);
}
else {
$revision_id = FALSE;
}
// Create a new variable which is either a prepared version of the $ids // Create a new variable which is either a prepared version of the $ids
// array for later comparison with the entity cache, or FALSE if no $ids // array for later comparison with the entity cache, or FALSE if no $ids
// were passed. The $ids array is reduced as items are loaded from cache, // were passed. The $ids array is reduced as items are loaded from cache,
...@@ -165,8 +155,8 @@ public function load($ids = array(), $conditions = array()) { ...@@ -165,8 +155,8 @@ public function load($ids = array(), $conditions = array()) {
$passed_ids = !empty($ids) ? array_flip($ids) : FALSE; $passed_ids = !empty($ids) ? array_flip($ids) : FALSE;
// Try to load entities from the static cache, if the entity type supports // Try to load entities from the static cache, if the entity type supports
// static caching. // static caching.
if ($this->cache && !$revision_id) { if ($this->cache && $ids) {
$entities += $this->cacheGet($ids, $conditions); $entities += $this->cacheGet($ids);
// If any entities were loaded, remove them from the ids still to load. // If any entities were loaded, remove them from the ids still to load.
if ($passed_ids) { if ($passed_ids) {
$ids = array_keys(array_diff_key($passed_ids, $entities)); $ids = array_keys(array_diff_key($passed_ids, $entities));
...@@ -174,11 +164,11 @@ public function load($ids = array(), $conditions = array()) { ...@@ -174,11 +164,11 @@ public function load($ids = array(), $conditions = array()) {
} }
// Load any remaining entities from the database. This is the case if $ids // Load any remaining entities from the database. This is the case if $ids
// is set to FALSE (so we load all entities), if there are any ids left to // is set to NULL (so we load all entities) or if there are any ids left to
// load, if loading a revision, or if $conditions was passed without $ids. // load.
if ($ids === FALSE || $ids || $revision_id ||