Issue #1184272 by Berdir, corvus_ch, sun: Remove deprecated $conditions support from entity controller.
parent
a1d60148b7
commit
64625f9048
|
@ -580,27 +580,19 @@ function file_save_htaccess($directory, $private = TRUE) {
|
|||
/**
|
||||
* Loads file entities from the database.
|
||||
*
|
||||
* @param array|bool $fids
|
||||
* An array of file IDs, or FALSE to load all files.
|
||||
* @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.
|
||||
* @param array $fids
|
||||
* (optional) An array of entity IDs. If omitted, all entities are loaded.
|
||||
*
|
||||
* @return array
|
||||
* An array of file entities, indexed by fid.
|
||||
*
|
||||
* @todo Remove $conditions in Drupal 8.
|
||||
*
|
||||
* @see hook_file_load()
|
||||
* @see file_load()
|
||||
* @see entity_load()
|
||||
* @see Drupal\entity\EntityFieldQuery
|
||||
*/
|
||||
function file_load_multiple($fids = array(), array $conditions = array()) {
|
||||
return entity_load_multiple('file', $fids, $conditions);
|
||||
function file_load_multiple(array $fids = NULL) {
|
||||
return entity_load_multiple('file', $fids);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -616,7 +608,7 @@ function file_load_multiple($fids = array(), array $conditions = array()) {
|
|||
* @see file_load_multiple()
|
||||
*/
|
||||
function file_load($fid) {
|
||||
$files = file_load_multiple(array($fid), array());
|
||||
$files = file_load_multiple(array($fid));
|
||||
return reset($files);
|
||||
}
|
||||
|
||||
|
@ -803,7 +795,7 @@ function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_REN
|
|||
$file->filename = drupal_basename($uri);
|
||||
// If we are replacing an existing file re-use its database record.
|
||||
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)) {
|
||||
$existing = reset($existing_files);
|
||||
$file->fid = $existing->fid;
|
||||
|
@ -1052,7 +1044,7 @@ function file_move(File $source, $destination = NULL, $replace = FILE_EXISTS_REN
|
|||
$file->uri = $uri;
|
||||
// If we are replacing an existing file re-use its database record.
|
||||
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)) {
|
||||
$existing = reset($existing_files);
|
||||
$delete_source = TRUE;
|
||||
|
@ -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 ($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)) {
|
||||
$existing = reset($existing_files);
|
||||
$file->fid = $existing->fid;
|
||||
|
@ -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 ($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)) {
|
||||
$existing = reset($existing_files);
|
||||
$file->fid = $existing->fid;
|
||||
|
|
|
@ -4638,7 +4638,8 @@ function _form_set_class(&$element, $class = array()) {
|
|||
* // 1 (or no value explicitly set) means the operation is finished
|
||||
* // 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['message'] = check_plain($node->label());
|
||||
* }
|
||||
|
@ -4658,7 +4659,7 @@ function _form_set_class(&$element, $class = array()) {
|
|||
* ->range(0, $limit)
|
||||
* ->execute();
|
||||
* 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['sandbox']['progress']++;
|
||||
* $context['sandbox']['current_node'] = $node->nid;
|
||||
|
|
|
@ -1267,7 +1267,7 @@ function book_export_traverse($tree, $visit_func) {
|
|||
|
||||
foreach ($tree as $data) {
|
||||
// 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 = '';
|
||||
|
||||
if ($data['below']) {
|
||||
|
|
|
@ -358,7 +358,7 @@ class BookTest extends WebTestBase {
|
|||
$this->drupalGet('node/' . $this->book->nid . '/outline/remove');
|
||||
$this->assertResponse('403', t('Deleting top-level book node properly forbidden.'));
|
||||
$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.'));
|
||||
|
||||
// Delete all child book nodes and retest top-level node deletion.
|
||||
|
@ -367,7 +367,7 @@ class BookTest extends WebTestBase {
|
|||
}
|
||||
node_delete_multiple($nids);
|
||||
$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.'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1443,7 +1443,7 @@ function comment_node_search_result(Node $node) {
|
|||
function comment_user_cancel($edit, $account, $method) {
|
||||
switch ($method) {
|
||||
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) {
|
||||
$comment->status = 0;
|
||||
comment_save($comment);
|
||||
|
@ -1451,7 +1451,7 @@ function comment_user_cancel($edit, $account, $method) {
|
|||
break;
|
||||
|
||||
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) {
|
||||
$comment->uid = 0;
|
||||
comment_save($comment);
|
||||
|
@ -1526,16 +1526,10 @@ function comment_delete_multiple($cids) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads comments from the database.
|
||||
* Loads comment entities from the database.
|
||||
*
|
||||
* @param array|bool $cids
|
||||
* An array of comment IDs, or FALSE to load all comments.
|
||||
* @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 array $cids
|
||||
* (optional) An array of entity IDs. If omitted, all entities are loaded.
|
||||
* @param bool $reset
|
||||
* Whether to reset the internal static entity cache. Note that the static
|
||||
* cache is disabled in comment_entity_info() by default.
|
||||
|
@ -1543,13 +1537,11 @@ function comment_delete_multiple($cids) {
|
|||
* @return array
|
||||
* An array of comment objects, indexed by comment ID.
|
||||
*
|
||||
* @todo Remove $conditions in Drupal 8.
|
||||
*
|
||||
* @see entity_load()
|
||||
* @see Drupal\entity\EntityFieldQuery
|
||||
*/
|
||||
function comment_load_multiple($cids = array(), array $conditions = array(), $reset = FALSE) {
|
||||
return entity_load_multiple('comment', $cids, $conditions, $reset);
|
||||
function comment_load_multiple(array $cids = NULL, $reset = FALSE) {
|
||||
return entity_load_multiple('comment', $cids, $reset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1722,9 +1714,9 @@ function comment_preview(Comment $comment) {
|
|||
|
||||
if ($comment->pid) {
|
||||
$build = array();
|
||||
if ($comments = comment_load_multiple(array($comment->pid), array('status' => COMMENT_PUBLISHED))) {
|
||||
$parent_comment = $comments[$comment->pid];
|
||||
$build = comment_view($parent_comment, $node);
|
||||
$comment = comment_load($comment->pid);
|
||||
if ($comment && $comment->status == COMMENT_PUBLISHED) {
|
||||
$build = comment_view($comment, $node);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -27,8 +27,8 @@ class CommentStorageController extends DatabaseStorageController {
|
|||
/**
|
||||
* Overrides Drupal\entity\DatabaseStorageController::buildQuery().
|
||||
*/
|
||||
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
|
||||
$query = parent::buildQuery($ids, $conditions, $revision_id);
|
||||
protected function buildQuery($ids, $revision_id = FALSE) {
|
||||
$query = parent::buildQuery($ids, $revision_id);
|
||||
// Specify additional fields from the user and node tables.
|
||||
$query->innerJoin('node', 'n', 'base.nid = n.nid');
|
||||
$query->addField('n', 'type', 'node_type');
|
||||
|
@ -41,7 +41,7 @@ class CommentStorageController extends DatabaseStorageController {
|
|||
/**
|
||||
* Overrides Drupal\entity\DatabaseStorageController::attachLoad().
|
||||
*/
|
||||
protected function attachLoad(&$comments, $revision_id = FALSE) {
|
||||
protected function attachLoad(&$comments, $load_revision = FALSE) {
|
||||
// Set up standard comment properties.
|
||||
foreach ($comments as $key => $comment) {
|
||||
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
|
||||
|
@ -49,7 +49,7 @@ class CommentStorageController extends DatabaseStorageController {
|
|||
$comment->node_type = 'comment_node_' . $comment->node_type;
|
||||
$comments[$key] = $comment;
|
||||
}
|
||||
parent::attachLoad($comments, $revision_id);
|
||||
parent::attachLoad($comments, $load_revision);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -363,7 +363,7 @@ class CommentInterfaceTest extends CommentTestBase {
|
|||
|
||||
// Checks the new values of node comment statistics with comment #1.
|
||||
// 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_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.'));
|
||||
|
@ -388,7 +388,7 @@ class CommentInterfaceTest extends CommentTestBase {
|
|||
// Checks the new values of node comment statistics with comment #2 and
|
||||
// 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.
|
||||
$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_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.'));
|
||||
|
@ -409,7 +409,7 @@ class CommentInterfaceTest extends CommentTestBase {
|
|||
|
||||
// Checks the new values of node comment statistics with comment #3.
|
||||
// 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_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.'));
|
||||
|
|
|
@ -141,7 +141,7 @@ function entity_info_cache_clear() {
|
|||
* @param bool $reset
|
||||
* 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.
|
||||
*
|
||||
* @see hook_entity_info()
|
||||
|
@ -151,10 +151,30 @@ function entity_info_cache_clear() {
|
|||
* @see Drupal\entity\EntityFieldQuery
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -174,9 +194,6 @@ function entity_load($entity_type, $id, $reset = FALSE) {
|
|||
* Thrown in case the requested entity type does not support UUIDs.
|
||||
*
|
||||
* @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) {
|
||||
$entity_info = entity_get_info($entity_type);
|
||||
|
@ -185,25 +202,12 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
|
|||
}
|
||||
$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);
|
||||
if ($reset) {
|
||||
$controller->resetCache();
|
||||
}
|
||||
$id = key($result[$entity_type]);
|
||||
$entities = $controller->load(array($id));
|
||||
return isset($entities[$id]) ? $entities[$id] : FALSE;
|
||||
$entities = $controller->loadByProperties(array($uuid_key => $uuid));
|
||||
return reset($entities);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,31 +229,40 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
|
|||
*
|
||||
* @param string $entity_type
|
||||
* The entity type to load, e.g. node or user.
|
||||
* @param array|bool $ids
|
||||
* An array of entity IDs, or FALSE to load all entities.
|
||||
* @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 array $ids
|
||||
* (optional) An array of entity IDs. If omitted, all entities are loaded.
|
||||
* @param bool $reset
|
||||
* Whether to reset the internal cache for the requested entity type.
|
||||
*
|
||||
* @return array
|
||||
* An array of entity objects indexed by their ids.
|
||||
*
|
||||
* @todo Remove $conditions in Drupal 8.
|
||||
*
|
||||
* @see hook_entity_info()
|
||||
* @see Drupal\entity\EntityStorageControllerInterface
|
||||
* @see Drupal\entity\DatabaseStorageController
|
||||
* @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) {
|
||||
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 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
|||
/**
|
||||
* Implements Drupal\entity\EntityStorageControllerInterface::load().
|
||||
*/
|
||||
public function load($ids = array(), $conditions = array()) {
|
||||
public function load(array $ids = NULL) {
|
||||
$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
|
||||
// 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,
|
||||
|
@ -165,8 +155,8 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
|||
$passed_ids = !empty($ids) ? array_flip($ids) : FALSE;
|
||||
// Try to load entities from the static cache, if the entity type supports
|
||||
// static caching.
|
||||
if ($this->cache && !$revision_id) {
|
||||
$entities += $this->cacheGet($ids, $conditions);
|
||||
if ($this->cache && $ids) {
|
||||
$entities += $this->cacheGet($ids);
|
||||
// If any entities were loaded, remove them from the ids still to load.
|
||||
if ($passed_ids) {
|
||||
$ids = array_keys(array_diff_key($passed_ids, $entities));
|
||||
|
@ -174,11 +164,11 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
|||
}
|
||||
|
||||
// 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
|
||||
// load, if loading a revision, or if $conditions was passed without $ids.
|
||||
if ($ids === FALSE || $ids || $revision_id || ($conditions && !$passed_ids)) {
|
||||
// is set to NULL (so we load all entities) or if there are any ids left to
|
||||
// load.
|
||||
if ($ids === NULL || $ids) {
|
||||
// Build and execute the query.
|
||||
$query_result = $this->buildQuery($ids, $conditions, $revision_id)->execute();
|
||||
$query_result = $this->buildQuery($ids)->execute();
|
||||
|
||||
if (!empty($this->entityInfo['entity class'])) {
|
||||
// We provide the necessary arguments for PDO to create objects of the
|
||||
|
@ -193,13 +183,13 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
|||
// which attaches fields (if supported by the entity type) and calls the
|
||||
// entity type specific load callback, for example hook_node_load().
|
||||
if (!empty($queried_entities)) {
|
||||
$this->attachLoad($queried_entities, $revision_id);
|
||||
$this->attachLoad($queried_entities);
|
||||
$entities += $queried_entities;
|
||||
}
|
||||
|
||||
if ($this->cache) {
|
||||
// Add entities to the cache if we are not loading a revision.
|
||||
if (!empty($queried_entities) && !$revision_id) {
|
||||
// Add entities to the cache.
|
||||
if (!empty($queried_entities)) {
|
||||
$this->cacheSet($queried_entities);
|
||||
}
|
||||
}
|
||||
|
@ -218,6 +208,62 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
|||
return $entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\entity\EntityStorageControllerInterface::loadRevision().
|
||||
*/
|
||||
public function loadRevision($revision_id) {
|
||||
// Build and execute the query.
|
||||
$query_result = $this->buildQuery(array(), $revision_id)->execute();
|
||||
|
||||
if (!empty($this->entityInfo['entity class'])) {
|
||||
// We provide the necessary arguments for PDO to create objects of the
|
||||
// specified entity class.
|
||||
// @see Drupal\entity\EntityInterface::__construct()
|
||||
$query_result->setFetchMode(PDO::FETCH_CLASS, $this->entityInfo['entity class'], array(array(), $this->entityType));
|
||||
}
|
||||
$queried_entities = $query_result->fetchAllAssoc($this->idKey);
|
||||
|
||||
// Pass the loaded entities from the database through $this->attachLoad(),
|
||||
// which attaches fields (if supported by the entity type) and calls the
|
||||
// entity type specific load callback, for example hook_node_load().
|
||||
if (!empty($queried_entities)) {
|
||||
$this->attachLoad($queried_entities, TRUE);
|
||||
}
|
||||
return reset($queried_entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\entity\EntityStorageControllerInterface::loadByProperties().
|
||||
*/
|
||||
public function loadByProperties(array $values = array()) {
|
||||
// Build a query to fetch the entity IDs.
|
||||
$entity_query = new EntityFieldQuery();
|
||||
$entity_query->entityCondition('entity_type', $this->entityType);
|
||||
$this->buildPropertyQuery($entity_query, $values);
|
||||
$result = $entity_query->execute();
|
||||
|
||||
if (empty($result[$this->entityType])) {
|
||||
return array();
|
||||
}
|
||||
// Load and return the found entities.
|
||||
return $this->load(array_keys($result[$this->entityType]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an entity query.
|
||||
*
|
||||
* @param Drupal\entity\EntityFieldQuery $entity_query
|
||||
* EntityFieldQuery instance.
|
||||
* @param array $values
|
||||
* An associative array of properties of the entity, where the keys are the
|
||||
* property names and the values are the values those properties must have.
|
||||
*/
|
||||
protected function buildPropertyQuery(EntityFieldQuery $entity_query, array $values) {
|
||||
foreach ($values as $name => $value) {
|
||||
$entity_query->propertyCondition($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the query to load the entity.
|
||||
*
|
||||
|
@ -230,10 +276,8 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
|||
* See Drupal\comment\CommentStorageController::buildQuery() or
|
||||
* Drupal\taxonomy\TermStorageController::buildQuery() for examples.
|
||||
*
|
||||
* @param $ids
|
||||
* An array of entity IDs, or FALSE to load all entities.
|
||||
* @param $conditions
|
||||
* An array of conditions in the form 'field' => $value.
|
||||
* @param array|null $ids
|
||||
* An array of entity IDs, or NULL to load all entities.
|
||||
* @param $revision_id
|
||||
* The ID of the revision to load, or FALSE if this query is asking for the
|
||||
* most current revision(s).
|
||||
|
@ -241,7 +285,7 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
|||
* @return SelectQuery
|
||||
* A SelectQuery object for loading the entity.
|
||||
*/
|
||||
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
|
||||
protected function buildQuery($ids, $revision_id = FALSE) {
|
||||
$query = db_select($this->entityInfo['base table'], 'base');
|
||||
|
||||
$query->addTag($this->entityType . '_load_multiple');
|
||||
|
@ -282,11 +326,6 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
|||
if ($ids) {
|
||||
$query->condition("base.{$this->idKey}", $ids, 'IN');
|
||||
}
|
||||
if ($conditions) {
|
||||
foreach ($conditions as $field => $value) {
|
||||
$query->condition('base.' . $field, $value);
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@ -303,14 +342,13 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
|||
*
|
||||
* @param $queried_entities
|
||||
* Associative array of query results, keyed on the entity ID.
|
||||
* @param $revision_id
|
||||
* ID of the revision that was loaded, or FALSE if the most current revision
|
||||
* was loaded.
|
||||
* @param $load_revision
|
||||
* (optional) TRUE if the revision should be loaded, defaults to FALSE.
|
||||
*/
|
||||
protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
|
||||
protected function attachLoad(&$queried_entities, $load_revision = FALSE) {
|
||||
// Attach fields.
|
||||
if ($this->entityInfo['fieldable']) {
|
||||
if ($revision_id) {
|
||||
if ($load_revision) {
|
||||
field_attach_load_revision($this->entityType, $queried_entities);
|
||||
}
|
||||
else {
|
||||
|
@ -337,35 +375,15 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
|||
*
|
||||
* @param $ids
|
||||
* If not empty, return entities that match these IDs.
|
||||
* @param $conditions
|
||||
* If set, return entities that match all of these conditions.
|
||||
*
|
||||
* @return
|
||||
* Array of entities from the entity cache.
|
||||
*/
|
||||
protected function cacheGet($ids, $conditions = array()) {
|
||||
protected function cacheGet($ids) {
|
||||
$entities = array();
|
||||
// Load any available entities from the internal cache.
|
||||
if (!empty($this->entityCache)) {
|
||||
if ($ids) {
|
||||
$entities += array_intersect_key($this->entityCache, array_flip($ids));
|
||||
}
|
||||
// If loading entities only by conditions, fetch all available entities
|
||||
// from the cache. Entities which don't match are removed later.
|
||||
elseif ($conditions) {
|
||||
$entities = $this->entityCache;
|
||||
}
|
||||
}
|
||||
|
||||
// Exclude any entities loaded from cache if they don't match $conditions.
|
||||
// This ensures the same behavior whether loading from memory or database.
|
||||
if ($conditions) {
|
||||
foreach ($entities as $entity) {
|
||||
$entity_values = (array) $entity;
|
||||
if (array_diff_assoc($conditions, $entity_values)) {
|
||||
unset($entities[$entity->{$this->idKey}]);
|
||||
}
|
||||
}
|
||||
$entities += array_intersect_key($this->entityCache, array_flip($ids));
|
||||
}
|
||||
return $entities;
|
||||
}
|
||||
|
|
|
@ -42,13 +42,34 @@ interface EntityStorageControllerInterface {
|
|||
*
|
||||
* @param $ids
|
||||
* An array of entity IDs, or FALSE to load all entities.
|
||||
* @param $conditions
|
||||
* An array of conditions in the form 'field' => $value.
|
||||
*
|
||||
* @return
|
||||
* An array of entity objects indexed by their ids.
|
||||
*/
|
||||
public function load($ids = array(), $conditions = array());
|
||||
public function load(array $ids = NULL);
|
||||
|
||||
/**
|
||||
* Load a specific entity revision.
|
||||
*
|
||||
* @param int $revision_id
|
||||
* The revision id.
|
||||
*
|
||||
* @return Drupal\entity\EntityInterface|false
|
||||
* The specified entity revision or FALSE if not found.
|
||||
*/
|
||||
public function loadRevision($revision_id);
|
||||
|
||||
/**
|
||||
* Load entities by their property values.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public function loadByProperties(array $values);
|
||||
|
||||
/**
|
||||
* Constructs a new entity object, without permanently saving it.
|
||||
|
|
|
@ -43,7 +43,7 @@ class EntityApiTest extends WebTestBase {
|
|||
$entity = entity_create('entity_test', array('name' => 'test', 'uid' => NULL));
|
||||
$entity->save();
|
||||
|
||||
$entities = array_values(entity_test_load_multiple(FALSE, array('name' => 'test')));
|
||||
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test')));
|
||||
|
||||
$this->assertEqual($entities[0]->get('name'), 'test', 'Created and loaded entity.');
|
||||
$this->assertEqual($entities[1]->get('name'), 'test', 'Created and loaded entity.');
|
||||
|
@ -53,23 +53,23 @@ class EntityApiTest extends WebTestBase {
|
|||
$this->assertEqual($loaded_entity->id, $entity->id, 'Loaded a single entity by id.');
|
||||
|
||||
// Test deleting an entity.
|
||||
$entities = array_values(entity_test_load_multiple(FALSE, array('name' => 'test2')));
|
||||
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test2')));
|
||||
$entities[0]->delete();
|
||||
$entities = array_values(entity_test_load_multiple(FALSE, array('name' => 'test2')));
|
||||
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test2')));
|
||||
$this->assertEqual($entities, array(), 'Entity deleted.');
|
||||
|
||||
// Test updating an entity.
|
||||
$entities = array_values(entity_test_load_multiple(FALSE, array('name' => 'test')));
|
||||
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test')));
|
||||
$entities[0]->set('name', 'test3');
|
||||
$entities[0]->save();
|
||||
$entity = entity_test_load($entities[0]->id);
|
||||
$this->assertEqual($entity->get('name'), 'test3', 'Entity updated.');
|
||||
|
||||
// Try deleting multiple test entities by deleting all.
|
||||
$ids = array_keys(entity_test_load_multiple(FALSE));
|
||||
$ids = array_keys(entity_test_load_multiple());
|
||||
entity_test_delete_multiple($ids);
|
||||
|
||||
$all = entity_test_load_multiple(FALSE);
|
||||
$all = entity_test_load_multiple();
|
||||
$this->assertTrue(empty($all), 'Deleted all entities.');
|
||||
}
|
||||
|
||||
|
|
|
@ -211,23 +211,23 @@ class EntityTranslationTest extends WebTestBase {
|
|||
// original language is the same of one used for a translation.
|
||||
$langcode = $this->langcodes[1];
|
||||
entity_create('entity_test', array('uid' => $properties[$langcode]['uid']))->save();
|
||||
$entities = entity_test_load_multiple(FALSE, array(), TRUE);
|
||||
$entities = entity_test_load_multiple();
|
||||
$this->assertEqual(count($entities), 3, 'Three entities were created.');
|
||||
$entities = entity_test_load_multiple(array($translated_id), array(), TRUE);
|
||||
$entities = entity_test_load_multiple(array($translated_id));
|
||||
$this->assertEqual(count($entities), 1, 'One entity correctly loaded by id.');
|
||||
$entities = entity_test_load_multiple(array(), array('name' => $name), TRUE);
|
||||
$entities = entity_load_multiple_by_properties('entity_test', array('name' => $name));
|
||||
$this->assertEqual(count($entities), 2, 'Two entities correctly loaded by name.');
|
||||
// @todo The default language condition should go away in favor of an
|
||||
// explicit parameter.
|
||||
$entities = entity_test_load_multiple(array(), array('name' => $properties[$langcode]['name'], 'default_langcode' => 0), TRUE);
|
||||
$entities = entity_load_multiple_by_properties('entity_test', array('name' => $properties[$langcode]['name'], 'default_langcode' => 0));
|
||||
$this->assertEqual(count($entities), 1, 'One entity correctly loaded by name translation.');
|
||||
$entities = entity_test_load_multiple(array(), array('langcode' => $default_langcode, 'name' => $name), TRUE);
|
||||
$entities = entity_load_multiple_by_properties('entity_test', array('langcode' => $default_langcode, 'name' => $name));
|
||||
$this->assertEqual(count($entities), 1, 'One entity correctly loaded by name and language.');
|
||||
$entities = entity_test_load_multiple(array(), array('langcode' => $langcode, 'name' => $properties[$langcode]['name']), TRUE);
|
||||
$entities = entity_load_multiple_by_properties('entity_test', array('langcode' => $langcode, 'name' => $properties[$langcode]['name']));
|
||||
$this->assertEqual(count($entities), 0, 'No entity loaded by name translation specifying the translation language.');
|
||||
$entities = entity_test_load_multiple(array(), array('langcode' => $langcode, 'name' => $properties[$langcode]['name'], 'default_langcode' => 0), TRUE);
|
||||
$entities = entity_load_multiple_by_properties('entity_test', array('langcode' => $langcode, 'name' => $properties[$langcode]['name'], 'default_langcode' => 0));
|
||||
$this->assertEqual(count($entities), 1, 'One entity loaded by name translation and language specifying to look for translations.');
|
||||
$entities = entity_test_load_multiple(array(), array('uid' => $properties[$langcode]['uid'], 'default_langcode' => NULL), TRUE);
|
||||
$entities = entity_load_multiple_by_properties('entity_test', array('uid' => $properties[$langcode]['uid'], 'default_langcode' => NULL));
|
||||
$this->assertEqual(count($entities), 2, 'Two entities loaded by uid without caring about property translatability.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,18 +45,16 @@ function entity_test_load($id, $reset = FALSE) {
|
|||
/**
|
||||
* Loads multiple test entities based on certain conditions.
|
||||
*
|
||||
* @param array|bool $ids
|
||||
* An array of entity IDs, or FALSE to load all entities.
|
||||
* @param array $conditions
|
||||
* An array of conditions to match against the {entity} table.
|
||||
* @param array $ids
|
||||
* (optional) An array of entity IDs. If omitted, all entities are loaded.
|
||||
* @param bool $reset
|
||||
* A boolean indicating that the internal cache should be reset.
|
||||
*
|
||||
* @return array
|
||||
* An array of test entity objects, indexed by ID.
|
||||
*/
|
||||
function entity_test_load_multiple($ids = array(), $conditions = array(), $reset = FALSE) {
|
||||
return entity_load_multiple('entity_test', $ids, $conditions, $reset);
|
||||
function entity_test_load_multiple(array $ids = NULL, $reset = FALSE) {
|
||||
return entity_load_multiple('entity_test', $ids, $reset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,22 +21,12 @@ use Drupal\entity\DatabaseStorageController;
|
|||
class EntityTestStorageController extends DatabaseStorageController {
|
||||
|
||||
/**
|
||||
* Overrides Drupal\entity\DatabaseStorageController::buildQuery().
|
||||
* Overrides Drupal\entity\DatabaseStorageController::loadByProperties().
|
||||
*/
|
||||
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
|
||||
$query = parent::buildQuery($ids, $conditions, $revision_id);
|
||||
|
||||
if ($conditions) {
|
||||
// Reset conditions as the default storage controller applies them to the
|
||||
// base table.
|
||||
$query_conditions = &$query->conditions();
|
||||
$query_conditions = array('#conjunction' => 'AND');
|
||||
|
||||
// Restore id conditions.
|
||||
if ($ids) {
|
||||
$query->condition("base.{$this->idKey}", $ids, 'IN');
|
||||
}
|
||||
|
||||
public function loadByProperties(array $values) {
|
||||
$query = db_select($this->entityInfo['base table'], 'base');
|
||||
$query->addTag($this->entityType . '_load_multiple');
|
||||
if ($values) {
|
||||
// Conditions need to be applied the property data table.
|
||||
$query->addJoin('inner', 'entity_test_property_data', 'data', "base.{$this->idKey} = data.{$this->idKey}");
|
||||
$query->distinct(TRUE);
|
||||
|
@ -46,27 +36,31 @@ class EntityTestStorageController extends DatabaseStorageController {
|
|||
// separate parameter during the following API refactoring.
|
||||
// Default to the original entity language if not explicitly specified
|
||||
// otherwise.
|
||||
if (!array_key_exists('default_langcode', $conditions)) {
|
||||
$conditions['default_langcode'] = 1;
|
||||
if (!array_key_exists('default_langcode', $values)) {
|
||||
$values['default_langcode'] = 1;
|
||||
}
|
||||
// If the 'default_langcode' flag is esplicitly not set, we do not care
|
||||
// whether the queried values are in the original entity language or not.
|
||||
elseif ($conditions['default_langcode'] === NULL) {
|
||||
unset($conditions['default_langcode']);
|
||||
elseif ($values['default_langcode'] === NULL) {
|
||||
unset($values['default_langcode']);
|
||||
}
|
||||
|
||||
foreach ($conditions as $field => $value) {
|
||||
$query->condition('data.' . $field, $value);
|
||||
$data_schema = drupal_get_schema('entity_test_property_data');
|
||||
$query->addField('data', $this->idKey);
|
||||
foreach ($values as $field => $value) {
|
||||
// Check on which table the condition needs to be added.
|
||||
$table = isset($data_schema['fields'][$field]) ? 'data' : 'base';
|
||||
$query->condition($table . '.' . $field, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
$ids = $query->execute()->fetchCol();
|
||||
return $ids ? $this->load($ids) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides Drupal\entity\DatabaseStorageController::attachLoad().
|
||||
*/
|
||||
protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
|
||||
protected function attachLoad(&$queried_entities, $load_revision = FALSE) {
|
||||
$data = db_select('entity_test_property_data', 'data', array('fetch' => PDO::FETCH_ASSOC))
|
||||
->fields('data')
|
||||
->condition('id', array_keys($queried_entities))
|
||||
|
@ -84,7 +78,7 @@ class EntityTestStorageController extends DatabaseStorageController {
|
|||
$entity->setProperties($values, $langcode);
|
||||
}
|
||||
|
||||
parent::attachLoad($queried_entities, $revision_id);
|
||||
parent::attachLoad($queried_entities, $load_revision);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -127,7 +127,7 @@ function file_file_download($uri, $field_type = 'file') {
|
|||
global $user;
|
||||
|
||||
// Get the file record based on the URI. If not in the database just return.
|
||||
$files = file_load_multiple(array(), array('uri' => $uri));
|
||||
$files = entity_load_multiple_by_properties('file', array('uri' => $uri));
|
||||
if (count($files)) {
|
||||
foreach ($files as $item) {
|
||||
// Since some database servers sometimes use a case-insensitive comparison
|
||||
|
|
|
@ -57,7 +57,7 @@ class FileFieldDisplayTest extends FileFieldTestBase {
|
|||
$this->drupalGet('node/' . $nid . '/edit');
|
||||
|
||||
// Check that the default formatter is displaying with the file name.
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$default_output = theme('file_link', array('file' => $node_file));
|
||||
$this->assertRaw($default_output, t('Default formatter displaying correctly on full node view.'));
|
||||
|
|
|
@ -32,7 +32,7 @@ class FileFieldPathTest extends FileFieldTestBase {
|
|||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
|
||||
// Check that the file was uploaded to the file root.
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$this->assertPathMatch('public://' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri)));
|
||||
|
||||
|
@ -43,7 +43,7 @@ class FileFieldPathTest extends FileFieldTestBase {
|
|||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
|
||||
// Check that the file was uploaded into the subdirectory.
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$this->assertPathMatch('public://foo/bar/baz/' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri)));
|
||||
|
||||
|
@ -55,7 +55,7 @@ class FileFieldPathTest extends FileFieldTestBase {
|
|||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
|
||||
// Check that the file was uploaded into the subdirectory.
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
// Do token replacement using the same user which uploaded the file, not
|
||||
// the user running the test case.
|
||||
|
|
|
@ -46,7 +46,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
|
|||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
|
||||
// Check that the file exists on disk and in the database.
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file_r1 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$node_vid_r1 = $node->vid;
|
||||
$this->assertFileExists($node_file_r1, t('New file saved to disk on node creation.'));
|
||||
|
@ -55,7 +55,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
|
|||
|
||||
// Upload another file to the same node in a new revision.
|
||||
$this->replaceNodeFile($test_file, $field_name, $nid);
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file_r2 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$node_vid_r2 = $node->vid;
|
||||
$this->assertFileExists($node_file_r2, t('Replacement file exists on disk after creating new revision.'));
|
||||
|
@ -63,7 +63,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
|
|||
$this->assertFileIsPermanent($node_file_r2, t('Replacement file is permanent.'));
|
||||
|
||||
// Check that the original file is still in place on the first revision.
|
||||
$node = node_load($nid, $node_vid_r1, TRUE);
|
||||
$node = node_revision_load($node_vid_r1);
|
||||
$this->assertEqual($node_file_r1, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('Original file still in place after replacing file in new revision.'));
|
||||
$this->assertFileExists($node_file_r1, t('Original file still in place after replacing file in new revision.'));
|
||||
$this->assertFileEntryExists($node_file_r1, t('Original file entry still in place after replacing file in new revision'));
|
||||
|
@ -72,7 +72,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
|
|||
// Save a new version of the node without any changes.
|
||||
// Check that the file is still the same as the previous revision.
|
||||
$this->drupalPost('node/' . $nid . '/edit', array('revision' => '1'), t('Save'));
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file_r3 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$node_vid_r3 = $node->vid;
|
||||
$this->assertEqual($node_file_r2, $node_file_r3, t('Previous revision file still in place after creating a new revision without a new file.'));
|
||||
|
@ -80,7 +80,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
|
|||
|
||||
// Revert to the first revision and check that the original file is active.
|
||||
$this->drupalPost('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert'));
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file_r4 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$node_vid_r4 = $node->vid;
|
||||
$this->assertEqual($node_file_r1, $node_file_r4, t('Original revision file still in place after reverting to the original revision.'));
|
||||
|
|
|
@ -143,7 +143,7 @@ abstract class FileFieldTestBase extends WebTestBase {
|
|||
$nid = $node->nid;
|
||||
// Save at least one revision to better simulate a real site.
|
||||
$this->drupalCreateNode(get_object_vars($node));
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$this->assertNotEqual($nid, $node->vid, t('Node revision exists.'));
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
|
|||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
$this->assertTrue($nid !== FALSE, t('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', array('@test_file' => $test_file->uri, '@field_name' => $field_name, '@type_name' => $type_name)));
|
||||
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$this->assertFileExists($node_file, t('File exists after uploading to the required field.'));
|
||||
|
@ -61,7 +61,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
|
|||
|
||||
// Create a new node with the uploaded file into the multivalue field.
|
||||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$this->assertFileExists($node_file, t('File exists after uploading to the required multiple value field.'));
|
||||
$this->assertFileEntryExists($node_file, t('File entry exists after uploading to the required multipel value field.'));
|
||||
|
@ -97,7 +97,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
|
|||
|
||||
// Create a new node with the small file, which should pass.
|
||||
$nid = $this->uploadNodeFile($small_file, $field_name, $type_name);
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize)));
|
||||
$this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize)));
|
||||
|
@ -113,7 +113,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
|
|||
|
||||
// Upload the big file successfully.
|
||||
$nid = $this->uploadNodeFile($large_file, $field_name, $type_name);
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize))));
|
||||
$this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize))));
|
||||
|
@ -140,7 +140,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
|
|||
|
||||
// Check that the file can be uploaded with no extension checking.
|
||||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$this->assertFileExists($node_file, t('File exists after uploading a file with no extension checking.'));
|
||||
$this->assertFileEntryExists($node_file, t('File entry exists after uploading a file with no extension checking.'));
|
||||
|
@ -158,7 +158,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
|
|||
|
||||
// Check that the file can be uploaded with extension checking.
|
||||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$this->assertFileExists($node_file, t('File exists after uploading a file with extension checking.'));
|
||||
$this->assertFileEntryExists($node_file, t('File entry exists after uploading a file with extension checking.'));
|
||||
|
|
|
@ -41,7 +41,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
|
|||
// @todo This only tests a 'nojs' submission, because drupalPostAJAX()
|
||||
// does not yet support file uploads.
|
||||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$this->assertFileExists($node_file, t('New file saved to disk on node creation.'));
|
||||
|
||||
|
@ -71,7 +71,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
|
|||
|
||||
// Save the node and ensure it does not have the file.
|
||||
$this->drupalPost(NULL, array(), t('Save'));
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$this->assertTrue(empty($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('File was successfully removed from the node.'));
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
|
|||
$matches = array();
|
||||
preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches);
|
||||
$nid = $matches[1];
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$this->assertTrue(empty($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('Node was successfully saved without any files.'));
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
|
|||
$edit = array('field[settings][uri_scheme]' => 'private');
|
||||
$this->drupalPost("admin/structure/types/manage/$type_name/fields/$field_name", $edit, t('Save settings'));
|
||||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
$this->assertFileExists($node_file, t('New file saved to disk on node creation.'));
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class FilePrivateTest extends FileFieldTestBase {
|
|||
|
||||
$test_file = $this->getTestFile('text');
|
||||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE));
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
// Ensure the file can be downloaded.
|
||||
$this->drupalGet(file_create_url($node_file->uri));
|
||||
|
|
|
@ -45,7 +45,7 @@ class FileTokenReplaceTest extends FileFieldTestBase {
|
|||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
|
||||
// Load the node and the file.
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
|
||||
|
||||
// Generate and test sanitized tokens.
|
||||
|
|
|
@ -301,7 +301,7 @@ function image_file_download($uri) {
|
|||
// Private file access for the original files. Note that we only
|
||||
// check access for non-temporary images, since file.module will
|
||||
// grant access for all temporary files.
|
||||
$files = file_load_multiple(array(), array('uri' => $uri));
|
||||
$files = entity_load_multiple_by_properties('file', array('uri' => $uri));
|
||||
if (count($files)) {
|
||||
$file = reset($files);
|
||||
if ($file->status) {
|
||||
|
|
|
@ -144,8 +144,8 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
|
|||
);
|
||||
|
||||
// Reload the nodes and confirm the field instance defaults are used.
|
||||
$article_built = node_view($article = node_load($article->nid, NULL, $reset = TRUE));
|
||||
$page_built = node_view($page = node_load($page->nid, NULL, $reset = TRUE));
|
||||
$article_built = node_view($article = node_load($article->nid, TRUE));
|
||||
$page_built = node_view($page = node_load($page->nid, TRUE));
|
||||
$this->assertEqual(
|
||||
$article_built[$field_name]['#items'][0]['fid'],
|
||||
$default_images['instance']->fid,
|
||||
|
@ -180,8 +180,8 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
|
|||
);
|
||||
|
||||
// Reload the nodes.
|
||||
$article_built = node_view($article = node_load($article->nid, NULL, $reset = TRUE));
|
||||
$page_built = node_view($page = node_load($page->nid, NULL, $reset = TRUE));
|
||||
$article_built = node_view($article = node_load($article->nid, TRUE));
|
||||
$page_built = node_view($page = node_load($page->nid, TRUE));
|
||||
|
||||
// Confirm the article uses the new default.
|
||||
$this->assertEqual(
|
||||
|
@ -215,8 +215,8 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
|
|||
);
|
||||
|
||||
// Reload the nodes.
|
||||
$article_built = node_view($article = node_load($article->nid, NULL, $reset = TRUE));
|
||||
$page_built = node_view($page = node_load($page->nid, NULL, $reset = TRUE));
|
||||
$article_built = node_view($article = node_load($article->nid, TRUE));
|
||||
$page_built = node_view($page = node_load($page->nid, TRUE));
|
||||
// Confirm the article uses the new field (not instance) default.
|
||||
$this->assertEqual(
|
||||
$article_built[$field_name]['#items'][0]['fid'],
|
||||
|
|
|
@ -52,7 +52,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
|
|||
// Create a new node with an image attached.
|
||||
$test_image = current($this->drupalGetTestFiles('image'));
|
||||
$nid = $this->uploadNodeImage($test_image, $field_name, 'article');
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
|
||||
// Test that the default formatter is being used.
|
||||
$image_uri = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri;
|
||||
|
@ -156,7 +156,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
|
|||
$this->assertFieldByName($field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][title]', '', t('Title field displayed on article form.'));
|
||||
// Verify that the attached image is being previewed using the 'medium'
|
||||
// style.
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$image_info = array(
|
||||
'uri' => image_style_url('medium', file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri),
|
||||
'width' => 220,
|
||||
|
@ -232,7 +232,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
|
|||
// Create a node with an image attached and ensure that the default image
|
||||
// is not displayed.
|
||||
$nid = $this->uploadNodeImage($images[1], $field_name, 'article');
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
$image_info = array(
|
||||
'uri' => file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri,
|
||||
'width' => 40,
|
||||
|
|
|
@ -157,7 +157,7 @@ class NodeStorageController extends DatabaseStorageController {
|
|||
/**
|
||||
* Overrides Drupal\entity\DatabaseStorageController::attachLoad().
|
||||
*/
|
||||
protected function attachLoad(&$nodes, $revision_id = FALSE) {
|
||||
protected function attachLoad(&$nodes, $load_revision = FALSE) {
|
||||
// Create an array of nodes for each content type and pass this to the
|
||||
// object type specific callback.
|
||||
$typed_nodes = array();
|
||||
|
@ -176,16 +176,16 @@ class NodeStorageController extends DatabaseStorageController {
|
|||
// hook_node_load(), containing a list of node types that were loaded.
|
||||
$argument = array_keys($typed_nodes);
|
||||
$this->hookLoadArguments = array($argument);
|
||||
parent::attachLoad($nodes, $revision_id);
|
||||
parent::attachLoad($nodes, $load_revision);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides Drupal\entity\DatabaseStorageController::buildQuery().
|
||||
*/
|
||||
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
|
||||
protected function buildQuery($ids, $revision_id = FALSE) {
|
||||
// Ensure that uid is taken from the {node} table,
|
||||
// alias timestamp to revision_timestamp and add revision_uid.
|
||||
$query = parent::buildQuery($ids, $conditions, $revision_id);
|
||||
$query = parent::buildQuery($ids, $revision_id);
|
||||
$fields =& $query->getFields();
|
||||
unset($fields['timestamp']);
|
||||
$query->addField('revision', 'timestamp', 'revision_timestamp');
|
||||
|
|
|
@ -94,7 +94,7 @@ class NodeFieldMultilingualTestCase extends WebTestBase {
|
|||
'langcode' => 'it'
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$node = $this->drupalGetNodeByTitle($edit[$title_key]);
|
||||
$node = $this->drupalGetNodeByTitle($edit[$title_key], TRUE);
|
||||
$this->assertTrue($node, t('Node found in database.'));
|
||||
|
||||
$assert = isset($node->body['it']) && !isset($node->body['en']) && $node->body['it'][0]['value'] == $body_value;
|
||||
|
|
|
@ -40,7 +40,7 @@ class NodeLoadHooksTest extends NodeTestBase {
|
|||
// Check that when a set of nodes that only contains articles is loaded,
|
||||
// the properties added to the node by node_test_load_node() correctly
|
||||
// reflect the expected values.
|
||||
$nodes = node_load_multiple(array(), array('status' => NODE_PUBLISHED));
|
||||
$nodes = entity_load_multiple_by_properties('node', array('status' => NODE_PUBLISHED));
|
||||
$loaded_node = end($nodes);
|
||||
$this->assertEqual($loaded_node->node_test_loaded_nids, array($node1->nid, $node2->nid), t('hook_node_load() received the correct list of node IDs the first time it was called.'));
|
||||
$this->assertEqual($loaded_node->node_test_loaded_types, array('article'), t('hook_node_load() received the correct list of node types the first time it was called.'));
|
||||
|
@ -48,7 +48,7 @@ class NodeLoadHooksTest extends NodeTestBase {
|
|||
// Now, as part of the same page request, load a set of nodes that contain
|
||||
// both articles and pages, and make sure the parameters passed to
|
||||
// node_test_node_load() are correctly updated.
|
||||
$nodes = node_load_multiple(array(), array('status' => NODE_NOT_PUBLISHED));
|
||||
$nodes = entity_load_multiple_by_properties('node', array('status' => NODE_NOT_PUBLISHED));
|
||||
$loaded_node = end($nodes);
|
||||
$this->assertEqual($loaded_node->node_test_loaded_nids, array($node3->nid, $node4->nid), t('hook_node_load() received the correct list of node IDs the second time it was called.'));
|
||||
$this->assertEqual($loaded_node->node_test_loaded_types, array('article', 'page'), t('hook_node_load() received the correct list of node types the second time it was called.'));
|
||||
|
|
|
@ -43,7 +43,7 @@ class NodeLoadMultipleTest extends NodeTestBase {
|
|||
$this->assertNoText($node4->label(), t('Node title does not appear in the default listing.'));
|
||||
|
||||
// Load nodes with only a condition. Nodes 3 and 4 will be loaded.
|
||||
$nodes = node_load_multiple(FALSE, array('promote' => 0));
|
||||
$nodes = entity_load_multiple_by_properties('node', array('promote' => 0));
|
||||
$this->assertEqual($node3->label(), $nodes[$node3->nid]->label(), t('Node was loaded.'));
|
||||
$this->assertEqual($node4->label(), $nodes[$node4->nid]->label(), t('Node was loaded.'));
|
||||
$count = count($nodes);
|
||||
|
@ -59,30 +59,5 @@ class NodeLoadMultipleTest extends NodeTestBase {
|
|||
foreach ($nodes as $node) {
|
||||
$this->assertTrue(is_object($node), t('Node is an object'));
|
||||
}
|
||||
|
||||
// Load nodes by nid, where type = article. Nodes 1, 2 and 3 will be loaded.
|
||||
$nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article'));
|
||||
$count = count($nodes);
|
||||
$this->assertTrue($count == 3, t('@count nodes loaded', array('@count' => $count)));
|
||||
$this->assertEqual($nodes[$node1->nid]->label(), $node1->label(), t('Node successfully loaded.'));
|
||||
$this->assertEqual($nodes[$node2->nid]->label(), $node2->label(), t('Node successfully loaded.'));
|
||||
$this->assertEqual($nodes[$node3->nid]->label(), $node3->label(), t('Node successfully loaded.'));
|
||||
$this->assertFalse(isset($nodes[$node4->nid]));
|
||||
|
||||
// Now that all nodes have been loaded into the static cache, ensure that
|
||||
// they are loaded correctly again when a condition is passed.
|
||||
$nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article'));
|
||||
$count = count($nodes);
|
||||
$this->assertTrue($count == 3, t('@count nodes loaded.', array('@count' => $count)));
|
||||
$this->assertEqual($nodes[$node1->nid]->label(), $node1->label(), t('Node successfully loaded'));
|
||||
$this->assertEqual($nodes[$node2->nid]->label(), $node2->label(), t('Node successfully loaded'));
|
||||
$this->assertEqual($nodes[$node3->nid]->label(), $node3->label(), t('Node successfully loaded'));
|
||||
$this->assertFalse(isset($nodes[$node4->nid]), t('Node was not loaded'));
|
||||
|
||||
// Load nodes by nid, where type = article and promote = 0.
|
||||
$nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article', 'promote' => 0));
|
||||
$count = count($nodes);
|
||||
$this->assertTrue($count == 1, t('@count node loaded', array('@count' => $count)));
|
||||
$this->assertEqual($nodes[$node3->nid]->label(), $node3->label(), t('Node successfully loaded.'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ class NodeRevisionPermissionsTest extends NodeTestBase {
|
|||
* Tests the _node_revision_access() function.
|
||||
*/
|
||||
function testNodeRevisionAccess() {
|
||||
$revision = $this->node_revisions[1];
|
||||
$revision = node_revision_load($this->node_revisions[1]->vid);
|
||||
|
||||
$parameters = array(
|
||||
'op' => array_keys($this->map),
|
||||
|
|
|
@ -87,7 +87,7 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
$this->assertTrue(($nodes[1]->body[LANGUAGE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[LANGUAGE_NOT_SPECIFIED][0]['value']), t('Node reverted correctly.'));
|
||||
|
||||
// Confirm that this is not the current version.
|
||||
$node = node_load($node->nid, $node->vid);
|
||||
$node = node_revision_load($node->vid);
|
||||
$this->assertFalse($node->isCurrentRevision(), 'Third node revision is not the current one.');
|
||||
|
||||
// Confirm revisions delete properly.
|
||||
|
@ -136,7 +136,7 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
$node->save();
|
||||
$this->drupalGet('node/' . $node->nid);
|
||||
$this->assertText($new_title, t('New node title appears on the page.'));
|
||||
$node_revision = node_load($node->nid, NULL, TRUE);
|
||||
$node_revision = node_load($node->nid, TRUE);
|
||||
$this->assertEqual($node_revision->log, $log, t('After an existing node revision is re-saved without a log message, the original log message is preserved.'));
|
||||
|
||||
// Create another node with an initial log message.
|
||||
|
@ -154,7 +154,7 @@ class NodeRevisionsTest extends NodeTestBase {
|
|||
$node->save();
|
||||
$this->drupalGet('node/' . $node->nid);
|
||||
$this->assertText($new_title, 'New node title appears on the page.');
|
||||
$node_revision = node_load($node->nid, NULL, TRUE);
|
||||
$node_revision = node_load($node->nid, TRUE);
|
||||
$this->assertTrue(empty($node_revision->log), 'After a new node revision is saved with an empty log message, the log message for the node is empty.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,15 +81,15 @@ class PageEditTest extends NodeTestBase {
|
|||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
// Ensure that the node revision has been created.
|
||||
$revised_node = $this->drupalGetNodeByTitle($edit['title']);
|
||||
$revised_node = $this->drupalGetNodeByTitle($edit['title'], TRUE);
|
||||
$this->assertNotIdentical($node->vid, $revised_node->vid, 'A new revision has been created.');
|
||||
// Ensure that the node author is preserved when it was not changed in the
|
||||
// edit form.
|
||||
$this->assertIdentical($node->uid, $revised_node->uid, 'The node author has been preserved.');
|
||||
// Ensure that the revision authors are different since the revisions were
|
||||
// made by different users.
|
||||
$first_node_version = node_load($node->nid, $node->vid);
|
||||
$second_node_version = node_load($node->nid, $revised_node->vid);
|
||||
$first_node_version = node_revision_load($node->vid);
|
||||
$second_node_version = node_revision_load($revised_node->vid);
|
||||
$this->assertNotIdentical($first_node_version->revision_uid, $second_node_version->revision_uid, 'Each revision has a distinct user.');
|
||||
}
|
||||
|
||||
|
@ -122,14 +122,14 @@ class PageEditTest extends NodeTestBase {
|
|||
// authorship to the anonymous user (uid 0).
|
||||
$edit['name'] = '';
|
||||
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
||||
$node = node_load($node->nid, NULL, TRUE);
|
||||
$node = node_load($node->nid, TRUE);
|
||||
$this->assertIdentical($node->uid, '0', 'Node authored by anonymous user.');
|
||||
|
||||
// Change the authored by field to another user's name (that is not
|
||||
// logged in).
|
||||
$edit['name'] = $this->web_user->name;
|
||||
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
||||
$node = node_load($node->nid, NULL, TRUE);
|
||||
$node = node_load($node->nid, TRUE);
|
||||
$this->assertIdentical($node->uid, $this->web_user->uid, 'Node authored by normal user.');
|
||||
|
||||
// Check that normal users cannot change the authored by information.
|
||||
|
|
|
@ -313,7 +313,7 @@ function node_mass_update($nodes, $updates) {
|
|||
* @see node_mass_update()
|
||||
*/
|
||||
function _node_mass_update_helper($nid, $updates) {
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
// For efficiency manually save the original node before applying any changes.
|
||||
$node->original = clone $node;
|
||||
foreach ($updates as $name => $value) {
|
||||
|
|
|
@ -987,47 +987,47 @@ function node_invoke($node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
|
|||
* from the database. Nodes are loaded into memory and will not require
|
||||
* database access if loaded again during the same page request.
|
||||
*
|
||||
* @param array|bool $nids
|
||||
* (optional) An array of node IDs, or FALSE to load all nodes.
|
||||
* @param array $conditions
|
||||
* (deprecated) An associative array of conditions on the {node}
|
||||
* 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 array $nids
|
||||
* (optional) An array of entity IDs. If omitted, all entities are loaded.
|
||||
* @param bool $reset
|
||||
* (optional) Whether to reset the internal node_load() cache.
|
||||
*
|
||||
* @return array
|
||||
* An array of node entities indexed by nid.
|
||||
*
|
||||
* @todo Remove $conditions in Drupal 8.
|
||||
*
|
||||
* @see entity_load_multiple()
|
||||
* @see Drupal\entity\EntityFieldQuery
|
||||
*/
|
||||
function node_load_multiple($nids = array(), array $conditions = array(), $reset = FALSE) {
|
||||
return entity_load_multiple('node', $nids, $conditions, $reset);
|
||||
function node_load_multiple(array $nids = NULL, $reset = FALSE) {
|
||||
return entity_load_multiple('node', $nids, $reset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a node entity from the database.
|
||||
*
|
||||
* @param int $nid
|
||||
* (optional) The node ID.
|
||||
* @param int $vid
|
||||
* (optional) The revision ID.
|
||||
* The node ID.
|
||||
* @param bool $reset
|
||||
* (optional) Whether to reset the node_load_multiple() cache.
|
||||
*
|
||||
* @return Drupal\node\Node|false
|
||||
* A fully-populated node entity, or FALSE if the node is not found.
|
||||
*/
|
||||
function node_load($nid = NULL, $vid = NULL, $reset = FALSE) {
|
||||
$nids = (isset($nid) ? array($nid) : array());
|
||||
$conditions = (isset($vid) ? array('vid' => $vid) : array());
|
||||
$node = node_load_multiple($nids, $conditions, $reset);
|
||||
return $node ? reset($node) : FALSE;
|
||||
function node_load($nid = NULL, $reset = FALSE) {
|
||||
return entity_load('node', $nid, $reset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a node revision from the database.
|
||||
*
|
||||
* @param int $nid
|
||||
* The node revision id.
|
||||
*
|
||||
* @return Drupal\node\Node|false
|
||||
* A fully-populated node entity, or FALSE if the node is not found.
|
||||
*/
|
||||
function node_revision_load($vid = NULL) {
|
||||
return entity_revision_load('node', $vid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1102,10 +1102,9 @@ function node_delete_multiple($nids) {
|
|||
* TRUE if the revision deletion was successful.
|
||||
*/
|
||||
function node_revision_delete($revision_id) {
|
||||
if ($revision = node_load(NULL, $revision_id)) {
|
||||
if ($revision = node_revision_load($revision_id)) {
|
||||
// Prevent deleting the current revision.
|
||||
$node = node_load($revision->nid);
|
||||
if ($revision_id == $node->vid) {
|
||||
if ($revision->isCurrentRevision()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -1765,15 +1764,12 @@ function _node_revision_access(Node $node, $op = 'view', $account = NULL, $langc
|
|||
return $access[$cid] = FALSE;
|
||||
}
|
||||
|
||||
$node_current_revision = node_load($node->nid);
|
||||
$is_current_revision = $node_current_revision->vid == $node->vid;
|
||||
|
||||
// There should be at least two revisions. If the vid of the given node
|
||||
// and the vid of the current revision differ, then we already have two
|
||||
// different revisions so there is no need for a separate database check.
|
||||
// Also, if you try to revert to or delete the current revision, that's
|
||||
// not good.
|
||||
if ($is_current_revision && (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField() == 1 || $op == 'update' || $op == 'delete')) {
|
||||
if ($node->isCurrentRevision() && (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField() == 1 || $op == 'update' || $op == 'delete')) {
|
||||
$access[$cid] = FALSE;
|
||||
}
|
||||
elseif (user_access('administer nodes', $account)) {
|
||||
|
@ -1782,7 +1778,7 @@ function _node_revision_access(Node $node, $op = 'view', $account = NULL, $langc
|
|||
else {
|
||||
// First check the access to the current revision and finally, if the
|
||||
// node passed in is not the current revision then access to that, too.
|
||||
$access[$cid] = node_access($op, $node_current_revision, $account, $langcode) && ($is_current_revision || node_access($op, $node, $account, $langcode));
|
||||
$access[$cid] = node_access($op, node_load($node->nid), $account, $langcode) && ($node->isCurrentRevision() || node_access($op, $node, $account, $langcode));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1959,30 +1955,27 @@ function node_menu() {
|
|||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'node.pages.inc',
|
||||
);
|
||||
$items['node/%node/revisions/%/view'] = array(
|
||||
$items['node/%node/revisions/%node_revision/view'] = array(
|
||||
'title' => 'Revisions',
|
||||
'load arguments' => array(3),
|
||||
'page callback' => 'node_show',
|
||||
'page arguments' => array(1, TRUE),
|
||||
'page arguments' => array(3, TRUE),
|
||||
'access callback' => '_node_revision_access',
|
||||
'access arguments' => array(1),
|
||||
'access arguments' => array(3),
|
||||
);
|
||||
$items['node/%node/revisions/%/revert'] = array(
|
||||
$items['node/%node/revisions/%node_revision/revert'] = array(
|
||||
'title' => 'Revert to earlier revision',
|
||||
'load arguments' => array(3),
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('node_revision_revert_confirm', 1),
|
||||
'page arguments' => array('node_revision_revert_confirm', 3),
|
||||
'access callback' => '_node_revision_access',
|
||||
'access arguments' => array(1, 'update'),
|
||||
'access arguments' => array(3, 'update'),
|
||||
'file' => 'node.pages.inc',
|
||||
);
|
||||
$items['node/%node/revisions/%/delete'] = array(
|
||||
$items['node/%node/revisions/%node_revision/delete'] = array(
|
||||
'title' => 'Delete earlier revision',
|
||||
'load arguments' => array(3),
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('node_revision_delete_confirm', 1),
|
||||
'page arguments' => array('node_revision_delete_confirm', 3),
|
||||
'access callback' => '_node_revision_access',
|
||||
'access arguments' => array(1, 'delete'),
|
||||
'access arguments' => array(3, 'delete'),
|
||||
'file' => 'node.pages.inc',
|
||||
);
|
||||
return $items;
|
||||
|
@ -3483,7 +3476,7 @@ function node_access_rebuild($batch_mode = FALSE) {
|
|||
// Rebuild newest nodes first so that recent content becomes available quickly.
|
||||
$nids = db_query("SELECT nid FROM {node} ORDER BY nid DESC")->fetchCol();
|
||||
foreach ($nids as $nid) {
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
$node = node_load($nid, TRUE);
|
||||
// To preserve database integrity, only acquire grants if the node
|
||||
// loads successfully.
|
||||
if (!empty($node)) {
|
||||
|
@ -3531,7 +3524,7 @@ function _node_access_rebuild_batch_operation(&$context) {
|
|||
// Process the next 20 nodes.
|
||||
$limit = 20;
|
||||
$nids = db_query_range("SELECT nid FROM {node} WHERE nid > :nid ORDER BY nid ASC", 0, $limit, array(':nid' => $context['sandbox']['current_node']))->fetchCol();
|
||||
$nodes = node_load_multiple($nids, array(), TRUE);
|
||||
$nodes = node_load_multiple($nids, TRUE);
|
||||
foreach ($nodes as $nid => $node) {
|
||||
// To preserve database integrity, only acquire grants if the node
|
||||
// loads successfully.
|
||||
|
|
|
@ -64,7 +64,7 @@ class PollTokenReplaceTest extends PollTestBase {
|
|||
$this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
|
||||
$this->drupalLogout();
|
||||
|
||||
$poll = node_load($poll_nid, NULL, TRUE);
|
||||
$poll = node_load($poll_nid, TRUE);
|
||||
|
||||
// Generate and test sanitized tokens.
|
||||
$tests = array();
|
||||
|
|
|
@ -89,7 +89,7 @@ class SearchCommentTest extends SearchTestBase {
|
|||
'search_block_form' => "'" . $edit_comment['subject'] . "'",
|
||||
);
|
||||
$this->drupalPost('', $edit, t('Search'));
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
$node2 = node_load($node->nid, TRUE);
|
||||
$this->assertText($node2->label(), t('Node found in search results.'));
|
||||
$this->assertText($edit_comment['subject'], t('Comment subject found in search results.'));
|
||||
|
||||
|
|
|
@ -157,13 +157,16 @@ abstract class WebTestBase extends TestBase {
|
|||
* @param $title
|
||||
* A node title, usually generated by $this->randomName().
|
||||
* @param $reset
|
||||
* (optional) Whether to reset the internal node_load() cache.
|
||||
* (optional) Whether to reset the entity cache.
|
||||
*
|
||||
* @return
|
||||
* A node entity matching $title.
|
||||
*/
|
||||
function drupalGetNodeByTitle($title, $reset = FALSE) {
|
||||
$nodes = node_load_multiple(array(), array('title' => $title), $reset);
|
||||
if ($reset) {
|
||||
entity_get_controller('node')->resetCache();
|
||||
}
|
||||
$nodes = entity_load_multiple_by_properties('node', array('title' => $title));
|
||||
// Load the first node returned from the database.
|
||||
$returned_node = reset($nodes);
|
||||
return $returned_node;
|
||||
|
|
|
@ -31,7 +31,7 @@ class LoadTest extends FileHookTestBase {
|
|||
* Try to load a non-existent file by URI.
|
||||
*/
|
||||
function testLoadMissingFilepath() {
|
||||
$files = file_load_multiple(array(), array('uri' => 'foobar://misc/druplicon.png'));
|
||||
$files = entity_load_multiple_by_properties('file', array('uri' => 'foobar://misc/druplicon.png'));
|
||||
$this->assertFalse(reset($files), t("Try to load a file that doesn't exist in the database fails."));
|
||||
$this->assertFileHooksCalled(array());
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class LoadTest extends FileHookTestBase {
|
|||
* Try to load a non-existent file by status.
|
||||
*/
|
||||
function testLoadInvalidStatus() {
|
||||
$files = file_load_multiple(array(), array('status' => -99));
|
||||
$files = entity_load_multiple_by_properties('file', array('status' => -99));
|
||||
$this->assertFalse(reset($files), t("Trying to load a file with an invalid status fails."));
|
||||
$this->assertFileHooksCalled(array());
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class LoadTest extends FileHookTestBase {
|
|||
|
||||
// Load by path.
|
||||
file_test_reset();
|
||||
$by_path_files = file_load_multiple(array(), array('uri' => $file->uri));
|
||||
$by_path_files = entity_load_multiple_by_properties('file', array('uri' => $file->uri));
|
||||
$this->assertFileHookCalled('load');
|
||||
$this->assertEqual(1, count($by_path_files), t('file_load_multiple() returned an array of the correct size.'));
|
||||
$by_path_file = reset($by_path_files);
|
||||
|
@ -81,7 +81,7 @@ class LoadTest extends FileHookTestBase {
|
|||
|
||||
// Load by fid.
|
||||
file_test_reset();
|
||||
$by_fid_files = file_load_multiple(array($file->fid), array());
|
||||
$by_fid_files = file_load_multiple(array($file->fid));
|
||||
$this->assertFileHookCalled('load');
|
||||
$this->assertEqual(1, count($by_fid_files), t('file_load_multiple() returned an array of the correct size.'));
|
||||
$by_fid_file = reset($by_fid_files);
|
||||
|
|
|
@ -113,9 +113,6 @@ class SaveUploadTest extends FileHookTestBase {
|
|||
$this->assertResponse(200, t('Received a 200 response for posted test file.'));
|
||||
$this->assertRaw(t('You WIN!'));
|
||||
$this->assertTrue(is_file('temporary://' . $dir . '/' . trim(drupal_basename($image3_realpath))));
|
||||
|
||||
// Check that file_load_multiple() with no arguments returns FALSE.
|
||||
$this->assertFalse(file_load_multiple(), t('No files were loaded.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -308,7 +308,7 @@ class BreadcrumbTest extends MenuTestBase {
|
|||
// the breadcrumb based on taxonomy term hierarchy.
|
||||
$parent_tid = 0;
|
||||
foreach ($tags as $name => $null) {
|
||||
$terms = taxonomy_term_load_multiple(FALSE, array('name' => $name));
|
||||
$terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $name));
|
||||
$term = reset($terms);
|
||||
$tags[$name]['term'] = $term;
|
||||
if ($parent_tid) {
|
||||
|
|
|
@ -43,20 +43,11 @@ class TermStorageController extends DatabaseStorageController {
|
|||
/**
|
||||
* Overrides Drupal\entity\DatabaseStorageController::buildQuery().
|
||||
*/
|
||||
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
|
||||
$query = parent::buildQuery($ids, $conditions, $revision_id);
|
||||
protected function buildQuery($ids, $revision_id = FALSE) {
|
||||
$query = parent::buildQuery($ids, $revision_id);
|
||||
$query->addTag('translatable');
|
||||
$query->addTag('term_access');
|
||||
// When name is passed as a condition use LIKE.
|
||||
if (isset($conditions['name'])) {
|
||||
$query_conditions = &$query->conditions();
|
||||
foreach ($query_conditions as $key => $condition) {
|
||||
if (is_array($condition) && $condition['field'] == 'base.name') {
|
||||
$query_conditions[$key]['operator'] = 'LIKE';
|
||||
$query_conditions[$key]['value'] = db_like($query_conditions[$key]['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the machine name field from the {taxonomy_vocabulary} table.
|
||||
$query->innerJoin('taxonomy_vocabulary', 'v', 'base.vid = v.vid');
|
||||
$query->addField('v', 'machine_name', 'vocabulary_machine_name');
|
||||
|
@ -64,18 +55,14 @@ class TermStorageController extends DatabaseStorageController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Overrides Drupal\entity\DatabaseStorageController::cacheGet().
|
||||
* Overrides Drupal\entity\DatabaseStorageController::buildPropertyQuery().
|
||||
*/
|
||||
protected function cacheGet($ids, $conditions = array()) {
|
||||
$terms = parent::cacheGet($ids, $conditions);
|
||||
// Name matching is case insensitive, note that with some collations
|
||||
// LOWER() and drupal_strtolower() may return different results.
|
||||
foreach ($terms as $term) {
|
||||
if (isset($conditions['name']) && drupal_strtolower($conditions['name'] != drupal_strtolower($term->name))) {
|
||||
unset($terms[$term->tid]);
|
||||
}
|
||||
protected function buildPropertyQuery(\Drupal\entity\EntityFieldQuery $entity_query, array $values) {
|
||||
if (isset($values['name'])) {
|
||||
$entity_query->propertyCondition('name', $values['name'], 'LIKE');
|
||||
unset($values['name']);
|
||||
}
|
||||
return $terms;
|
||||
parent::buildPropertyQuery($entity_query, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,7 +41,7 @@ class LoadMultipleTest extends TaxonomyTestBase {
|
|||
$this->createTerm($vocabulary);
|
||||
}
|
||||
// Load the terms from the vocabulary.
|
||||
$terms = taxonomy_term_load_multiple(FALSE, array('vid' => $vocabulary->vid));
|
||||
$terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->vid));
|
||||
$count = count($terms);
|
||||
$this->assertEqual($count, 5, format_string('Correct number of terms were loaded. !count terms.', array('!count' => $count)));
|
||||
|
||||
|
@ -50,24 +50,20 @@ class LoadMultipleTest extends TaxonomyTestBase {
|
|||
$this->assertEqual($count, count($terms2), 'Five terms were loaded by tid.');
|
||||
$this->assertEqual($terms, $terms2, 'Both arrays contain the same terms.');
|
||||
|
||||
// Load the terms by tid, with a condition on vid.
|
||||
$terms3 = taxonomy_term_load_multiple(array_keys($terms2), array('vid' => $vocabulary->vid));
|
||||
$this->assertEqual($terms2, $terms3, 'Same terms found when limiting load to vocabulary.');
|
||||
|
||||
// Remove one term from the array, then delete it.
|
||||
$deleted = array_shift($terms3);
|
||||
$deleted = array_shift($terms2);
|
||||
taxonomy_term_delete($deleted->tid);
|
||||
$deleted_term = taxonomy_term_load($deleted->tid);
|
||||
$this->assertFalse($deleted_term);
|
||||
|
||||
// Load terms from the vocabulary by vid.
|
||||
$terms4 = taxonomy_term_load_multiple(FALSE, array('vid' => $vocabulary->vid));
|
||||
$this->assertEqual(count($terms4), 4, 'Correct number of terms were loaded.');
|
||||
$this->assertFalse(isset($terms4[$deleted->tid]));
|
||||
$terms3 = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->vid));
|
||||
$this->assertEqual(count($terms3), 4, 'Correct number of terms were loaded.');
|
||||
$this->assertFalse(isset($terms3[$deleted->tid]));
|
||||
|
||||
// Create a single term and load it by name.
|
||||
$term = $this->createTerm($vocabulary);
|
||||
$loaded_terms = taxonomy_term_load_multiple(array(), array('name' => $term->name));
|
||||
$loaded_terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $term->name));
|
||||
$this->assertEqual(count($loaded_terms), 1, 'One term was loaded.');
|
||||
$loaded_term = reset($loaded_terms);
|
||||
$this->assertEqual($term->tid, $loaded_term->tid, 'Term loaded by name successfully.');
|
||||
|
|
|
@ -25,7 +25,7 @@ class TermUnitTest extends TaxonomyTestBase {
|
|||
$valid_term = $this->createTerm($vocabulary);
|
||||
// Delete a valid term.
|
||||
taxonomy_term_delete($valid_term->tid);
|
||||
$terms = taxonomy_term_load_multiple(array(), array('vid' => $vocabulary->vid));
|
||||
$terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->vid));
|
||||
$this->assertTrue(empty($terms), 'Vocabulary is empty after deletion');
|
||||
|
||||
// Delete an invalid term. Should not throw any notices.
|
||||
|
|
|
@ -85,7 +85,7 @@ class VocabularyTest extends TaxonomyTestBase {
|
|||
$this->createVocabulary();
|
||||
}
|
||||
// Get all vocabularies and change their weights.
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple();
|
||||
$edit = array();
|
||||
foreach ($vocabularies as $key => $vocabulary) {
|
||||
$vocabulary->weight = -$vocabulary->weight;
|
||||
|
@ -96,7 +96,7 @@ class VocabularyTest extends TaxonomyTestBase {
|
|||
$this->drupalPost('admin/structure/taxonomy', $edit, t('Save'));
|
||||
|
||||
// Load the vocabularies from the database.
|
||||
$new_vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
|
||||
$new_vocabularies = taxonomy_vocabulary_load_multiple();
|
||||
|
||||
// Check that the weights are saved in the database correctly.
|
||||
foreach ($vocabularies as $key => $vocabulary) {
|
||||
|
@ -109,12 +109,12 @@ class VocabularyTest extends TaxonomyTestBase {
|
|||
*/
|
||||
function testTaxonomyAdminNoVocabularies() {
|
||||
// Delete all vocabularies.
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple();
|
||||
foreach ($vocabularies as $key => $vocabulary) {
|
||||
taxonomy_vocabulary_delete($key);
|
||||
}
|
||||
// Confirm that no vocabularies are found in the database.
|
||||
$this->assertFalse(taxonomy_vocabulary_load_multiple(FALSE), 'No vocabularies found in the database.');
|
||||
$this->assertFalse(taxonomy_vocabulary_load_multiple(), 'No vocabularies found in the database.');
|
||||
$this->drupalGet('admin/structure/taxonomy');
|
||||
// Check the default message for no vocabularies.
|
||||
$this->assertText(t('No vocabularies available.'), 'No vocabularies were found.');
|
||||
|
@ -133,7 +133,7 @@ class VocabularyTest extends TaxonomyTestBase {
|
|||
$this->assertText(t('Created new vocabulary'), 'New vocabulary was created.');
|
||||
|
||||
// Check the created vocabulary.
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple();
|
||||
$vid = $vocabularies[count($vocabularies) - 1]->vid;
|
||||
entity_get_controller('taxonomy_vocabulary')->resetCache();
|
||||
$vocabulary = taxonomy_vocabulary_load($vid);
|
||||
|
|
|
@ -41,7 +41,7 @@ class VocabularyUnitTest extends TaxonomyTestBase {
|
|||
*/
|
||||
function testTaxonomyVocabularyLoadReturnFalse() {
|
||||
// Load a vocabulary that doesn't exist.
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple();
|
||||
$vid = count($vocabularies) + 1;
|
||||
$vocabulary = taxonomy_vocabulary_load($vid);
|
||||
// This should not return an object because no such vocabulary exists.
|
||||
|
@ -61,7 +61,7 @@ class VocabularyUnitTest extends TaxonomyTestBase {
|
|||
*/
|
||||
function testTaxonomyVocabularyDeleteWithTerms() {
|
||||
// Delete any existing vocabularies.
|
||||
foreach (taxonomy_vocabulary_load_multiple(FALSE) as $vocabulary) {
|
||||
foreach (taxonomy_vocabulary_load_multiple() as $vocabulary) {
|
||||
taxonomy_vocabulary_delete($vocabulary->vid);
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ class VocabularyUnitTest extends TaxonomyTestBase {
|
|||
|
||||
// Delete the vocabulary.
|
||||
taxonomy_vocabulary_delete($this->vocabulary->vid);
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple();
|
||||
$this->assertTrue(!isset($vocabularies[$this->vocabulary->vid]), 'The vocabulary was deleted.');
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ class VocabularyUnitTest extends TaxonomyTestBase {
|
|||
function testTaxonomyVocabularyLoadMultiple() {
|
||||
|
||||
// Delete any existing vocabularies.
|
||||
foreach (taxonomy_vocabulary_load_multiple(FALSE) as $vocabulary) {
|
||||
foreach (taxonomy_vocabulary_load_multiple() as $vocabulary) {
|
||||
taxonomy_vocabulary_delete($vocabulary->vid);
|
||||
}
|
||||
|
||||
|
@ -141,9 +141,9 @@ class VocabularyUnitTest extends TaxonomyTestBase {
|
|||
$names = taxonomy_vocabulary_get_names();
|
||||
$this->assertEqual($names[$vocabulary1->machine_name]->name, $vocabulary1->name, 'Vocabulary 1 name found.');
|
||||
|
||||
// Fetch all of the vocabularies using taxonomy_vocabulary_load_multiple(FALSE).
|
||||
// Fetch all of the vocabularies using taxonomy_vocabulary_load_multiple().
|
||||
// Confirm that the vocabularies are ordered by weight.
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple();
|
||||
$this->assertEqual(array_shift($vocabularies)->vid, $vocabulary1->vid, 'Vocabulary was found in the vocabularies array.');
|
||||
$this->assertEqual(array_shift($vocabularies)->vid, $vocabulary2->vid, 'Vocabulary was found in the vocabularies array.');
|
||||
$this->assertEqual(array_shift($vocabularies)->vid, $vocabulary3->vid, 'Vocabulary was found in the vocabularies array.');
|
||||
|
@ -156,7 +156,7 @@ class VocabularyUnitTest extends TaxonomyTestBase {
|
|||
$this->assertEqual(array_shift($vocabularies)->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by ID.');
|
||||
|
||||
// Fetch vocabulary 1 by name.
|
||||
$vocabulary = current(taxonomy_vocabulary_load_multiple(array(), array('name' => $vocabulary1->name)));
|
||||
$vocabulary = current(entity_load_multiple_by_properties('taxonomy_vocabulary', array('name' => $vocabulary1->name)));
|
||||
$this->assertEqual($vocabulary->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by name.');
|
||||
|
||||
// Fetch vocabulary 1 by name and ID.
|
||||
|
|
|
@ -18,8 +18,8 @@ class VocabularyStorageController extends DatabaseStorageController {
|
|||
/**
|
||||
* Overrides Drupal\entity\DatabaseStorageController::buildQuery().
|
||||
*/
|
||||
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
|
||||
$query = parent::buildQuery($ids, $conditions, $revision_id);
|
||||
protected function buildQuery($ids, $revision_id = FALSE) {
|
||||
$query = parent::buildQuery($ids, $revision_id);
|
||||
$query->addTag('translatable');
|
||||
$query->orderBy('base.weight');
|
||||
$query->orderBy('base.name');
|
||||
|
|
|
@ -16,7 +16,7 @@ use Drupal\taxonomy\Vocabulary;
|
|||
* @see theme_taxonomy_overview_vocabularies()
|
||||
*/
|
||||
function taxonomy_overview_vocabularies($form) {
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple();
|
||||
$form['#tree'] = TRUE;
|
||||
foreach ($vocabularies as $vocabulary) {
|
||||
$form[$vocabulary->vid]['#vocabulary'] = $vocabulary;
|
||||
|
|
|
@ -89,7 +89,7 @@ function taxonomy_permission() {
|
|||
'title' => t('Administer vocabularies and terms'),
|
||||
),
|
||||
);
|
||||
foreach (taxonomy_vocabulary_load_multiple(FALSE) as $vocabulary) {
|
||||
foreach (taxonomy_vocabulary_load_multiple() as $vocabulary) {
|
||||
$permissions += array(
|
||||
'edit terms in ' . $vocabulary->vid => array(
|
||||
'title' => t('Edit terms in %vocabulary', array('%vocabulary' => $vocabulary->name)),
|
||||
|
@ -920,18 +920,18 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities
|
|||
* An array of matching term objects.
|
||||
*/
|
||||
function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) {
|
||||
$conditions = array('name' => trim($name));
|
||||
$values = array('name' => trim($name));
|
||||
if (isset($vocabulary)) {
|
||||
$vocabularies = taxonomy_vocabulary_get_names();
|
||||
if (isset($vocabularies[$vocabulary])){
|
||||
$conditions['vid'] = $vocabularies[$vocabulary]->vid;
|
||||
$values['vid'] = $vocabularies[$vocabulary]->vid;
|
||||
}
|
||||
else {
|
||||
// Return an empty array when filtering by a non-existing vocabulary.
|
||||
return array();
|
||||
}
|
||||
}
|
||||
return taxonomy_term_load_multiple(array(), $conditions);
|
||||
return entity_load_multiple_by_properties('taxonomy_term', $values);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -944,23 +944,15 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) {
|
|||
* @see entity_load_multiple()
|
||||
* @see Drupal\entity\EntityFieldQuery
|
||||
*
|
||||
* @param array|bool $tids
|
||||
* An array of taxonomy term IDs, or FALSE to load all terms.
|
||||
* @param array $conditions
|
||||
* (deprecated) An associative array of conditions on the {taxonomy_term}
|
||||
* 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 array $tids
|
||||
* (optional) An array of entity IDs. If omitted, all entities are loaded.
|
||||
*
|
||||
* @return array
|
||||
* An array of taxonomy term entities, indexed by tid. When no results are
|
||||
* found, an empty array is returned.
|
||||
*
|
||||
* @todo Remove $conditions in Drupal 8.
|
||||
*/
|
||||
function taxonomy_term_load_multiple($tids = array(), array $conditions = array()) {
|
||||
return entity_load_multiple('taxonomy_term', $tids, $conditions);
|
||||
function taxonomy_term_load_multiple(array $tids = NULL) {
|
||||
return entity_load_multiple('taxonomy_term', $tids);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -972,16 +964,14 @@ function taxonomy_term_load_multiple($tids = array(), array $conditions = array(
|
|||
*
|
||||
* @see entity_load_multiple()
|
||||
*
|
||||
* @param array|bool $vids
|
||||
* An array of taxonomy vocabulary IDs, or FALSE to load all vocabularies.
|
||||
* @param array $conditions
|
||||
* An array of conditions to add to the query.
|
||||
* @param array $vids
|
||||
* (optional) An array of entity IDs. If omitted, all entities are loaded.
|
||||
*
|
||||
* @return array
|
||||
* An array of vocabulary objects, indexed by vid.
|
||||
*/
|
||||
function taxonomy_vocabulary_load_multiple($vids = array(), array $conditions = array()) {
|
||||
return entity_load_multiple('taxonomy_vocabulary', $vids, $conditions);
|
||||
function taxonomy_vocabulary_load_multiple(array $vids = NULL) {
|
||||
return entity_load_multiple('taxonomy_vocabulary', $vids);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1013,7 +1003,7 @@ function taxonomy_vocabulary_load($vid) {
|
|||
* @see taxonomy_vocabulary_load()
|
||||
*/
|
||||
function taxonomy_vocabulary_machine_name_load($name) {
|
||||
$result = entity_load_multiple('taxonomy_vocabulary', FALSE, array('machine_name' => $name));
|
||||
$result = entity_load_multiple_by_properties('taxonomy_vocabulary', array('machine_name' => $name));
|
||||
return reset($result);
|
||||
}
|
||||
|
||||
|
@ -1414,7 +1404,7 @@ function taxonomy_autocomplete_validate($element, &$form_state) {
|
|||
foreach ($typed_terms as $typed_term) {
|
||||
// See if the term exists in the chosen vocabulary and return the tid;
|
||||
// otherwise, create a new 'autocreate' term for insert/update.
|
||||
if ($possibilities = taxonomy_term_load_multiple(array(), array('name' => trim($typed_term), 'vid' => array_keys($vocabularies)))) {
|
||||
if ($possibilities = entity_load_multiple_by_properties('taxonomy_term', array('name' => trim($typed_term), 'vid' => array_keys($vocabularies)))) {
|
||||
$term = array_pop($possibilities);
|
||||
}
|
||||
else {
|
||||
|
@ -1444,7 +1434,7 @@ function taxonomy_field_widget_error($element, $error, $form, &$form_state) {
|
|||
*/
|
||||
function taxonomy_field_settings_form($field, $instance, $has_data) {
|
||||
// Get proper values for 'allowed_values_function', which is a core setting.
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
|
||||
$vocabularies = taxonomy_vocabulary_load_multiple();
|
||||
$options = array();
|
||||
foreach ($vocabularies as $vocabulary) {
|
||||
$options[$vocabulary->machine_name] = $vocabulary->name;
|
||||
|
|
|
@ -58,7 +58,7 @@ class UserCancelTest extends WebTestBase {
|
|||
$this->assertTrue($account->status == 1, t('User account was not canceled.'));
|
||||
|
||||
// Confirm user's content has not been altered.
|
||||
$test_node = node_load($node->nid, NULL, TRUE);
|
||||
$test_node = node_load($node->nid, TRUE);
|
||||
$this->assertTrue(($test_node->uid == $account->uid && $test_node->status == 1), t('Node of the user has not been altered.'));
|
||||
}
|
||||
|
||||
|
@ -135,11 +135,11 @@ class UserCancelTest extends WebTestBase {
|
|||
$bogus_timestamp = $timestamp - 86400 - 60;
|
||||
$this->drupalGet("user/$account->uid/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login));
|
||||
$this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), t('Expired cancel account request rejected.'));
|
||||
$accounts = user_load_multiple(array($account->uid), array('status' => 1));
|
||||
$this->assertTrue(reset($accounts), t('User account was not canceled.'));
|
||||
$account = user_load($account->uid, TRUE);
|
||||
$this->assertTrue($account->status, t('User account was not canceled.'));
|
||||
|
||||
// Confirm user's content has not been altered.
|
||||
$test_node = node_load($node->nid, NULL, TRUE);
|
||||
$test_node = node_load($node->nid, TRUE);
|
||||
$this->assertTrue(($test_node->uid == $account->uid && $test_node->status == 1), t('Node of the user has not been altered.'));
|
||||
}
|
||||
|
||||
|
@ -213,9 +213,9 @@ class UserCancelTest extends WebTestBase {
|
|||
$this->assertTrue($account->status == 0, t('User has been blocked.'));
|
||||
|
||||
// Confirm user's content has been unpublished.
|
||||
$test_node = node_load($node->nid, NULL, TRUE);
|
||||
$test_node = node_load($node->nid, TRUE);
|
||||
$this->assertTrue($test_node->status == 0, t('Node of the user has been unpublished.'));
|
||||
$test_node = node_load($node->nid, $node->vid, TRUE);
|
||||
$test_node = node_revision_load($node->vid);
|
||||
$this->assertTrue($test_node->status == 0, t('Node revision of the user has been unpublished.'));
|
||||
|
||||
// Confirm user is logged out.
|
||||
|
@ -262,11 +262,11 @@ class UserCancelTest extends WebTestBase {
|
|||
$this->assertFalse(user_load($account->uid, TRUE), t('User is not found in the database.'));
|
||||
|
||||
// Confirm that user's content has been attributed to anonymous user.
|
||||
$test_node = node_load($node->nid, NULL, TRUE);
|
||||
$test_node = node_load($node->nid, TRUE);
|
||||
$this->assertTrue(($test_node->uid == 0 && $test_node->status == 1), t('Node of the user has been attributed to anonymous user.'));
|
||||
$test_node = node_load($revision_node->nid, $revision, TRUE);
|
||||
$test_node = node_revision_load($revision, TRUE);
|
||||
$this->assertTrue(($test_node->revision_uid == 0 && $test_node->status == 1), t('Node revision of the user has been attributed to anonymous user.'));
|
||||
$test_node = node_load($revision_node->nid, NULL, TRUE);
|
||||
$test_node = node_load($revision_node->nid, TRUE);
|
||||
$this->assertTrue(($test_node->uid != 0 && $test_node->status == 1), t("Current revision of the user's node was not attributed to anonymous user."));
|
||||
|
||||
// Confirm that user is logged out.
|
||||
|
@ -297,7 +297,7 @@ class UserCancelTest extends WebTestBase {
|
|||
$this->drupalPost('comment/reply/' . $node->nid, $edit, t('Preview'));
|
||||
$this->drupalPost(NULL, array(), t('Save'));
|
||||
$this->assertText(t('Your comment has been posted.'));
|
||||
$comments = comment_load_multiple(FALSE, array('subject' => $edit['subject']));
|
||||
$comments = entity_load_multiple_by_properties('comment', array('subject' => $edit['subject']));
|
||||
$comment = reset($comments);
|
||||
$this->assertTrue($comment->cid, t('Comment found.'));
|
||||
|
||||
|
@ -326,9 +326,9 @@ class UserCancelTest extends WebTestBase {
|
|||
$this->assertFalse(user_load($account->uid, TRUE), t('User is not found in the database.'));
|
||||
|
||||
// Confirm that user's content has been deleted.
|
||||
$this->assertFalse(node_load($node->nid, NULL, TRUE), t('Node of the user has been deleted.'));
|
||||
$this->assertFalse(node_load($node->nid, $revision, TRUE), t('Node revision of the user has been deleted.'));
|
||||
$this->assertTrue(node_load($revision_node->nid, NULL, TRUE), t("Current revision of the user's node was not deleted."));
|
||||
$this->assertFalse(node_load($node->nid, TRUE), t('Node of the user has been deleted.'));
|
||||
$this->assertFalse(node_revision_load($revision), t('Node revision of the user has been deleted.'));
|
||||
$this->assertTrue(node_load($revision_node->nid, TRUE), t("Current revision of the user's node was not deleted."));
|
||||
$this->assertFalse(comment_load($comment->cid), t('Comment of the user has been deleted.'));
|
||||
|
||||
// Confirm that user is logged out.
|
||||
|
|
|
@ -42,7 +42,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
$this->drupalPost('user/register', $edit, t('Create new account'));
|
||||
$this->assertText(t('A welcome message with further instructions has been sent to your e-mail address.'), t('User registered successfully.'));
|
||||
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$new_user = reset($accounts);
|
||||
$this->assertTrue($new_user->status, t('New account is active after registration.'));
|
||||
|
||||
|
@ -52,7 +52,8 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$edit['name'] = $name = $this->randomName();
|
||||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
$this->drupalPost('user/register', $edit, t('Create new account'));
|
||||
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
|
||||
entity_get_controller('user')->resetCache();
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$new_user = reset($accounts);
|
||||
$this->assertFalse($new_user->status, t('New account is blocked until approved by an administrator.'));
|
||||
}
|
||||
|
@ -77,7 +78,8 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$edit['pass[pass1]'] = $new_pass = $this->randomName();
|
||||
$edit['pass[pass2]'] = $new_pass;
|
||||
$this->drupalPost('user/register', $edit, t('Create new account'));
|
||||
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
|
||||
entity_get_controller('user')->resetCache();
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$new_user = reset($accounts);
|
||||
$this->assertText(t('Registration successful. You are now logged in.'), t('Users are logged in after registering.'));
|
||||
$this->drupalLogout();
|
||||
|
@ -101,7 +103,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->assertText(t('The username @name has not been activated or is blocked.', array('@name' => $name)), t('User cannot login yet.'));
|
||||
|
||||
// Activate the new account.
|
||||
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$new_user = reset($accounts);
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$this->drupalLogin($admin_user);
|
||||
|
@ -165,7 +167,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->drupalPost(NULL, $edit, t('Create new account'));
|
||||
|
||||
// Check user fields.
|
||||
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$new_user = reset($accounts);
|
||||
$this->assertEqual($new_user->name, $name, t('Username matches.'));
|
||||
$this->assertEqual($new_user->mail, $mail, t('E-mail address matches.'));
|
||||
|
@ -229,7 +231,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$edit['test_user_field[und][0][value]'] = $value;
|
||||
$this->drupalPost(NULL, $edit, t('Create new account'));
|
||||
// Check user fields.
|
||||
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$new_user = reset($accounts);
|
||||
$this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][0]['value'], $value, t('The field value was correclty saved.'));
|
||||
|
||||
|
@ -257,7 +259,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
$this->drupalPost(NULL, $edit, t('Create new account'));
|
||||
// Check user fields.
|
||||
$accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$new_user = reset($accounts);
|
||||
$this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][0]['value'], $value, t('@js : The field value was correclty saved.', array('@js' => $js)));
|
||||
$this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][1]['value'], $value + 1, t('@js : The field value was correclty saved.', array('@js' => $js)));
|
||||
|
|
|
@ -22,7 +22,7 @@ class UserStorageController extends DatabaseStorageController {
|
|||
/**
|
||||
* Overrides Drupal\entity\DatabaseStorageController::attachLoad().
|
||||
*/
|
||||
function attachLoad(&$queried_users, $revision_id = FALSE) {
|
||||
function attachLoad(&$queried_users, $load_revision = FALSE) {
|
||||
// Build an array of user picture IDs so that these can be fetched later.
|
||||
$picture_fids = array();
|
||||
foreach ($queried_users as $key => $record) {
|
||||
|
@ -56,7 +56,7 @@ class UserStorageController extends DatabaseStorageController {
|
|||
}
|
||||
// Call the default attachLoad() method. This will add fields and call
|
||||
// hook_user_load().
|
||||
parent::attachLoad($queried_users, $revision_id);
|
||||
parent::attachLoad($queried_users, $load_revision);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -278,14 +278,8 @@ function user_external_load($authname) {
|
|||
* from the database. Users are loaded into memory and will not require
|
||||
* database access if loaded again during the same page request.
|
||||
*
|
||||
* @param array|bool $uids
|
||||
* An array of user IDs, or FALSE to load all users.
|
||||
* @param array $conditions
|
||||
* (deprecated) An associative array of conditions on the {users}
|
||||
* 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 array $uids
|
||||
* (optional) An array of entity IDs. If omitted, all entities are loaded.
|
||||
* @param bool $reset
|
||||
* A boolean indicating that the internal cache should be reset. Use this if
|
||||
* loading a user object which has been altered during the page request.
|
||||
|
@ -298,11 +292,9 @@ function user_external_load($authname) {
|
|||
* @see user_load_by_mail()
|
||||
* @see user_load_by_name()
|
||||
* @see Drupal\entity\EntityFieldQuery
|
||||
*
|
||||
* @todo Remove $conditions in Drupal 8.
|
||||
*/
|
||||
function user_load_multiple($uids = array(), array $conditions = array(), $reset = FALSE) {
|
||||
return entity_load_multiple('user', $uids, $conditions, $reset);
|
||||
function user_load_multiple(array $uids = NULL, $reset = FALSE) {
|
||||
return entity_load_multiple('user', $uids, $reset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -345,7 +337,7 @@ function user_load($uid, $reset = FALSE) {
|
|||
* @see user_load_multiple()
|
||||
*/
|
||||
function user_load_by_mail($mail) {
|
||||
$users = entity_load_multiple('user', FALSE, array('mail' => $mail));
|
||||
$users = entity_load_multiple_by_properties('user', array('mail' => $mail));
|
||||
return reset($users);
|
||||
}
|
||||
|
||||
|
@ -361,7 +353,7 @@ function user_load_by_mail($mail) {
|
|||
* @see user_load_multiple()
|
||||
*/
|
||||
function user_load_by_name($name) {
|
||||
$users = entity_load_multiple('user', FALSE, array('name' => $name));
|
||||
$users = entity_load_multiple_by_properties('user', array('name' => $name));
|
||||
return reset($users);
|
||||
}
|
||||
|
||||
|
@ -2005,7 +1997,7 @@ function user_delete($uid) {
|
|||
*/
|
||||
function user_delete_multiple(array $uids) {
|
||||
if (!empty($uids)) {
|
||||
$accounts = user_load_multiple($uids, array());
|
||||
$accounts = user_load_multiple($uids);
|
||||
|
||||
$transaction = db_transaction();
|
||||
try {
|
||||
|
|
|
@ -61,11 +61,11 @@ function user_pass() {
|
|||
function user_pass_validate($form, &$form_state) {
|
||||
$name = trim($form_state['values']['name']);
|
||||
// Try to load by email.
|
||||
$users = user_load_multiple(array(), array('mail' => $name, 'status' => '1'));
|
||||
$users = entity_load_multiple_by_properties('user', array('mail' => $name, 'status' => '1'));
|
||||
$account = reset($users);
|
||||
if (!$account) {
|
||||
// No success, try to load by name.
|
||||
$users = user_load_multiple(array(), array('name' => $name, 'status' => '1'));
|
||||
$users = entity_load_multiple_by_properties('user', array('name' => $name, 'status' => '1'));
|
||||
$account = reset($users);
|
||||
}
|
||||
if (isset($account->uid)) {
|
||||
|
@ -122,9 +122,9 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a
|
|||
// 86400 seconds.
|
||||
$timeout = variable_get('user_password_reset_timeout', 86400);
|
||||
$current = REQUEST_TIME;
|
||||
// Some redundant checks for extra security ?
|
||||
$users = user_load_multiple(array($uid), array('status' => '1'));
|
||||
if ($timestamp <= $current && $account = reset($users)) {
|
||||
$account = user_load($uid);
|
||||
// Verify that the user exists and is active.
|
||||
if ($timestamp <= $current && $account && $account->status) {
|
||||
// No time out for first time login.
|
||||
if ($account->login && $current - $timestamp > $timeout) {
|
||||
drupal_set_message(t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.'));
|
||||
|
|
Loading…
Reference in New Issue