diff --git a/core/includes/file.inc b/core/includes/file.inc index 7bd5e4e..03dde2a 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -795,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 = entity_load_by_properties(array('uri' => $uri)); + $existing_files = entity_load_by_properties('file', array('uri' => $uri)); if (count($existing_files)) { $existing = reset($existing_files); $file->fid = $existing->fid; @@ -1044,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 = entity_load_by_properties(array('uri' => $uri)); + $existing_files = entity_load_by_properties('file', array('uri' => $uri)); if (count($existing_files)) { $existing = reset($existing_files); $delete_source = TRUE; @@ -1557,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 = entity_load_by_properties(array('uri' => $uri)); + $existing_files = entity_load_by_properties('file', array('uri' => $uri)); if (count($existing_files)) { $existing = reset($existing_files); $file->fid = $existing->fid; @@ -1850,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 = entity_load_by_properties(array('uri' => $uri)); + $existing_files = entity_load_by_properties('file', array('uri' => $uri)); if (count($existing_files)) { $existing = reset($existing_files); $file->fid = $existing->fid; diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index ab51268..4db08a2 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -205,7 +205,7 @@ function entity_load($entity_type, $id, $reset = FALSE) { * @see Drupal\entity\DatabaseStorageController */ function entity_load_revision($entity_type, $revision_id) { - entity_get_controller($entity_type)->loadRevision($revision_id); + return entity_get_controller($entity_type)->loadRevision($revision_id); } /** diff --git a/core/modules/entity/lib/Drupal/entity/DatabaseStorageController.php b/core/modules/entity/lib/Drupal/entity/DatabaseStorageController.php index 6af1fc3..74ca58b 100644 --- a/core/modules/entity/lib/Drupal/entity/DatabaseStorageController.php +++ b/core/modules/entity/lib/Drupal/entity/DatabaseStorageController.php @@ -221,7 +221,15 @@ class DatabaseStorageController implements EntityStorageControllerInterface { // @see Drupal\entity\EntityInterface::__construct() $query_result->setFetchMode(PDO::FETCH_CLASS, $this->entityInfo['entity class'], array(array(), $this->entityType)); } - return $query_result->fetch(); + $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); + } + return reset($queried_entities); } /** diff --git a/core/modules/entity/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php b/core/modules/entity/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php index 87784a0..072fdfc 100644 --- a/core/modules/entity/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php +++ b/core/modules/entity/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php @@ -45,9 +45,11 @@ class EntityTestStorageController extends DatabaseStorageController { unset($values['default_langcode']); } + $entity_fields = $this->entityInfo['schema_fields_sql']['base table']; $query->addField('data', $this->idKey); foreach ($values as $field => $value) { - $query->condition('data.' . $field, $value); + $table = isset($entity_fields[$field]) ? 'base' : 'data'; + $query->condition($table . '.' . $field, $value); } } $ids = $query->execute()->fetchCol(); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php index 90e316c..c09be63 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php @@ -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_revision($node_vid_r1); + $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')); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php index cbcc41a..6b1b141 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php @@ -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. diff --git a/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php b/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php index d239a06..f43e99a 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php @@ -88,8 +88,8 @@ class PageEditTest extends NodeTestBase { $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_revision($node->vid); - $second_node_version = node_load_revision($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.'); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index a75f7ca..436b79f 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1014,7 +1014,7 @@ function node_load($nid = NULL, $reset = FALSE) { } /** - * Loads a node entity from the database. + * Loads a node revision from the database. * * @param int $nid * The node revision id. @@ -1022,7 +1022,7 @@ function node_load($nid = NULL, $reset = FALSE) { * @return Drupal\node\Node|false * A fully-populated node entity, or FALSE if the node is not found. */ -function node_load_revision($vid = NULL) { +function node_revision_load($vid = NULL) { return entity_load_revision('node', $vid); } @@ -1173,7 +1173,7 @@ function node_delete_multiple($nids) { * TRUE if the revision deletion was successful. */ function node_revision_delete($revision_id) { - if ($revision = node_load_revision($revision_id)) { + if ($revision = node_revision_load($revision_id)) { // Prevent deleting the current revision. if ($revision->isCurrentRevision()) { return FALSE; @@ -1845,7 +1845,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->isCurrentRevision(), $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)); } } @@ -2022,30 +2022,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; diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php index 4b94a65..0716ff7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php @@ -308,7 +308,7 @@ class BreadcrumbTest extends MenuTestBase { // the breadcrumb based on taxonomy term hierarchy. $parent_tid = 0; foreach ($tags as $name => $null) { - $terms = entity_load_by_properties('term', array('name' => $name)); + $terms = entity_load_by_properties('taxonomy_term', array('name' => $name)); $term = reset($terms); $tags[$name]['term'] = $term; if ($parent_tid) { diff --git a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php index e243799..1824d6a 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php @@ -215,7 +215,7 @@ class UserCancelTest extends WebTestBase { // Confirm user's content has been unpublished. $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_revision($node->vid); + $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. @@ -264,7 +264,7 @@ class UserCancelTest extends WebTestBase { // Confirm that user's content has been attributed to anonymous user. $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($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, 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.")); @@ -327,7 +327,7 @@ class UserCancelTest extends WebTestBase { // Confirm that user's content has been deleted. $this->assertFalse(node_load($node->nid, TRUE), t('Node of the user has been deleted.')); - $this->assertFalse(node_load_revision($revision), t('Node revision 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.'));