2c2 < index b280fe8..49a3f68 100644 --- > index 5674611d5c..1f07417c18 100644 5c5 < @@ -59,9 +59,9 @@ function config_help($route_name, RouteMatchInterface $route_match) { --- > @@ -61,9 +61,9 @@ function config_help($route_name, RouteMatchInterface $route_match) { 14,15c14,15 < $scheme = file_uri_scheme($uri); < $target = file_uri_target($uri); --- > $scheme = StreamWrapperManager::getScheme($uri); > $target = StreamWrapperManager::getTarget($uri); 18c18 < index 1fda717..1e2c068 100644 --- > index bc60c04565..3585eb9250 100644 21c21,22 < @@ -78,5 +78,26 @@ function hook_file_move(Drupal\file\FileInterface $file, Drupal\file\FileInterfa --- > @@ -124,6 +124,27 @@ function hook_file_move(\Drupal\file\FileInterface $file, \Drupal\file\FileInter > } 24c25 < /** --- > +/** 36,37c37,38 < + $scheme = file_uri_scheme($uri); < + $target = file_uri_target($uri); --- > + $scheme = \Drupal\Core\StreamWrapper\StreamWrapperManager::getScheme($uri); > + $target = \Drupal\Core\StreamWrapper\StreamWrapperManager::getTarget($uri); 39c40 < + return array( --- > + return [ 41c42 < + ); --- > + ]; 45c46 < +/** --- > /** 49c50 < index a6fc3f6..5b5f970 100644 --- > index b43532e611..19bcba2524 100644 52c53,54 < @@ -540,26 +540,6 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM --- > @@ -536,24 +536,6 @@ function file_save_data($data, $destination = NULL, $replace = FileSystemInterfa > } 55c57 < /** --- > -/** 66,67d67 < - $type = Unicode::mimeHeaderEncode($file->getMimeType()); < - 69c69 < - 'Content-Type' => $type, --- > - 'Content-Type' => $file->getMimeType(), 75c75 < -/** --- > /** 78,79c78,79 < function file_theme() { < @@ -585,62 +565,6 @@ function file_theme() { --- > @@ -585,53 +567,6 @@ function file_theme() { > ]; 82c82 < /** --- > -/** 87,99c87,90 < - /** @var \Drupal\file\FileInterface[] $files */ < - $files = entity_load_multiple_by_properties('file', ['uri' => $uri]); < - if (count($files)) { < - foreach ($files as $item) { < - // Since some database servers sometimes use a case-insensitive comparison < - // by default, double check that the filename is an exact match. < - if ($item->getFileUri() === $uri) { < - $file = $item; < - break; < - } < - } < - } < - if (!isset($file)) { --- > - /** @var \Drupal\file\FileRepositoryInterface $file_repository */ > - $file_repository = \Drupal::service('file.repository'); > - $file = $file_repository->loadByUri($uri); > - if (!$file) { 138c129 < -/** --- > /** 141d131 < function file_cron() { 143c133 < index a68b9ba..783b403 100644 --- > index 57276f495e..07dae9d154 100644 154,157c144,158 < @@ -112,6 +113,18 @@ public function getCreatedTime() { < /** < * {@inheritdoc} < */ --- > @@ -10,6 +11,7 @@ > use Drupal\Core\File\Exception\FileException; > use Drupal\file\FileInterface; > use Drupal\user\EntityOwnerTrait; > +use Symfony\Component\Mime\Header\UnstructuredHeader; > use Symfony\Component\Mime\MimeTypeGuesserInterface; > > /** > @@ -120,6 +122,18 @@ public function getCreatedTime() { > return $this->get('created')->value; > } > > + /** > + * {@inheritdoc} > + */ 159c160 < + $type = Unicode::mimeHeaderEncode($this->getMimeType()); --- > + $type = new UnstructuredHeader('Content-Type', $this->getMimeType()); 161c162 < + 'Content-Type' => $type, --- > + 'Content-Type' => $type->getValue(), 167,172c168,170 < + /** < + * {@inheritdoc} < + */ < public function getOwner() { < return $this->get('uid')->entity; < } --- > /** > * {@inheritdoc} > */ 174c172 < index ee7120b..ff90b48 100644 --- > index c90575aa4f..b24a084079 100644 177c175 < @@ -116,4 +116,14 @@ public function setTemporary(); --- > @@ -138,4 +138,14 @@ public function setTemporary(); 181d178 < + 190a188 > + 192,209d189 < diff --git a/core/modules/file/src/Tests/DownloadTest.php b/core/modules/file/src/Tests/DownloadTest.php < index c5189fa..2b8ab39 100644 < --- a/core/modules/file/src/Tests/DownloadTest.php < +++ b/core/modules/file/src/Tests/DownloadTest.php < @@ -72,10 +72,10 @@ protected function doPrivateFileTransferTest() { < // Test that the file transferred correctly. < $this->assertEqual($contents, $this->content, 'Contents of the file are correct.'); < < - // Deny access to all downloads via a -1 header. < - file_test_set_return('download', -1); < + // Deny access to all downloads without header. < + file_test_set_return('download', NULL); < $this->drupalHead($url); < - $this->assertResponse(403, 'Correctly denied access to a file when file_test sets the header to -1.'); < + $this->assertResponse(403, 'Correctly denied access to a file when no headers are sent.'); < < // Try non-existent file. < $url = file_create_url('private://' . $this->randomMachineName()); 211c191 < index 0baa0cb..5dc0099 100644 --- > index 6551ae3274..24f132d364 100644 224c204 < $files = entity_load_multiple_by_properties('file', ['uri' => $uri]); --- > $files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]); 225a206,223 > diff --git a/core/modules/file/tests/src/Functional/DownloadTest.php b/core/modules/file/tests/src/Functional/DownloadTest.php > index 0a2fdb9ba4..22982b287c 100644 > --- a/core/modules/file/tests/src/Functional/DownloadTest.php > +++ b/core/modules/file/tests/src/Functional/DownloadTest.php > @@ -95,10 +95,10 @@ protected function doPrivateFileTransferTest() { > $this->assertSame($contents, $this->getSession()->getPage()->getContent(), 'Contents of the file are correct.'); > $http_client = $this->getHttpClient(); > > - // Deny access to all downloads via a -1 header. > - file_test_set_return('download', -1); > + // Deny access to all downloads without header. > + file_test_set_return('download', NULL); > $response = $http_client->head($url, ['http_errors' => FALSE]); > - $this->assertSame(403, $response->getStatusCode(), 'Correctly denied access to a file when file_test sets the header to -1.'); > + $this->assertSame(403, $response->getStatusCode(), 'Correctly denied access to a file when no headers are send.'); > > // Try non-existent file. > file_test_reset(); 227c225 < index 6107ecd..812c4d6 100644 --- > index 5d4aa2754e..2c80c1fffd 100644 230c228,229 < @@ -159,45 +159,6 @@ function image_theme() { --- > @@ -131,46 +131,6 @@ function image_theme() { > ]; 233c232 < /** --- > -/** 239c238,239 < - $path = file_uri_target($uri); --- > - > - $path = StreamWrapperManager::getTarget($uri); 249c249 < - $original_uri = file_uri_scheme($uri) . '://' . implode('/', $args); --- > - $original_uri = StreamWrapperManager::getScheme($uri) . '://' . implode('/', $args); 272c272 < -/** --- > /** 275d274 < function image_file_move(File $file, File $source) { 277c276 < index afc1edf..2e9750b 100644 --- > index 6ded44fab6..0ee9c11560 100644 280,295c279 < @@ -6,12 +6,14 @@ < use Drupal\Core\Image\ImageFactory; < use Drupal\Core\Lock\LockBackendInterface; < use Drupal\image\ImageStyleInterface; < +use Drupal\file\Entity\File; < use Drupal\system\FileDownloadController; < use Symfony\Component\DependencyInjection\ContainerInterface; < use Symfony\Component\HttpFoundation\BinaryFileResponse; < use Symfony\Component\HttpFoundation\Request; < use Symfony\Component\HttpFoundation\Response; < use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; < +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; < use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; < < /** < @@ -113,8 +115,10 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st --- > @@ -143,8 +143,10 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st 309c293 < index 20c515e..e410868 100644 --- > index 3fd845cc58..4907d47606 100644 312c296 < @@ -7,8 +7,11 @@ --- > @@ -7,7 +7,10 @@ 317d300 < - $default_uri = \Drupal::state()->get('image.test_file_download') ?: FALSE; 322c305 < + $default_uri = \Drupal::state()->get('image.test_file_download') ? : FALSE; --- > $default_uri = \Drupal::state()->get('image.test_file_download', FALSE); 325d307 < } 327c309 < index 08b1632..606c7bc 100644 --- > index cb9071bc17..d45553c1af 100644 330c312 < @@ -44,16 +44,7 @@ public function download(Request $request, $scheme = 'private') { --- > @@ -72,16 +72,7 @@ public function download(Request $request, $scheme = 'private') { 333c315 < if (file_stream_wrapper_valid_scheme($scheme) && file_exists($uri)) { --- > if ($this->streamWrapperManager->isValidScheme($scheme) && is_file($uri)) { 348c330 < @@ -67,4 +58,39 @@ public function download(Request $request, $scheme = 'private') { --- > @@ -95,4 +86,40 @@ public function download(Request $request, $scheme = 'private') { 361c343 < + * @return array|NULL --- > + * @return array|null 370,372c352,354 < + $files = $this->entityManager() < + ->getStorage('file') < + ->loadByProperties(array('uri' => $file_uri)); --- > + $files = \Drupal::entityTypeManager() > + ->getStorage('file') > + ->loadByProperties(['uri' => $file_uri]); 379c361,362 < + $headers = $this->moduleHandler()->invokeAll('unmanaged_file_download_headers', array($file_uri)); --- > + $headers = $this->moduleHandler() > + ->invokeAll('unmanaged_file_download_headers', [$file_uri]);