Mercurial > hg > cmmr2012-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
5 use Drupal\Core\Cache\Cache; | 5 use Drupal\Core\Cache\Cache; |
6 use Drupal\Core\Config\Entity\ConfigEntityBase; | 6 use Drupal\Core\Config\Entity\ConfigEntityBase; |
7 use Drupal\Core\Entity\Entity\EntityFormDisplay; | 7 use Drupal\Core\Entity\Entity\EntityFormDisplay; |
8 use Drupal\Core\Entity\EntityStorageInterface; | 8 use Drupal\Core\Entity\EntityStorageInterface; |
9 use Drupal\Core\Entity\EntityWithPluginCollectionInterface; | 9 use Drupal\Core\Entity\EntityWithPluginCollectionInterface; |
10 use Drupal\Core\File\Exception\FileException; | |
11 use Drupal\Core\File\FileSystemInterface; | |
10 use Drupal\Core\Routing\RequestHelper; | 12 use Drupal\Core\Routing\RequestHelper; |
11 use Drupal\Core\Site\Settings; | 13 use Drupal\Core\Site\Settings; |
12 use Drupal\Core\Url; | 14 use Drupal\Core\Url; |
13 use Drupal\image\ImageEffectPluginCollection; | 15 use Drupal\image\ImageEffectPluginCollection; |
14 use Drupal\image\ImageEffectInterface; | 16 use Drupal\image\ImageEffectInterface; |
249 /** | 251 /** |
250 * {@inheritdoc} | 252 * {@inheritdoc} |
251 */ | 253 */ |
252 public function flush($path = NULL) { | 254 public function flush($path = NULL) { |
253 // A specific image path has been provided. Flush only that derivative. | 255 // A specific image path has been provided. Flush only that derivative. |
256 /** @var \Drupal\Core\File\FileSystemInterface $file_system */ | |
257 $file_system = \Drupal::service('file_system'); | |
254 if (isset($path)) { | 258 if (isset($path)) { |
255 $derivative_uri = $this->buildUri($path); | 259 $derivative_uri = $this->buildUri($path); |
256 if (file_exists($derivative_uri)) { | 260 if (file_exists($derivative_uri)) { |
257 file_unmanaged_delete($derivative_uri); | 261 try { |
262 $file_system->delete($derivative_uri); | |
263 } | |
264 catch (FileException $e) { | |
265 // Ignore failed deletes. | |
266 } | |
258 } | 267 } |
259 return $this; | 268 return $this; |
260 } | 269 } |
261 | 270 |
262 // Delete the style directory in each registered wrapper. | 271 // Delete the style directory in each registered wrapper. |
263 $wrappers = $this->getStreamWrapperManager()->getWrappers(StreamWrapperInterface::WRITE_VISIBLE); | 272 $wrappers = $this->getStreamWrapperManager()->getWrappers(StreamWrapperInterface::WRITE_VISIBLE); |
264 foreach ($wrappers as $wrapper => $wrapper_data) { | 273 foreach ($wrappers as $wrapper => $wrapper_data) { |
265 if (file_exists($directory = $wrapper . '://styles/' . $this->id())) { | 274 if (file_exists($directory = $wrapper . '://styles/' . $this->id())) { |
266 file_unmanaged_delete_recursive($directory); | 275 try { |
276 $file_system->deleteRecursive($directory); | |
277 } | |
278 catch (FileException $e) { | |
279 // Ignore failed deletes. | |
280 } | |
267 } | 281 } |
268 } | 282 } |
269 | 283 |
270 // Let other modules update as necessary on flush. | 284 // Let other modules update as necessary on flush. |
271 $module_handler = \Drupal::moduleHandler(); | 285 $module_handler = \Drupal::moduleHandler(); |
288 if (!$image->isValid()) { | 302 if (!$image->isValid()) { |
289 return FALSE; | 303 return FALSE; |
290 } | 304 } |
291 | 305 |
292 // Get the folder for the final location of this style. | 306 // Get the folder for the final location of this style. |
293 $directory = drupal_dirname($derivative_uri); | 307 $directory = \Drupal::service('file_system')->dirname($derivative_uri); |
294 | 308 |
295 // Build the destination folder tree if it doesn't already exist. | 309 // Build the destination folder tree if it doesn't already exist. |
296 if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { | 310 if (!\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) { |
297 \Drupal::logger('image')->error('Failed to create style directory: %directory', ['%directory' => $directory]); | 311 \Drupal::logger('image')->error('Failed to create style directory: %directory', ['%directory' => $directory]); |
298 return FALSE; | 312 return FALSE; |
299 } | 313 } |
300 | 314 |
301 foreach ($this->getEffects() as $effect) { | 315 foreach ($this->getEffects() as $effect) { |