Commit f66ac343 authored by catch's avatar catch
Browse files

Issue #1292374 by jbrown, chris.leversuch, slashrsm, karschsp, Kevin Morse,...

Issue #1292374 by jbrown, chris.leversuch, slashrsm, karschsp, Kevin Morse, Berdir: Fixed Enable static caching for File entities.
parent 20fe13eb
...@@ -104,6 +104,8 @@ function file_entity_view_mode_info() { ...@@ -104,6 +104,8 @@ function file_entity_view_mode_info() {
* *
* @param array $fids * @param array $fids
* (optional) An array of entity IDs. If omitted, all entities are loaded. * (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 * @return array
* An array of file entities, indexed by fid. * An array of file entities, indexed by fid.
...@@ -113,8 +115,8 @@ function file_entity_view_mode_info() { ...@@ -113,8 +115,8 @@ function file_entity_view_mode_info() {
* @see entity_load() * @see entity_load()
* @see Drupal\Core\Entity\Query\EntityQueryInterface * @see Drupal\Core\Entity\Query\EntityQueryInterface
*/ */
function file_load_multiple(array $fids = NULL) { function file_load_multiple(array $fids = NULL, $reset = FALSE) {
return entity_load_multiple('file', $fids); return entity_load_multiple('file', $fids, $reset);
} }
/** /**
...@@ -122,6 +124,8 @@ function file_load_multiple(array $fids = NULL) { ...@@ -122,6 +124,8 @@ function file_load_multiple(array $fids = NULL) {
* *
* @param $fid * @param $fid
* A file ID. * A file ID.
* @param $reset
* Whether to reset the internal file_load_multiple() cache.
* *
* @return Drupal\file\File * @return Drupal\file\File
* A file entity or FALSE if the file was not found. * A file entity or FALSE if the file was not found.
...@@ -129,8 +133,8 @@ function file_load_multiple(array $fids = NULL) { ...@@ -129,8 +133,8 @@ function file_load_multiple(array $fids = NULL) {
* @see hook_file_load() * @see hook_file_load()
* @see file_load_multiple() * @see file_load_multiple()
*/ */
function file_load($fid) { function file_load($fid, $reset = FALSE) {
$files = file_load_multiple(array($fid)); $files = file_load_multiple(array($fid), $reset);
return reset($files); return reset($files);
} }
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
* module = "file", * module = "file",
* controller_class = "Drupal\file\FileStorageController", * controller_class = "Drupal\file\FileStorageController",
* base_table = "file_managed", * base_table = "file_managed",
* static_cache = FALSE,
* entity_keys = { * entity_keys = {
* "id" = "fid", * "id" = "fid",
* "label" = "filename", * "label" = "filename",
......
...@@ -71,7 +71,7 @@ function testInUse() { ...@@ -71,7 +71,7 @@ function testInUse() {
drupal_cron_run(); drupal_cron_run();
// system_cron() loads // 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_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.')); $this->assertFalse(file_load($file->fid), t('File was removed from the database.'));
} }
......
...@@ -82,7 +82,7 @@ function testMultiple() { ...@@ -82,7 +82,7 @@ function testMultiple() {
// Load by fid. // Load by fid.
file_test_reset(); file_test_reset();
$by_fid_files = file_load_multiple(array($file->fid)); $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.')); $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); $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.')); $this->assertTrue($by_fid_file->file_test['loaded'], t('file_test_file_load() was able to modify the file during load.'));
......
...@@ -78,7 +78,7 @@ function testCreateDeletePicture() { ...@@ -78,7 +78,7 @@ function testCreateDeletePicture() {
drupal_cron_run(); drupal_cron_run();
// Verify that the image has been deleted. // 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. // Clear out PHP's file stat cache so we see the current value.
clearstatcache(TRUE, $file->uri); clearstatcache(TRUE, $file->uri);
$this->assertFalse(is_file($file->uri), 'File was removed from the file system.'); $this->assertFalse(is_file($file->uri), 'File was removed from the file system.');
...@@ -122,6 +122,6 @@ function saveUserPicture($image) { ...@@ -122,6 +122,6 @@ function saveUserPicture($image) {
// Load actual user data from database. // Load actual user data from database.
$account = user_load($this->web_user->uid, TRUE); $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);
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment