![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-media-gallery/Model/Directory/Command/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\MediaGallery\Model\Directory\Command; use Magento\Cms\Model\Wysiwyg\Images\Storage; use Magento\Framework\Exception\CouldNotDeleteException; use Magento\MediaGalleryApi\Api\DeleteDirectoriesByPathsInterface; use Magento\MediaGalleryApi\Api\IsPathExcludedInterface; use Psr\Log\LoggerInterface; /** * Delete directory by provided paths in the media storage */ class DeleteByPaths implements DeleteDirectoriesByPathsInterface { /** * @var LoggerInterface */ private $logger; /** * @var Storage */ private $storage; /** * @var IsPathExcludedInterface */ private $isPathExcluded; /** * @param LoggerInterface $logger * @param Storage $storage * @param IsPathExcludedInterface $isPathExcluded */ public function __construct( LoggerInterface $logger, Storage $storage, IsPathExcludedInterface $isPathExcluded ) { $this->logger = $logger; $this->storage = $storage; $this->isPathExcluded = $isPathExcluded; } /** * @inheritdoc */ public function execute(array $paths): void { $failedPaths = []; foreach ($paths as $path) { if ($this->isPathExcluded->execute($path)) { $failedPaths[] = $path; continue; } try { $this->storage->deleteDirectory($this->storage->getCmsWysiwygImages()->getStorageRoot() . $path); } catch (\Exception $exception) { $this->logger->critical($exception); $failedPaths[] = $path; } } if (!empty($failedPaths)) { throw new CouldNotDeleteException( __( 'Could not delete directories: %paths', [ 'paths' => implode(' ,', $failedPaths) ] ) ); } } }