From f66ac34331452e07b76347ddada6bad335f715ad Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Tue, 12 Feb 2013 12:14:30 +0000
Subject: [PATCH] Issue #1292374 by jbrown, chris.leversuch, slashrsm,
 karschsp, Kevin Morse, Berdir: Fixed Enable static caching for File entities.

---
 core/modules/file/file.module                        | 12 ++++++++----
 .../file/lib/Drupal/file/Plugin/Core/Entity/File.php |  1 -
 .../file/lib/Drupal/file/Tests/DeleteTest.php        |  2 +-
 core/modules/file/lib/Drupal/file/Tests/LoadTest.php |  2 +-
 .../user/lib/Drupal/user/Tests/UserPictureTest.php   |  4 ++--
 5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 913f75a3bfcb..75c4f84df785 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -104,6 +104,8 @@ function file_entity_view_mode_info() {
  *
  * @param array $fids
  *   (optional) An array of entity IDs. If omitted, all entities are loaded.
+ * @param $reset
+ *   Whether to reset the internal file_load_multiple() cache.
  *
  * @return array
  *   An array of file entities, indexed by fid.
@@ -113,8 +115,8 @@ function file_entity_view_mode_info() {
  * @see entity_load()
  * @see Drupal\Core\Entity\Query\EntityQueryInterface
  */
-function file_load_multiple(array $fids = NULL) {
-  return entity_load_multiple('file', $fids);
+function file_load_multiple(array $fids = NULL, $reset = FALSE) {
+  return entity_load_multiple('file', $fids, $reset);
 }
 
 /**
@@ -122,6 +124,8 @@ function file_load_multiple(array $fids = NULL) {
  *
  * @param $fid
  *   A file ID.
+ * @param $reset
+ *   Whether to reset the internal file_load_multiple() cache.
  *
  * @return Drupal\file\File
  *   A file entity or FALSE if the file was not found.
@@ -129,8 +133,8 @@ function file_load_multiple(array $fids = NULL) {
  * @see hook_file_load()
  * @see file_load_multiple()
  */
-function file_load($fid) {
-  $files = file_load_multiple(array($fid));
+function file_load($fid, $reset = FALSE) {
+  $files = file_load_multiple(array($fid), $reset);
   return reset($files);
 }
 
diff --git a/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php b/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php
index d7f2a6ba418a..e811c58778cf 100644
--- a/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php
+++ b/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php
@@ -21,7 +21,6 @@
  *   module = "file",
  *   controller_class = "Drupal\file\FileStorageController",
  *   base_table = "file_managed",
- *   static_cache = FALSE,
  *   entity_keys = {
  *     "id" = "fid",
  *     "label" = "filename",
diff --git a/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php b/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php
index 6adafdb48823..ca2f712e79a5 100644
--- a/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php
@@ -71,7 +71,7 @@ function testInUse() {
     drupal_cron_run();
 
     // system_cron() loads
-    $this->assertFileHooksCalled(array('load', 'delete'));
+    $this->assertFileHooksCalled(array('delete'));
     $this->assertFalse(file_exists($file->uri), t('File has been deleted after its last usage was removed.'));
     $this->assertFalse(file_load($file->fid), t('File was removed from the database.'));
   }
diff --git a/core/modules/file/lib/Drupal/file/Tests/LoadTest.php b/core/modules/file/lib/Drupal/file/Tests/LoadTest.php
index 833c26074b25..aaaec27ba339 100644
--- a/core/modules/file/lib/Drupal/file/Tests/LoadTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/LoadTest.php
@@ -82,7 +82,7 @@ function testMultiple() {
     // Load by fid.
     file_test_reset();
     $by_fid_files = file_load_multiple(array($file->fid));
-    $this->assertFileHookCalled('load');
+    $this->assertFileHooksCalled(array());
     $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);
     $this->assertTrue($by_fid_file->file_test['loaded'], t('file_test_file_load() was able to modify the file during load.'));
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
index 8447031753b2..77646992f0b0 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
@@ -78,7 +78,7 @@ function testCreateDeletePicture() {
     drupal_cron_run();
 
     // Verify that the image has been deleted.
-    $this->assertFalse(file_load($file->fid), 'File was removed from the database.');
+    $this->assertFalse(file_load($file->fid, TRUE), 'File was removed from the database.');
     // Clear out PHP's file stat cache so we see the current value.
     clearstatcache(TRUE, $file->uri);
     $this->assertFalse(is_file($file->uri), 'File was removed from the file system.');
@@ -122,6 +122,6 @@ function saveUserPicture($image) {
 
     // Load actual user data from database.
     $account = user_load($this->web_user->uid, TRUE);
-    return file_load($account->user_picture[LANGUAGE_NOT_SPECIFIED][0]['fid']);
+    return file_load($account->user_picture[LANGUAGE_NOT_SPECIFIED][0]['fid'], TRUE);
   }
 }
-- 
GitLab