Mercurial > hg > cmmr2012-drupal-site
diff core/modules/image/src/Entity/ImageStyle.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
line wrap: on
line diff
--- a/core/modules/image/src/Entity/ImageStyle.php Thu Feb 28 13:11:55 2019 +0000 +++ b/core/modules/image/src/Entity/ImageStyle.php Thu May 09 15:34:47 2019 +0100 @@ -7,6 +7,8 @@ use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; +use Drupal\Core\File\Exception\FileException; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Routing\RequestHelper; use Drupal\Core\Site\Settings; use Drupal\Core\Url; @@ -251,10 +253,17 @@ */ public function flush($path = NULL) { // A specific image path has been provided. Flush only that derivative. + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); if (isset($path)) { $derivative_uri = $this->buildUri($path); if (file_exists($derivative_uri)) { - file_unmanaged_delete($derivative_uri); + try { + $file_system->delete($derivative_uri); + } + catch (FileException $e) { + // Ignore failed deletes. + } } return $this; } @@ -263,7 +272,12 @@ $wrappers = $this->getStreamWrapperManager()->getWrappers(StreamWrapperInterface::WRITE_VISIBLE); foreach ($wrappers as $wrapper => $wrapper_data) { if (file_exists($directory = $wrapper . '://styles/' . $this->id())) { - file_unmanaged_delete_recursive($directory); + try { + $file_system->deleteRecursive($directory); + } + catch (FileException $e) { + // Ignore failed deletes. + } } } @@ -290,10 +304,10 @@ } // Get the folder for the final location of this style. - $directory = drupal_dirname($derivative_uri); + $directory = \Drupal::service('file_system')->dirname($derivative_uri); // Build the destination folder tree if it doesn't already exist. - if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { + if (!\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) { \Drupal::logger('image')->error('Failed to create style directory: %directory', ['%directory' => $directory]); return FALSE; }