Skip to content

Commit c006590

Browse files
committed
Added blacklist to directory operations
1 parent 21955c5 commit c006590

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

app/code/Magento/MediaGallery/Model/Asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/**
1515
* Media Gallery Asset
16-
* @SuppressWarnings(PHPMD.ExcessiveParameterList
16+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
1717
*/
1818
class Asset implements AssetInterface
1919
{

app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Cms\Model\Wysiwyg\Images\Storage;
1111
use Magento\Framework\Exception\CouldNotSaveException;
1212
use Magento\MediaGalleryApi\Api\CreateDirectoriesByPathsInterface;
13+
use Magento\MediaGalleryApi\Api\IsPathBlacklistedInterface;
1314
use Psr\Log\LoggerInterface;
1415

1516
/**
@@ -27,16 +28,24 @@ class CreateByPaths implements CreateDirectoriesByPathsInterface
2728
*/
2829
private $storage;
2930

31+
/**
32+
* @var IsPathBlacklistedInterface
33+
*/
34+
private $isPathBlacklisted;
35+
3036
/**
3137
* @param LoggerInterface $logger
3238
* @param Storage $storage
39+
* @param IsPathBlacklistedInterface $isPathBlacklisted
3340
*/
3441
public function __construct(
3542
LoggerInterface $logger,
36-
Storage $storage
43+
Storage $storage,
44+
IsPathBlacklistedInterface $isPathBlacklisted
3745
) {
3846
$this->logger = $logger;
3947
$this->storage = $storage;
48+
$this->isPathBlacklisted = $isPathBlacklisted;
4049
}
4150

4251
/**
@@ -46,6 +55,10 @@ public function execute(array $paths): void
4655
{
4756
$failedPaths = [];
4857
foreach ($paths as $path) {
58+
if ($this->isPathBlacklisted->execute($path)) {
59+
$failedPaths[] = $path;
60+
continue;
61+
}
4962
try {
5063
//phpcs:ignore Magento2.Functions.DiscouragedFunction
5164
$name = basename($path);

app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Cms\Model\Wysiwyg\Images\Storage;
1111
use Magento\Framework\Exception\CouldNotDeleteException;
1212
use Magento\MediaGalleryApi\Api\DeleteDirectoriesByPathsInterface;
13+
use Magento\MediaGalleryApi\Api\IsPathBlacklistedInterface;
1314
use Psr\Log\LoggerInterface;
1415

1516
/**
@@ -27,16 +28,24 @@ class DeleteByPaths implements DeleteDirectoriesByPathsInterface
2728
*/
2829
private $storage;
2930

31+
/**
32+
* @var IsPathBlacklistedInterface
33+
*/
34+
private $isPathBlacklisted;
35+
3036
/**
3137
* @param LoggerInterface $logger
3238
* @param Storage $storage
39+
* @param IsPathBlacklistedInterface $isPathBlacklisted
3340
*/
3441
public function __construct(
3542
LoggerInterface $logger,
36-
Storage $storage
43+
Storage $storage,
44+
IsPathBlacklistedInterface $isPathBlacklisted
3745
) {
3846
$this->logger = $logger;
3947
$this->storage = $storage;
48+
$this->isPathBlacklisted = $isPathBlacklisted;
4049
}
4150

4251
/**
@@ -46,6 +55,10 @@ public function execute(array $paths): void
4655
{
4756
$failedPaths = [];
4857
foreach ($paths as $path) {
58+
if ($this->isPathBlacklisted->execute($path)) {
59+
$failedPaths[] = $path;
60+
continue;
61+
}
4962
try {
5063
$this->storage->deleteDirectory($this->storage->getCmsWysiwygImages()->getStorageRoot() . $path);
5164
} catch (\Exception $exception) {

0 commit comments

Comments
 (0)