Skip to content

Commit 9f4bafc

Browse files
committed
#27499: MediaGallery bulk interfaces introduced
1 parent a8ba203 commit 9f4bafc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+954
-164
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
use Psr\Log\LoggerInterface;
1515

1616
/**
17-
* Class DeleteByDirectoryPath
18-
*
1917
* Remove asset(s) that correspond the provided directory path
18+
* @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead
2019
*/
2120
class DeleteByDirectoryPath implements DeleteByDirectoryPathInterface
2221
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/**
1717
* Class DeleteByPath
18+
* @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead
1819
*/
1920
class DeleteByPath implements DeleteByPathInterface
2021
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
/**
1919
* Get media asset by id
20+
* @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface instead
2021
*/
2122
class GetById implements GetByIdInterface
2223
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
use Psr\Log\LoggerInterface;
1717

1818
/**
19-
* Class GetListByIds
19+
* Class GetByPath
20+
* @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByPathInterface instead
2021
*/
2122
class GetByPath implements GetByPathInterface
2223
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
/**
1818
* Class Save
19+
* @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetInterface instead
1920
*/
2021
class Save implements SaveInterface
2122
{
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaGallery\Model;
9+
10+
use Magento\Framework\Model\AbstractExtensibleModel;
11+
use Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterface;
12+
use Magento\MediaGalleryApi\Api\Data\AssetKeywordsExtensionInterface;
13+
14+
/**
15+
* Asset's Keywords
16+
*/
17+
class AssetKeywords extends AbstractExtensibleModel implements AssetKeywordsInterface
18+
{
19+
private const ASSET_ID = 'asset_id';
20+
private const KEYWORDS = 'keywords';
21+
22+
/**
23+
* @inheritdoc
24+
*/
25+
public function getAssetId(): int
26+
{
27+
return (int) $this->getData(self::ASSET_ID);
28+
}
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
public function getKeywords(): array
34+
{
35+
return $this->getData(self::KEYWORDS);
36+
}
37+
38+
/**
39+
* @inheritdoc
40+
*/
41+
public function getExtensionAttributes(): AssetKeywordsExtensionInterface
42+
{
43+
return $this->_getExtensionAttributes();
44+
}
45+
46+
/**
47+
* @inheritdoc
48+
*/
49+
public function setExtensionAttributes(AssetKeywordsExtensionInterface $extensionAttributes): void
50+
{
51+
$this->_setExtensionAttributes($extensionAttributes);
52+
}
53+
}

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
use Magento\Cms\Model\Wysiwyg\Images\Storage;
1111
use Magento\Framework\Exception\CouldNotSaveException;
12-
use Magento\MediaGalleryApi\Model\Directory\Command\CreateByPathInterface;
12+
use Magento\MediaGalleryApi\Api\CreateDirectoriesByPathsInterface;
1313
use Psr\Log\LoggerInterface;
1414

1515
/**
1616
* Create folder by provided path
1717
*/
18-
class CreateByPath implements CreateByPathInterface
18+
class CreateByPath implements CreateDirectoriesByPathsInterface
1919
{
2020
/**
2121
* @var LoggerInterface
@@ -40,19 +40,31 @@ public function __construct(
4040
}
4141

4242
/**
43-
* Create new directory by the provided path in the media storage
44-
*
45-
* @param string $path
46-
* @param string $name
47-
* @throws CouldNotSaveException
43+
* @inheritdoc
4844
*/
49-
public function execute(string $path, string $name): void
45+
public function execute(array $paths): void
5046
{
51-
try {
52-
$this->storage->createDirectory($name, $this->storage->getCmsWysiwygImages()->getStorageRoot() . $path);
53-
} catch (\Exception $exception) {
54-
$this->logger->critical($exception);
55-
throw new CouldNotSaveException(__('Failed to create the folder'), $exception);
47+
$failedPaths = [];
48+
foreach ($paths as $path) {
49+
try {
50+
$name = end(explode('/', $path));
51+
$this->storage->createDirectory(
52+
$name,
53+
$this->storage->getCmsWysiwygImages()->getStorageRoot() . $path
54+
);
55+
} catch (\Exception $exception) {
56+
$this->logger->critical($exception);
57+
$failedPaths[] = $path;
58+
}
59+
}
60+
61+
if (!empty($failedPaths)) {
62+
throw new CouldNotSaveException(
63+
__(
64+
'Could not save directories: %paths',
65+
implode(' ,', $failedPaths)
66+
)
67+
);
5668
}
5769
}
5870
}

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
use Magento\Cms\Model\Wysiwyg\Images\Storage;
1111
use Magento\Framework\Exception\CouldNotDeleteException;
12-
use Magento\MediaGalleryApi\Model\Directory\Command\DeleteByPathInterface;
12+
use Magento\MediaGalleryApi\Api\DeleteDirectoriesByPathsInterface;
1313
use Psr\Log\LoggerInterface;
1414

1515
/**
1616
* Delete directory from media storage by path
1717
*/
18-
class DeleteByPath implements DeleteByPathInterface
18+
class DeleteByPath implements DeleteDirectoriesByPathsInterface
1919
{
2020
/**
2121
* @var LoggerInterface
@@ -40,18 +40,27 @@ public function __construct(
4040
}
4141

4242
/**
43-
* Removes directory and corresponding thumbnails directory from media storage if not in blacklist
44-
*
45-
* @param string $path
46-
* @throws CouldNotDeleteException
43+
* @inheritdoc
4744
*/
48-
public function execute(string $path): void
45+
public function execute(array $paths): void
4946
{
50-
try {
51-
$this->storage->deleteDirectory($this->storage->getCmsWysiwygImages()->getStorageRoot() . $path);
52-
} catch (\Exception $exception) {
53-
$this->logger->critical($exception);
54-
throw new CouldNotDeleteException(__('Failed to delete the folder'), $exception);
47+
$failedPaths = [];
48+
foreach ($paths as $path) {
49+
try {
50+
$this->storage->deleteDirectory($this->storage->getCmsWysiwygImages()->getStorageRoot() . $path);
51+
} catch (\Exception $exception) {
52+
$this->logger->critical($exception);
53+
$failedPaths[] = $path;
54+
}
55+
}
56+
57+
if (!empty($failedPaths)) {
58+
throw new CouldNotDeleteException(
59+
__(
60+
'Could not delete directories: %paths',
61+
implode(' ,', $failedPaths)
62+
)
63+
);
5564
}
5665
}
5766
}

app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
namespace Magento\MediaGallery\Model\Directory;
99

10-
use Magento\MediaGalleryApi\Model\Directory\IsBlacklistedInterface;
10+
use Magento\MediaGalleryApi\Api\IsPathBlacklistedInterface;
1111

1212
/**
1313
* Check if the path is blacklisted for media gallery. Directory path may be blacklisted if it's reserved by the system
1414
*/
15-
class IsBlacklisted implements IsBlacklistedInterface
15+
class IsBlacklisted implements IsPathBlacklistedInterface
1616
{
1717
/**
1818
* @var Config

app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)