From c12201ea7e461ec73f765b6db18d26988a83a9d8 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Mon, 30 Mar 2020 12:31:22 +0100 Subject: [PATCH 01/35] Updated MediaGallery modules and marked as API --- .../Model/Asset/Command/GetById.php | 2 +- .../Model/Asset/Command/GetByPath.php | 6 +- .../Model/Directory/Command/CreateByPath.php | 59 ++++++++++ .../Model/Directory/Command/DeleteByPath.php | 58 ++++++++++ .../MediaGallery/Model/Directory/Excluded.php | 48 ++++++++ .../Model/File/Command/DeleteByAssetId.php | 74 +++++++++++++ .../Keyword/Command/GetAssetKeywords.php | 2 +- .../Unit/Model/Directory/ExcludedTest.php | 64 +++++++++++ .../File/Command/DeleteByAssetIdTest.php | 103 ++++++++++++++++++ app/code/Magento/MediaGallery/etc/di.xml | 14 +++ .../Api/Data/AssetInterface.php | 1 + .../Api/Data/KeywordInterface.php | 1 + .../DeleteByDirectoryPathInterface.php | 2 +- .../Asset/Command/DeleteByPathInterface.php | 2 +- .../Model/Asset/Command/GetByIdInterface.php | 2 +- .../Asset/Command/GetByPathInterface.php | 2 +- .../Model/Asset/Command/SaveInterface.php | 2 +- .../Model/DataExtractorInterface.php | 1 + .../Command/CreateByPathInterface.php | 24 ++++ .../Command/DeleteByPathInterface.php | 23 ++++ .../Model/Directory/ExcludedInterface.php | 23 ++++ .../File/Command/DeleteByAssetIdInterface.php | 24 ++++ .../Command/GetAssetKeywordsInterface.php | 2 +- .../Command/SaveAssetKeywordsInterface.php | 1 + 24 files changed, 528 insertions(+), 12 deletions(-) create mode 100644 app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php create mode 100644 app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php create mode 100644 app/code/Magento/MediaGallery/Model/Directory/Excluded.php create mode 100644 app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php create mode 100644 app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php create mode 100644 app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php create mode 100644 app/code/Magento/MediaGalleryApi/Model/Directory/Command/CreateByPathInterface.php create mode 100644 app/code/Magento/MediaGalleryApi/Model/Directory/Command/DeleteByPathInterface.php create mode 100644 app/code/Magento/MediaGalleryApi/Model/Directory/ExcludedInterface.php create mode 100644 app/code/Magento/MediaGalleryApi/Model/File/Command/DeleteByAssetIdInterface.php diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php index 6be11610ac197..b6153c45dbf8c 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php @@ -28,7 +28,7 @@ class GetById implements GetByIdInterface private $resourceConnection; /** - * @var AssetInterface + * @var AssetInterfaceFactory */ private $assetFactory; diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php index db8482d3399ba..fe5fcca6cb0de 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php @@ -30,7 +30,7 @@ class GetByPath implements GetByPathInterface private $resourceConnection; /** - * @var AssetInterface + * @var AssetInterfaceFactory */ private $mediaAssetFactory; @@ -78,9 +78,7 @@ public function execute(string $mediaFilePath): AssetInterface throw new NoSuchEntityException($message); } - $mediaAssets = $this->mediaAssetFactory->create(['data' => $data]); - - return $mediaAssets; + return $this->mediaAssetFactory->create(['data' => $data]); } catch (\Exception $exception) { $this->logger->critical($exception); $message = __('An error occurred during get media asset list: %1', $exception->getMessage()); diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php new file mode 100644 index 0000000000000..6d0ea45aa02cd --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php @@ -0,0 +1,59 @@ +logger = $logger; + $this->storage = $storage; + } + + /** + * Create new directory by provided path + * + * @param string $path + * @param string $name + * @throws CouldNotSaveException + */ + public function execute(string $path, string $name): void + { + try { + $this->storage->createDirectory($name, $this->storage->getCmsWysiwygImages()->getStorageRoot() . $path); + } catch (\Exception $exception) { + $this->logger->critical($exception); + $message = __('Failed to create the folder: %error', ['error' => $exception->getMessage()]); + throw new CouldNotSaveException($message, $exception); + } + } +} diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php new file mode 100644 index 0000000000000..ee78216fafdaf --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php @@ -0,0 +1,58 @@ +logger = $logger; + $this->storage = $storage; + } + + /** + * Deletes the existing folder + * + * @param string $path + * @throws CouldNotDeleteException + */ + public function execute(string $path): void + { + try { + $this->storage->deleteDirectory($this->storage->getCmsWysiwygImages()->getStorageRoot() . $path); + } catch (\Exception $exception) { + $this->logger->critical($exception); + $message = __('Failed to delete the folder: %error', ['error' => $exception->getMessage()]); + throw new CouldNotDeleteException($message, $exception); + } + } +} diff --git a/app/code/Magento/MediaGallery/Model/Directory/Excluded.php b/app/code/Magento/MediaGallery/Model/Directory/Excluded.php new file mode 100644 index 0000000000000..ad8843da9e8c3 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/Directory/Excluded.php @@ -0,0 +1,48 @@ +patterns = $patterns; + } + + /** + * Check if the path is excluded from displaying in the media gallery + * + * @param string $path + * @return bool + */ + public function isExcluded(string $path): bool + { + foreach ($this->patterns as $pattern) { + preg_match($pattern, $path, $result); + + if ($result) { + return true; + } + } + return false; + } +} diff --git a/app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php b/app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php new file mode 100644 index 0000000000000..177c67280580c --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php @@ -0,0 +1,74 @@ +getAssetById = $getAssetById; + $this->imagesStorage = $imagesStorage; + $this->filesystem = $filesystem; + } + + /** + * Delete image by asset ID + * + * @param int $assetId + * + * @return void + * + * @throws LocalizedException + */ + public function execute(int $assetId): void + { + $mediaFilePath = $this->getAssetById->execute($assetId)->getPath(); + $mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); + + if (!$mediaDirectory->isFile($mediaFilePath)) { + throw new LocalizedException(__('File "%1" does not exist in media directory.', $mediaFilePath)); + } + + $this->imagesStorage->deleteFile($mediaDirectory->getAbsolutePath() . $mediaFilePath); + } +} diff --git a/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php b/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php index 5b826a26e937d..ae61867884c7a 100644 --- a/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php +++ b/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php @@ -59,7 +59,7 @@ public function __construct( * * @param int $assetId * - * @return KeywordInterface[]|[] + * @return KeywordInterface[] * @throws IntegrationException */ public function execute(int $assetId): array diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php new file mode 100644 index 0000000000000..e468bee7cc5d7 --- /dev/null +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php @@ -0,0 +1,64 @@ +object = (new ObjectManager($this))->getObject( + Excluded::class, + [ + 'patterns' => [ + 'tmp' => '/pub\/media\/tmp/', + 'captcha' => '/pub\/media\/captcha/' + ] + ] + ); + } + + /** + * Test is directory path excluded + * + * @param string $path + * @param bool $isExcluded + * @dataProvider pathsProvider + */ + public function testIsExcluded(string $path, bool $isExcluded): void + { + $this->assertEquals($isExcluded, $this->object->isExcluded($path)); + } + + /** + * Data provider for testIsExcluded + * + * @return array + */ + public function pathsProvider() + { + return [ + ['/var/www/html/pub/media/tmp/somedir', true], + ['/var/www/html/pub/media/wysiwyg/somedir', false] + ]; + } +} diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php new file mode 100644 index 0000000000000..de5b5d42c71e3 --- /dev/null +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php @@ -0,0 +1,103 @@ +filesystem = $this->createMock(Filesystem::class); + $this->storage = $this->createMock(Storage::class); + $this->getById = $this->createMock(GetByIdInterface::class); + + $this->object = (new ObjectManager($this))->getObject( + DeleteByAssetId::class, + [ + 'filesystem' => $this->filesystem, + 'imagesStorage' => $this->storage, + 'getAssetById' => $this->getById + ] + ); + } + + /** + * Test delete file by asset id + */ + public function testExecute(): void + { + $assetId = 42; + $path = '/file1.jpg'; + $absoluteMediaPath = '/var/www/html/pub/media'; + + $asset = $this->createMock(AssetInterface::class); + $asset->expects($this->once()) + ->method('getPath') + ->willReturn($path); + + $this->getById->expects($this->once()) + ->method('execute') + ->with($assetId) + ->willReturn($asset); + + $directory = $this->createMock(Read::class); + $directory->expects($this->once()) + ->method('isFile') + ->willReturn(true); + $directory->expects($this->once()) + ->method('getAbsolutePath') + ->willReturn($absoluteMediaPath); + + $this->filesystem->expects($this->once()) + ->method('getDirectoryRead') + ->with(DirectoryList::MEDIA) + ->willReturn($directory); + + $this->storage->expects($this->once()) + ->method('deleteFile') + ->with($absoluteMediaPath . $path); + + $this->object->execute($assetId); + } +} diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index 24ed42b2b06dd..ccc8ce28a733d 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -29,4 +29,18 @@ + + + + /pub\/media\/captcha/ + /pub\/media\/catalog\/product/ + /pub\/media\/customer/ + /pub\/media\/downloadable/ + /pub\/media\/import/ + /pub\/media\/theme/ + /pub\/media\/theme_customization/ + /pub\/media\/tmp/ + + + diff --git a/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php b/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php index 0f4b78a6dc603..7cd94f90a60a0 100644 --- a/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php @@ -13,6 +13,7 @@ /** * Represents a media gallery asset which contains information about a media asset entity such * as path to the media storage, media asset title and its content type, etc. + * @api */ interface AssetInterface extends ExtensibleDataInterface { diff --git a/app/code/Magento/MediaGalleryApi/Api/Data/KeywordInterface.php b/app/code/Magento/MediaGalleryApi/Api/Data/KeywordInterface.php index ae3b7dbd76291..7f19e53d6e380 100644 --- a/app/code/Magento/MediaGalleryApi/Api/Data/KeywordInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/Data/KeywordInterface.php @@ -12,6 +12,7 @@ /** * Represents a media gallery keyword. This object contains information about a media asset keyword entity. + * @api */ interface KeywordInterface extends ExtensibleDataInterface { diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByDirectoryPathInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByDirectoryPathInterface.php index e55f7cb714f77..ee012c068a697 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByDirectoryPathInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByDirectoryPathInterface.php @@ -11,6 +11,7 @@ /** * A command represents the media gallery assets delete action. A media gallery asset is filtered by directory * path value. + * @api */ interface DeleteByDirectoryPathInterface { @@ -18,7 +19,6 @@ interface DeleteByDirectoryPathInterface * Delete media assets by directory path * * @param string $directoryPath - * * @return void */ public function execute(string $directoryPath): void; diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByPathInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByPathInterface.php index b3612a67ed536..0f04eaecf02ec 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByPathInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByPathInterface.php @@ -10,6 +10,7 @@ /** * A command represents the media gallery asset delete action. A media gallery asset is filtered by path value. + * @api */ interface DeleteByPathInterface { @@ -17,7 +18,6 @@ interface DeleteByPathInterface * Delete media asset by path * * @param string $mediaAssetPath - * * @return void */ public function execute(string $mediaAssetPath): void; diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByIdInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByIdInterface.php index ef2ceb5ffbfe6..9d0b8863baf22 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByIdInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByIdInterface.php @@ -10,6 +10,7 @@ /** * A command represents the get media gallery asset by using media gallery asset id as a filter parameter. + * @api */ interface GetByIdInterface { @@ -17,7 +18,6 @@ interface GetByIdInterface * Get media asset by id * * @param int $mediaAssetId - * * @return \Magento\MediaGalleryApi\Api\Data\AssetInterface * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\IntegrationException diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php index 547b0dc695dae..9d39b5cc692f3 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php @@ -10,6 +10,7 @@ /** * A command represents the get media gallery asset by using media gallery asset path as a filter parameter. + * @api */ interface GetByPathInterface { @@ -17,7 +18,6 @@ interface GetByPathInterface * Get media asset list * * @param string $mediaFilePath - * * @return \Magento\MediaGalleryApi\Api\Data\AssetInterface */ public function execute(string $mediaFilePath): \Magento\MediaGalleryApi\Api\Data\AssetInterface; diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php index b3e3607e6e822..6d2aae21754b8 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php @@ -12,6 +12,7 @@ /** * A command which executes the media gallery asset save operation. + * @api */ interface SaveInterface { @@ -19,7 +20,6 @@ interface SaveInterface * Save media asset * * @param \Magento\MediaGalleryApi\Api\Data\AssetInterface $mediaAsset - * * @return int * @throws \Magento\Framework\Exception\CouldNotSaveException */ diff --git a/app/code/Magento/MediaGalleryApi/Model/DataExtractorInterface.php b/app/code/Magento/MediaGalleryApi/Model/DataExtractorInterface.php index 6570cd2235412..33fd2425edc6f 100644 --- a/app/code/Magento/MediaGalleryApi/Model/DataExtractorInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/DataExtractorInterface.php @@ -9,6 +9,7 @@ /** * Extract data from an object using available getters + * @api */ interface DataExtractorInterface { diff --git a/app/code/Magento/MediaGalleryApi/Model/Directory/Command/CreateByPathInterface.php b/app/code/Magento/MediaGalleryApi/Model/Directory/Command/CreateByPathInterface.php new file mode 100644 index 0000000000000..59a371cdb823f --- /dev/null +++ b/app/code/Magento/MediaGalleryApi/Model/Directory/Command/CreateByPathInterface.php @@ -0,0 +1,24 @@ + Date: Mon, 30 Mar 2020 19:36:21 +0100 Subject: [PATCH 02/35] Fixed static tests --- .../MediaGallery/Model/Asset/Command/GetById.php | 2 +- .../Model/File/Command/DeleteByAssetId.php | 2 -- .../Model/Keyword/Command/GetAssetKeywords.php | 2 +- .../Test/Unit/Model/Directory/ExcludedTest.php | 4 ++-- .../Unit/Model/File/Command/DeleteByAssetIdTest.php | 10 +++++----- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php index b6153c45dbf8c..4475d5570c988 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php @@ -16,7 +16,7 @@ use Psr\Log\LoggerInterface; /** - * Class GetById + * Get media asset by id */ class GetById implements GetByIdInterface { diff --git a/app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php b/app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php index 177c67280580c..dff91e73c8c7a 100644 --- a/app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php +++ b/app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php @@ -55,9 +55,7 @@ public function __construct( * Delete image by asset ID * * @param int $assetId - * * @return void - * * @throws LocalizedException */ public function execute(int $assetId): void diff --git a/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php b/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php index ae61867884c7a..6cd8bd2463a2c 100644 --- a/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php +++ b/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php @@ -15,7 +15,7 @@ use Psr\Log\LoggerInterface; /** - * ClassGetAssetKeywords + * Retrieve keywords for the media asset */ class GetAssetKeywords implements GetAssetKeywordsInterface { diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php index e468bee7cc5d7..ea9094b3ac1f4 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php @@ -5,14 +5,14 @@ */ declare(strict_types=1); -namespace Magento\MediaGallery\Test\Unit\Model\File\Command; +namespace Magento\MediaGallery\Test\Unit\Model\Directory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use PHPUnit\Framework\TestCase; use Magento\MediaGallery\Model\Directory\Excluded; /** - * Test the DeleteByAssetIdTest command model + * Test the Excluded model */ class ExcludedTest extends TestCase { diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php index de5b5d42c71e3..903b366d0a9fd 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php @@ -7,16 +7,16 @@ namespace Magento\MediaGallery\Test\Unit\Model\File\Command; +use Magento\Cms\Model\Wysiwyg\Images\Storage; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\MediaGalleryApi\Api\Data\AssetInterface; -use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\Directory\Read; -use Magento\Cms\Model\Wysiwyg\Images\Storage; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\MediaGalleryApi\Api\Data\AssetInterface; use Magento\MediaGalleryApi\Model\Asset\Command\GetByIdInterface; use Magento\MediaGallery\Model\File\Command\DeleteByAssetId; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** * Test the DeleteByAssetIdTest command model From be2e6958f68593c30b8e21d39d467f5e5ddfcc53 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Wed, 1 Apr 2020 20:57:00 +0100 Subject: [PATCH 03/35] magento/magento2#27499: Code review changes --- .../Model/Directory/Command/CreateByPath.php | 5 ++-- .../Model/Directory/Command/DeleteByPath.php | 7 +++--- app/code/Magento/MediaGallery/etc/di.xml | 16 ------------- .../Model/Directory/Blacklist.php} | 19 +++++++++------ ...edInterface.php => BlacklistInterface.php} | 8 +++---- .../File/Command/DeleteByAssetIdInterface.php | 4 ++-- .../Unit/Model/Directory/BlacklistTest.php} | 16 ++++++------- app/code/Magento/MediaGalleryApi/etc/di.xml | 24 +++++++++++++++++++ 8 files changed, 55 insertions(+), 44 deletions(-) rename app/code/Magento/{MediaGallery/Model/Directory/Excluded.php => MediaGalleryApi/Model/Directory/Blacklist.php} (55%) rename app/code/Magento/MediaGalleryApi/Model/Directory/{ExcludedInterface.php => BlacklistInterface.php} (51%) rename app/code/Magento/{MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php => MediaGalleryApi/Test/Unit/Model/Directory/BlacklistTest.php} (72%) create mode 100644 app/code/Magento/MediaGalleryApi/etc/di.xml diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php index 6d0ea45aa02cd..c70f71df02a39 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php @@ -40,7 +40,7 @@ public function __construct( } /** - * Create new directory by provided path + * Create new directory by the provided path in the media storage * * @param string $path * @param string $name @@ -52,8 +52,7 @@ public function execute(string $path, string $name): void $this->storage->createDirectory($name, $this->storage->getCmsWysiwygImages()->getStorageRoot() . $path); } catch (\Exception $exception) { $this->logger->critical($exception); - $message = __('Failed to create the folder: %error', ['error' => $exception->getMessage()]); - throw new CouldNotSaveException($message, $exception); + throw new CouldNotSaveException(__('Failed to create the folder'), $exception); } } } diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php index ee78216fafdaf..73f0e08add751 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php @@ -13,7 +13,7 @@ use Psr\Log\LoggerInterface; /** - * Delete folder by provided path + * Delete directory from media storage by path */ class DeleteByPath implements DeleteByPathInterface { @@ -40,7 +40,7 @@ public function __construct( } /** - * Deletes the existing folder + * Removes directory and corresponding thumbnails directory from media storage if not in blacklist * * @param string $path * @throws CouldNotDeleteException @@ -51,8 +51,7 @@ public function execute(string $path): void $this->storage->deleteDirectory($this->storage->getCmsWysiwygImages()->getStorageRoot() . $path); } catch (\Exception $exception) { $this->logger->critical($exception); - $message = __('Failed to delete the folder: %error', ['error' => $exception->getMessage()]); - throw new CouldNotDeleteException($message, $exception); + throw new CouldNotDeleteException(__('Failed to delete the folder'), $exception); } } } diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index ccc8ce28a733d..2f402c30c5bc7 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -19,8 +19,6 @@ - - @@ -29,18 +27,4 @@ - - - - /pub\/media\/captcha/ - /pub\/media\/catalog\/product/ - /pub\/media\/customer/ - /pub\/media\/downloadable/ - /pub\/media\/import/ - /pub\/media\/theme/ - /pub\/media\/theme_customization/ - /pub\/media\/tmp/ - - - diff --git a/app/code/Magento/MediaGallery/Model/Directory/Excluded.php b/app/code/Magento/MediaGalleryApi/Model/Directory/Blacklist.php similarity index 55% rename from app/code/Magento/MediaGallery/Model/Directory/Excluded.php rename to app/code/Magento/MediaGalleryApi/Model/Directory/Blacklist.php index ad8843da9e8c3..fc6d73550f0fa 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Excluded.php +++ b/app/code/Magento/MediaGalleryApi/Model/Directory/Blacklist.php @@ -5,14 +5,16 @@ */ declare(strict_types=1); -namespace Magento\MediaGallery\Model\Directory; - -use Magento\MediaGalleryApi\Model\Directory\ExcludedInterface; +namespace Magento\MediaGalleryApi\Model\Directory; /** - * Directory paths that should not be included in the media gallery + * Directories blacklisted for media gallery. This class should be used for DI configuration. + * + * Please use the interface in the code (for constructor injection) instead of this implementation. + * + * @api */ -class Excluded implements ExcludedInterface +class Blacklist implements BlacklistInterface { /** * @var array @@ -29,14 +31,17 @@ public function __construct( } /** - * Check if the path is excluded from displaying in the media gallery + * Check if the directory path can be used in the media gallery operations * * @param string $path * @return bool */ - public function isExcluded(string $path): bool + public function isBlacklisted(string $path): bool { foreach ($this->patterns as $pattern) { + if (empty($pattern)) { + continue; + } preg_match($pattern, $path, $result); if ($result) { diff --git a/app/code/Magento/MediaGalleryApi/Model/Directory/ExcludedInterface.php b/app/code/Magento/MediaGalleryApi/Model/Directory/BlacklistInterface.php similarity index 51% rename from app/code/Magento/MediaGalleryApi/Model/Directory/ExcludedInterface.php rename to app/code/Magento/MediaGalleryApi/Model/Directory/BlacklistInterface.php index 159813a7094a3..f75af40fa72a7 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Directory/ExcludedInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Directory/BlacklistInterface.php @@ -8,16 +8,16 @@ namespace Magento\MediaGalleryApi\Model\Directory; /** - * Directory paths that should not be included in the media gallery + * Directory paths that are reserved by system and not be included in the media gallery * @api */ -interface ExcludedInterface +interface BlacklistInterface { /** - * Check if the path is excluded from displaying in the media gallery + * Check if the path is excluded from displaying and processing in the media gallery * * @param string $path * @return bool */ - public function isExcluded(string $path): bool; + public function isBlacklisted(string $path): bool; } diff --git a/app/code/Magento/MediaGalleryApi/Model/File/Command/DeleteByAssetIdInterface.php b/app/code/Magento/MediaGalleryApi/Model/File/Command/DeleteByAssetIdInterface.php index a73a29e8de1dd..5d973eb785abf 100644 --- a/app/code/Magento/MediaGalleryApi/Model/File/Command/DeleteByAssetIdInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/File/Command/DeleteByAssetIdInterface.php @@ -8,13 +8,13 @@ namespace Magento\MediaGalleryApi\Model\File\Command; /** - * Load Media Asset path from database by id and delete the file + * Remove the media asset file from the media storage * @api */ interface DeleteByAssetIdInterface { /** - * Delete the file by asset ID + * Remove the file of the media asset identified by the passed id from the media storage * * @param int $assetId * @return void diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php b/app/code/Magento/MediaGalleryApi/Test/Unit/Model/Directory/BlacklistTest.php similarity index 72% rename from app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php rename to app/code/Magento/MediaGalleryApi/Test/Unit/Model/Directory/BlacklistTest.php index ea9094b3ac1f4..3fe4ebd7cafcc 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/ExcludedTest.php +++ b/app/code/Magento/MediaGalleryApi/Test/Unit/Model/Directory/BlacklistTest.php @@ -5,19 +5,19 @@ */ declare(strict_types=1); -namespace Magento\MediaGallery\Test\Unit\Model\Directory; +namespace Magento\MediaGalleryApi\Test\Unit\Model\Directory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use PHPUnit\Framework\TestCase; -use Magento\MediaGallery\Model\Directory\Excluded; +use Magento\MediaGalleryApi\Model\Directory\Blacklist; /** * Test the Excluded model */ -class ExcludedTest extends TestCase +class BlacklistTest extends TestCase { /** - * @var Excluded + * @var Blacklist */ private $object; @@ -27,7 +27,7 @@ class ExcludedTest extends TestCase protected function setUp(): void { $this->object = (new ObjectManager($this))->getObject( - Excluded::class, + Blacklist::class, [ 'patterns' => [ 'tmp' => '/pub\/media\/tmp/', @@ -38,15 +38,15 @@ protected function setUp(): void } /** - * Test is directory path excluded + * Test if the directory path is blacklisted * * @param string $path * @param bool $isExcluded * @dataProvider pathsProvider */ - public function testIsExcluded(string $path, bool $isExcluded): void + public function testIsBlacklisted(string $path, bool $isExcluded): void { - $this->assertEquals($isExcluded, $this->object->isExcluded($path)); + $this->assertEquals($isExcluded, $this->object->isBlacklisted($path)); } /** diff --git a/app/code/Magento/MediaGalleryApi/etc/di.xml b/app/code/Magento/MediaGalleryApi/etc/di.xml new file mode 100644 index 0000000000000..7a00192cdd87b --- /dev/null +++ b/app/code/Magento/MediaGalleryApi/etc/di.xml @@ -0,0 +1,24 @@ + + + + + + + + /pub\/media\/captcha/ + /pub\/media\/catalog\/product/ + /pub\/media\/customer/ + /pub\/media\/downloadable/ + /pub\/media\/import/ + /pub\/media\/theme/ + /pub\/media\/theme_customization/ + /pub\/media\/tmp/ + + + + From e8eb3a9c474a38b129eace62e0af6a5f80d74b70 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Wed, 1 Apr 2020 21:01:38 +0100 Subject: [PATCH 04/35] magento/magento2#27499: Corrected DI configuration --- app/code/Magento/MediaGallery/etc/di.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index 2f402c30c5bc7..67ae43e667d17 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -19,6 +19,12 @@ + + + + + + From e671db30c6d593301b8817f34840d0c9e20672e2 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Thu, 2 Apr 2020 21:36:45 -0500 Subject: [PATCH 05/35] - Rename interface - Refactoring - Test coverage --- .../Model/Directory/IsBlacklisted.php} | 8 +- .../Model/Directory/IsBlacklistedTest.php} | 14 ++-- app/code/Magento/MediaGallery/etc/di.xml | 17 ++++ ...terface.php => IsBlacklistedInterface.php} | 4 +- app/code/Magento/MediaGalleryApi/etc/di.xml | 24 ------ .../Directory/Command/DeleteByPathTest.php | 83 +++++++++++++++++++ 6 files changed, 114 insertions(+), 36 deletions(-) rename app/code/Magento/{MediaGalleryApi/Model/Directory/Blacklist.php => MediaGallery/Model/Directory/IsBlacklisted.php} (82%) rename app/code/Magento/{MediaGalleryApi/Test/Unit/Model/Directory/BlacklistTest.php => MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php} (75%) rename app/code/Magento/MediaGalleryApi/Model/Directory/{BlacklistInterface.php => IsBlacklistedInterface.php} (84%) delete mode 100644 app/code/Magento/MediaGalleryApi/etc/di.xml create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php diff --git a/app/code/Magento/MediaGalleryApi/Model/Directory/Blacklist.php b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php similarity index 82% rename from app/code/Magento/MediaGalleryApi/Model/Directory/Blacklist.php rename to app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php index fc6d73550f0fa..312d5ab3dcf8a 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Directory/Blacklist.php +++ b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php @@ -5,7 +5,9 @@ */ declare(strict_types=1); -namespace Magento\MediaGalleryApi\Model\Directory; +namespace Magento\MediaGallery\Model\Directory; + +use Magento\MediaGalleryApi\Model\Directory\IsBlacklistedInterface; /** * Directories blacklisted for media gallery. This class should be used for DI configuration. @@ -14,7 +16,7 @@ * * @api */ -class Blacklist implements BlacklistInterface +class IsBlacklisted implements IsBlacklistedInterface { /** * @var array @@ -36,7 +38,7 @@ public function __construct( * @param string $path * @return bool */ - public function isBlacklisted(string $path): bool + public function execute(string $path): bool { foreach ($this->patterns as $pattern) { if (empty($pattern)) { diff --git a/app/code/Magento/MediaGalleryApi/Test/Unit/Model/Directory/BlacklistTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php similarity index 75% rename from app/code/Magento/MediaGalleryApi/Test/Unit/Model/Directory/BlacklistTest.php rename to app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php index 3fe4ebd7cafcc..4742db34cfcab 100644 --- a/app/code/Magento/MediaGalleryApi/Test/Unit/Model/Directory/BlacklistTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php @@ -5,19 +5,19 @@ */ declare(strict_types=1); -namespace Magento\MediaGalleryApi\Test\Unit\Model\Directory; +namespace Magento\MediaGallery\Test\Unit\Model\Directory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use PHPUnit\Framework\TestCase; -use Magento\MediaGalleryApi\Model\Directory\Blacklist; +use Magento\MediaGallery\Model\Directory\IsBlacklisted; /** * Test the Excluded model */ -class BlacklistTest extends TestCase +class IsBlacklistedTest extends TestCase { /** - * @var Blacklist + * @var */ private $object; @@ -27,7 +27,7 @@ class BlacklistTest extends TestCase protected function setUp(): void { $this->object = (new ObjectManager($this))->getObject( - Blacklist::class, + IsBlacklisted::class, [ 'patterns' => [ 'tmp' => '/pub\/media\/tmp/', @@ -44,9 +44,9 @@ protected function setUp(): void * @param bool $isExcluded * @dataProvider pathsProvider */ - public function testIsBlacklisted(string $path, bool $isExcluded): void + public function testExecute(string $path, bool $isExcluded): void { - $this->assertEquals($isExcluded, $this->object->isBlacklisted($path)); + $this->assertEquals($isExcluded, $this->object->execute($path)); } /** diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index 67ae43e667d17..ea05da9498607 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -23,8 +23,25 @@ + + + + + + + /pub\/media\/captcha/ + /pub\/media\/catalog\/product/ + /pub\/media\/customer/ + /pub\/media\/downloadable/ + /pub\/media\/import/ + /pub\/media\/theme/ + /pub\/media\/theme_customization/ + /pub\/media\/tmp/ + + + diff --git a/app/code/Magento/MediaGalleryApi/Model/Directory/BlacklistInterface.php b/app/code/Magento/MediaGalleryApi/Model/Directory/IsBlacklistedInterface.php similarity index 84% rename from app/code/Magento/MediaGalleryApi/Model/Directory/BlacklistInterface.php rename to app/code/Magento/MediaGalleryApi/Model/Directory/IsBlacklistedInterface.php index f75af40fa72a7..bc01bcdc77912 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Directory/BlacklistInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Directory/IsBlacklistedInterface.php @@ -11,7 +11,7 @@ * Directory paths that are reserved by system and not be included in the media gallery * @api */ -interface BlacklistInterface +interface IsBlacklistedInterface { /** * Check if the path is excluded from displaying and processing in the media gallery @@ -19,5 +19,5 @@ interface BlacklistInterface * @param string $path * @return bool */ - public function isBlacklisted(string $path): bool; + public function execute(string $path): bool; } diff --git a/app/code/Magento/MediaGalleryApi/etc/di.xml b/app/code/Magento/MediaGalleryApi/etc/di.xml deleted file mode 100644 index 7a00192cdd87b..0000000000000 --- a/app/code/Magento/MediaGalleryApi/etc/di.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - /pub\/media\/captcha/ - /pub\/media\/catalog\/product/ - /pub\/media\/customer/ - /pub\/media\/downloadable/ - /pub\/media\/import/ - /pub\/media\/theme/ - /pub\/media\/theme_customization/ - /pub\/media\/tmp/ - - - - diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php new file mode 100644 index 0000000000000..27da09e38889d --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php @@ -0,0 +1,83 @@ +get(Filesystem::class) + ->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath(); + mkdir(self::$_mediaPath . self::TEST_DIRECTORY_NAME); + } + + /** + * @inheritdoc + */ + public function setUp() + { + $this->deleteByPath = Bootstrap::getObjectManager()->create(DeleteByPathInterface::class); + } + + /** + * @return void + * @throws \Magento\Framework\Exception\CouldNotDeleteException + */ + public function testDeleteDirectoryWithExistingDirectoryAndCorrectAbsolutePath(): void + { + $fullPath = self::$_mediaPath . self::TEST_DIRECTORY_NAME; + $this->assertFileExists($fullPath); + $this->deleteByPath->execute(self::TEST_DIRECTORY_NAME); + $this->assertFileNotExists($fullPath); + } + + /** + * @return void + * @throws \Magento\Framework\Exception\CouldNotDeleteException + * @expectedException \Magento\Framework\Exception\CouldNotDeleteException + */ + public function testDeleteDirectoryWithRelativePathUnderMediaFolder(): void + { + $this->deleteByPath->execute('../../pub/media'); + } + + /** + * @return void + * @throws \Magento\Framework\Exception\CouldNotDeleteException + * @expectedException \Magento\Framework\Exception\CouldNotDeleteException + */ + public function testDeleteDirectoryThatIsNotAllowed(): void + { + $this->deleteByPath->execute('theme'); + } +} From 83e7e37e2e2bef0bfffa67814adbb7bd3557805d Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Fri, 3 Apr 2020 03:13:00 -0500 Subject: [PATCH 06/35] Test coverage --- .../Directory/Command/CreateByPathTest.php | 95 ++++++++++++++++++ .../Directory/Command/DeleteByPathTest.php | 21 +++- .../File/Command/DeleteByAssertIdTest.php | 99 +++++++++++++++++++ .../MediaGallery/_files/media_asset.php | 29 ++++++ 4 files changed, 241 insertions(+), 3 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php new file mode 100644 index 0000000000000..84861a5375713 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php @@ -0,0 +1,95 @@ +get(Filesystem::class) + ->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath(); + } + + /** + * @inheritdoc + */ + public function setUp() + { + $this->createByPath = Bootstrap::getObjectManager()->create(CreateByPathInterface::class); + } + + /** + * @return void + * @throws \Magento\Framework\Exception\CouldNotSaveException + */ + public function testCreateDirectory(): void + { + $fullPath = self::$_mediaPath . self::TEST_DIRECTORY_NAME; + $this->createByPath->execute('', self::TEST_DIRECTORY_NAME); + $this->assertFileExists($fullPath); + } + + /** + * @return void + * @throws \Magento\Framework\Exception\CouldNotSaveException + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + */ + public function testCreateDirectoryThatAlreadyExist(): void + { + $this->createByPath->execute('', self::TEST_DIRECTORY_NAME); + } + + /** + * @return void + * @throws \Magento\Framework\Exception\CouldNotSaveException + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + */ + public function testCreateDirectoryWithRelativePath(): void + { + $this->createByPath->execute('../../pub/', self::TEST_DIRECTORY_NAME); + } + + /** + * @throws \Magento\Framework\Exception\FileSystemException + */ + public static function tearDownAfterClass() + { + $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get(\Magento\Framework\Filesystem::class); + /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */ + $directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); + if ($directory->isExist(self::TEST_DIRECTORY_NAME)) { + $directory->delete(self::TEST_DIRECTORY_NAME); + } + } +} diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php index 27da09e38889d..282dbe2ed11d0 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php @@ -36,9 +36,10 @@ class DeleteByPathTest extends \PHPUnit\Framework\TestCase */ public static function setUpBeforeClass() { - self::$_mediaPath = Bootstrap::getObjectManager()->get(Filesystem::class) - ->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath(); - mkdir(self::$_mediaPath . self::TEST_DIRECTORY_NAME); + /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */ + $directory = Bootstrap::getObjectManager()->get(Filesystem::class)->getDirectoryWrite(DirectoryList::MEDIA); + self::$_mediaPath = $directory->getAbsolutePath(); + $directory->create(self::TEST_DIRECTORY_NAME); } /** @@ -80,4 +81,18 @@ public function testDeleteDirectoryThatIsNotAllowed(): void { $this->deleteByPath->execute('theme'); } + + /** + * @throws \Magento\Framework\Exception\FileSystemException + */ + public static function tearDownAfterClass() + { + $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get(\Magento\Framework\Filesystem::class); + /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */ + $directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); + if ($directory->isExist(self::TEST_DIRECTORY_NAME)) { + $directory->delete(self::TEST_DIRECTORY_NAME); + } + } } diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php new file mode 100644 index 0000000000000..7eb0d7a886e92 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php @@ -0,0 +1,99 @@ +get(Filesystem::class)->getDirectoryWrite(DirectoryList::MEDIA); + self::$_mediaPath = $directory->getAbsolutePath(); + $directory->create(self::TEST_DIRECTORY_NAME); + $directory->touch(self::TEST_DIRECTORY_NAME . '/path.jpg'); + } + + /** + * @inheritdoc + */ + public function setUp() + { + $this->deleteByAssetId = Bootstrap::getObjectManager()->create(DeleteByAssetIdInterface::class); + } + + /** + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * @return void + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function testDeleteByAssetIdWithExistingAsset(): void + { + $fullPath = self::$_mediaPath . self::TEST_DIRECTORY_NAME . '/path.jpg'; + $getById = Bootstrap::getObjectManager()->get(GetByIdInterface::class); + $this->assertFileExists($fullPath); + $this->assertEquals(1, $getById->execute(1)->getId()); + $this->deleteByAssetId->execute(1); + $this->assertFileNotExists($fullPath); + $this->expectException(\Magento\Framework\Exception\NoSuchEntityException::class); + $getById->execute(1); + } + + /** + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * @return void + * @throws \Magento\Framework\Exception\LocalizedException + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testDeleteByAssetIdWithoutAsset(): void + { + $fullPath = self::$_mediaPath . self::TEST_DIRECTORY_NAME . '/path.jpg'; + $this->assertFileNotExists($fullPath); + $this->deleteByAssetId->execute(1); + } + + /** + * @throws \Magento\Framework\Exception\FileSystemException + */ + public static function tearDownAfterClass() + { + $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get(\Magento\Framework\Filesystem::class); + /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */ + $directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); + if ($directory->isExist(self::TEST_DIRECTORY_NAME)) { + $directory->delete(self::TEST_DIRECTORY_NAME); + } + } +} diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php new file mode 100644 index 0000000000000..c0a6691e54852 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php @@ -0,0 +1,29 @@ +get(AssetInterfaceFactory::class); +/** @var AssetInterface $mediaAsset */ +$mediaAsset = $mediaAssetFactory->create( + [ + 'data' => [ + 'id' => 1, + 'path' => 'testDirectory/path.jpg' + ] + ] +); +/** @var SaveInterface $mediaSave */ +$mediaSave = $objectManager->get(SaveInterface::class); +$mediaId = $mediaSave->execute($mediaAsset); + From 3784f92befdc78d8db72f3a9755948bf63f6f921 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Fri, 3 Apr 2020 14:12:20 +0100 Subject: [PATCH 07/35] magento/magento2#27499: Removed DataExtractor in favour to DataObjectProcessor --- .../MediaGallery/Model/Asset/Command/Save.php | 17 +- .../MediaGallery/Model/DataExtractor.php | 48 ------ .../Unit/Model/Asset/Command/SaveTest.php | 21 +-- .../Test/Unit/Model/DataExtractorTest.php | 161 ------------------ app/code/Magento/MediaGallery/etc/di.xml | 2 - .../Model/DataExtractorInterface.php | 24 --- 6 files changed, 21 insertions(+), 252 deletions(-) delete mode 100644 app/code/Magento/MediaGallery/Model/DataExtractor.php delete mode 100644 app/code/Magento/MediaGallery/Test/Unit/Model/DataExtractorTest.php delete mode 100644 app/code/Magento/MediaGalleryApi/Model/DataExtractorInterface.php diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php index 7cb2f73169642..e017c4c58eb63 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php @@ -7,11 +7,11 @@ namespace Magento\MediaGallery\Model\Asset\Command; -use Magento\MediaGalleryApi\Model\DataExtractorInterface; use Magento\MediaGalleryApi\Api\Data\AssetInterface; use Magento\MediaGalleryApi\Model\Asset\Command\SaveInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Exception\CouldNotSaveException; +use Magento\Framework\Reflection\DataObjectProcessor; use Psr\Log\LoggerInterface; /** @@ -27,9 +27,9 @@ class Save implements SaveInterface private $resourceConnection; /** - * @var DataExtractorInterface + * @var DataObjectProcessor */ - private $extractor; + private $objectProcessor; /** * @var LoggerInterface @@ -40,16 +40,16 @@ class Save implements SaveInterface * Save constructor. * * @param ResourceConnection $resourceConnection - * @param DataExtractorInterface $extractor + * @param DataObjectProcessor $objectProcessor * @param LoggerInterface $logger */ public function __construct( ResourceConnection $resourceConnection, - DataExtractorInterface $extractor, + DataObjectProcessor $objectProcessor, LoggerInterface $logger ) { $this->resourceConnection = $resourceConnection; - $this->extractor = $extractor; + $this->objectProcessor = $objectProcessor; $this->logger = $logger; } @@ -68,7 +68,10 @@ public function execute(AssetInterface $mediaAsset): int $connection = $this->resourceConnection->getConnection(); $tableName = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET); - $connection->insertOnDuplicate($tableName, $this->extractor->extract($mediaAsset, AssetInterface::class)); + $connection->insertOnDuplicate( + $tableName, + array_filter($this->objectProcessor->buildOutputDataArray($mediaAsset, AssetInterface::class)) + ); return (int) $connection->lastInsertId($tableName); } catch (\Exception $exception) { $this->logger->critical($exception); diff --git a/app/code/Magento/MediaGallery/Model/DataExtractor.php b/app/code/Magento/MediaGallery/Model/DataExtractor.php deleted file mode 100644 index 92cf237022c28..0000000000000 --- a/app/code/Magento/MediaGallery/Model/DataExtractor.php +++ /dev/null @@ -1,48 +0,0 @@ -getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { - $methodName = $method->getName(); - if (strpos($methodName, 'get') !== 0 - || !empty($method->getParameters()) - || strpos($methodName, 'getExtensionAttributes') !== false - ) { - continue; - } - $value = $object->$methodName(); - if (!empty($value)) { - $key = strtolower(preg_replace("/([a-z])([A-Z])/", "$1_$2", substr($methodName, 3))); - $data[$key] = $value; - } - } - return $data; - } -} diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php index 2f736fb832eac..8af26f0c64b16 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php @@ -7,9 +7,9 @@ namespace Magento\MediaGallery\Test\Unit\Model\Asset\Command; +use Magento\Eav\Helper\Data; use Magento\MediaGallery\Model\Asset\Command\Save; use Magento\MediaGalleryApi\Api\Data\AssetInterface; -use Magento\MediaGalleryApi\Model\DataExtractorInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Adapter\Pdo\Mysql; @@ -17,6 +17,7 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Magento\Framework\Reflection\DataObjectProcessor; use Psr\Log\LoggerInterface; /** @@ -63,14 +64,14 @@ class SaveTest extends TestCase private $resourceConnectionMock; /** - * @var MockObject | DataExtractorInterface + * @var MockObject | LoggerInterface */ private $loggerMock; /** - * @var MockObject | LoggerInterface + * @var MockObject | DataObjectProcessor */ - private $extractorMock; + private $objectProcessor; /** * @var MockObject | AdapterInterface @@ -97,7 +98,7 @@ protected function setUp(): void $this->mediaAssetMock = $this->createMock(AssetInterface::class); /* Save constructor mocks */ - $this->extractorMock = $this->createMock(DataExtractorInterface::class); + $this->objectProcessor = $this->createMock(DataObjectProcessor::class); $this->loggerMock = $this->createMock(LoggerInterface::class); $this->resourceConnectionMock = $this->createConfiguredMock( ResourceConnection::class, @@ -112,7 +113,7 @@ protected function setUp(): void Save::class, [ 'resourceConnection' => $this->resourceConnectionMock, - 'extractor' => $this->extractorMock, + 'objectProcessor' => $this->objectProcessor, 'logger' => $this->loggerMock ] ); @@ -126,9 +127,9 @@ public function testSuccessfulExecute(): void $this->resourceConnectionMock->expects(self::once())->method('getConnection'); $this->resourceConnectionMock->expects(self::once())->method('getTableName'); - $this->extractorMock + $this->objectProcessor ->expects(self::once()) - ->method('extract') + ->method('buildOutputDataArray') ->with($this->mediaAssetMock, AssetInterface::class) ->willReturn(self::IMAGE_DATA); @@ -155,9 +156,9 @@ public function testExceptionExecute(): void $this->resourceConnectionMock->expects(self::once())->method('getConnection'); $this->resourceConnectionMock->expects(self::once())->method('getTableName'); - $this->extractorMock + $this->objectProcessor ->expects(self::once()) - ->method('extract') + ->method('buildOutputDataArray') ->with($this->mediaAssetMock, AssetInterface::class) ->willReturn(self::IMAGE_DATA); diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/DataExtractorTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/DataExtractorTest.php deleted file mode 100644 index f70e4ccdae22c..0000000000000 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/DataExtractorTest.php +++ /dev/null @@ -1,161 +0,0 @@ -dataExtractor = new DataExtractor(); - } - - /** - * Test extract object data by interface - * - * @dataProvider assetProvider - * - * @param string $class - * @param string|null $interfaceClass - * @param array $expectedData - * - * @throws \ReflectionException - */ - public function testExtractData(string $class, $interfaceClass, array $expectedData): void - { - $data = []; - foreach ($expectedData as $expectedDataKey => $expectedDataItem) { - $data[$expectedDataKey] = $expectedDataItem['value']; - } - $model = (new ObjectManager($this))->getObject( - $class, - [ - 'data' => $data, - ] - ); - if ($interfaceClass) { - $receivedData = $this->dataExtractor->extract($model, $interfaceClass); - $this->checkAssetValues($expectedData, $receivedData, $model); - } else { - $receivedData = $this->dataExtractor->extract($model); - $this->checkKeyWordValues($expectedData, $receivedData, $model); - } - } - - /** - * @param array $expectedData - * @param array $data - * @param object $model - */ - private function checkAssetValues(array $expectedData, array $data, $model) - { - foreach ($expectedData as $expectedDataKey => $expectedDataItem) { - $this->assertEquals($data[$expectedDataKey] ?? null, $model->{$expectedDataItem['method']}()); - $this->assertEquals($data[$expectedDataKey] ?? null, $expectedDataItem['value']); - } - $this->assertEquals(array_keys($expectedData), array_keys($data)); - } - - /** - * @param array $expectedData - * @param array $data - * @param object $model - */ - private function checkKeyWordValues(array $expectedData, array $data, $model) - { - foreach ($expectedData as $expectedDataKey => $expectedDataItem) { - $this->assertEquals($data[$expectedDataKey] ?? null, $model->{$expectedDataItem['method']}()); - $this->assertEquals($data[$expectedDataKey] ?? null, $expectedDataItem['value']); - } - $this->assertEquals(array_keys($expectedData), array_keys(array_slice($data, 0, 2))); - } - - /** - * @return array - */ - public function assetProvider() - { - return [ - 'Asset conversion with interface' => [ - Asset::class, - AssetInterface::class, - [ - 'id' => [ - 'value' => 2, - 'method' => 'getId', - ], - 'path' => [ - 'value' => 'path', - 'method' => 'getPath', - ], - 'title' => [ - 'value' => 'title', - 'method' => 'getTitle', - ], - 'source' => [ - 'value' => 'source', - 'method' => 'getSource', - ], - 'content_type' => [ - 'value' => 'content_type', - 'method' => 'getContentType', - ], - 'height' => [ - 'value' => 4, - 'method' => 'getHeight', - ], - 'width' => [ - 'value' => 3, - 'method' => 'getWidth', - ], - 'size' => [ - 'value' => 300, - 'method' => 'getSize', - ], - 'created_at' => [ - 'value' => '2019-11-28 10:40:09', - 'method' => 'getCreatedAt', - ], - 'updated_at' => [ - 'value' => '2019-11-28 10:41:08', - 'method' => 'getUpdatedAt', - ], - ], - ], - 'Keyword conversion without interface' => [ - Keyword::class, - '', - [ - 'id' => [ - 'value' => 2, - 'method' => 'getId', - ], - 'keyword' => [ - 'value' => 'keyword', - 'method' => 'getKeyword', - ], - ], - ] - ]; - } -} diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index ea05da9498607..c993d82342326 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -19,8 +19,6 @@ - - diff --git a/app/code/Magento/MediaGalleryApi/Model/DataExtractorInterface.php b/app/code/Magento/MediaGalleryApi/Model/DataExtractorInterface.php deleted file mode 100644 index 33fd2425edc6f..0000000000000 --- a/app/code/Magento/MediaGalleryApi/Model/DataExtractorInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - Date: Fri, 3 Apr 2020 14:23:27 +0100 Subject: [PATCH 08/35] magento/magento2#27499: Code review changes --- .../MediaGallery/Model/Asset/Command/GetByPath.php | 8 ++++---- .../Magento/MediaGalleryApi/Api/Data/AssetInterface.php | 2 +- .../Model/Asset/Command/GetByPathInterface.php | 4 ++-- .../MediaGalleryApi/Model/Asset/Command/SaveInterface.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php index fe5fcca6cb0de..32c7323c3a511 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php @@ -59,22 +59,22 @@ public function __construct( /** * Return media asset asset list * - * @param string $mediaFilePath + * @param string $path * * @return AssetInterface * @throws IntegrationException */ - public function execute(string $mediaFilePath): AssetInterface + public function execute(string $path): AssetInterface { try { $connection = $this->resourceConnection->getConnection(); $select = $connection->select() ->from($this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET)) - ->where(self::MEDIA_GALLERY_ASSET_PATH . ' = ?', $mediaFilePath); + ->where(self::MEDIA_GALLERY_ASSET_PATH . ' = ?', $path); $data = $connection->query($select)->fetch(); if (empty($data)) { - $message = __('There is no such media asset with path "%1"', $mediaFilePath); + $message = __('There is no such media asset with path "%1"', $path); throw new NoSuchEntityException($message); } diff --git a/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php b/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php index 7cd94f90a60a0..c3454400b2995 100644 --- a/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php @@ -39,7 +39,7 @@ public function getPath(): string; public function getTitle(): ?string; /** - * Get source of the file + * Get the name of the channel/stock/integration file was retrieved from. null if not identified. * * @return string|null */ diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php index 9d39b5cc692f3..aa3f76f721374 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php @@ -17,8 +17,8 @@ interface GetByPathInterface /** * Get media asset list * - * @param string $mediaFilePath + * @param string $path * @return \Magento\MediaGalleryApi\Api\Data\AssetInterface */ - public function execute(string $mediaFilePath): \Magento\MediaGalleryApi\Api\Data\AssetInterface; + public function execute(string $path): \Magento\MediaGalleryApi\Api\Data\AssetInterface; } diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php index 6d2aae21754b8..77f8fcf8b2c2e 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php @@ -17,7 +17,7 @@ interface SaveInterface { /** - * Save media asset + * Save media asset and return the media asset id * * @param \Magento\MediaGalleryApi\Api\Data\AssetInterface $mediaAsset * @return int From 909ea3f184eaeeb3caff92178722ec02a48a813d Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Sat, 4 Apr 2020 17:28:17 +0100 Subject: [PATCH 09/35] agento/magento2#27499: Updated blacklist patterns --- app/code/Magento/MediaGallery/etc/di.xml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index c993d82342326..8910a2261005c 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -29,14 +29,15 @@ - /pub\/media\/captcha/ - /pub\/media\/catalog\/product/ - /pub\/media\/customer/ - /pub\/media\/downloadable/ - /pub\/media\/import/ - /pub\/media\/theme/ - /pub\/media\/theme_customization/ - /pub\/media\/tmp/ + /^captcha/ + /^catalog\/product/ + /^customer/ + /^downloadable/ + /^import/ + /^theme/ + /^theme_customization/ + /^tmp/ + /^\./ From 0a57486892d9cdf9b4bdb26e50e69906fb3ed2fc Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 7 Apr 2020 00:36:20 -0500 Subject: [PATCH 10/35] Add configuration for MediaGallery/Directory --- .../MediaGallery/Model/Directory/Config.php | 40 ++++++++++++ .../Model/Directory/Config/Converter.php | 57 ++++++++++++++++ .../Model/Directory/Config/Reader.php | 65 +++++++++++++++++++ .../Model/Directory/Config/SchemaLocator.php | 48 ++++++++++++++ .../Model/Directory/IsBlacklisted.php | 14 ++-- app/code/Magento/MediaGallery/etc/di.xml | 32 +++++---- .../Magento/MediaGallery/etc/directory.xml | 22 +++++++ .../Magento/MediaGallery/etc/directory.xsd | 38 +++++++++++ 8 files changed, 294 insertions(+), 22 deletions(-) create mode 100644 app/code/Magento/MediaGallery/Model/Directory/Config.php create mode 100644 app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php create mode 100644 app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php create mode 100644 app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php create mode 100644 app/code/Magento/MediaGallery/etc/directory.xml create mode 100644 app/code/Magento/MediaGallery/etc/directory.xsd diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config.php b/app/code/Magento/MediaGallery/Model/Directory/Config.php new file mode 100644 index 0000000000000..59b37cb4bbd25 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/Directory/Config.php @@ -0,0 +1,40 @@ +data = $data; + } + + /** + * Get config value by key. + * + * @param string|null $key + * @param string|null $default + * @return array + */ + public function get($key = null, $default = null) + { + return $this->data->get($key, $default); + } +} diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php b/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php new file mode 100644 index 0000000000000..564512935a3c4 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php @@ -0,0 +1,57 @@ +getElementsByTagName(self::BLACKLIST_TAG_NAME) as $blacklist) { + $result[self::BLACKLIST_TAG_NAME] = []; + foreach ($blacklist->getElementsByTagName(self::PATTERNS_TAG_NAME) as $patterns) { + $result[self::BLACKLIST_TAG_NAME][self::PATTERNS_TAG_NAME] = []; + foreach ($patterns->getElementsByTagName(self::PATTERN_TAG_NAME) as $pattern) { + $result[self::BLACKLIST_TAG_NAME][self::PATTERNS_TAG_NAME] + [$pattern->attributes->getNamedItem('name')->nodeValue] = $pattern->nodeValue; + } + } + } + + return $result; + } +} diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php b/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php new file mode 100644 index 0000000000000..a502139b44ded --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php @@ -0,0 +1,65 @@ + 'patterns', + '/config/patterns/pattern' => 'name', + ]; + + /** + * XML Configuration file name + */ + private const XML_FILE_NAME = 'directory.xml'; + + /** + * Construct the FileSystem Reader Class + * + * @param \Magento\Framework\Config\FileResolverInterface $fileResolver + * @param Converter $converter + * @param SchemaLocator $schemaLocator + * @param \Magento\Framework\Config\ValidationStateInterface $validationState + * @param string $fileName + * @param array $idAttributes + * @param string $domDocumentClass + * @param string $defaultScope + */ + public function __construct( + FileResolverInterface $fileResolver, + Converter $converter, + SchemaLocator $schemaLocator, + ValidationStateInterface $validationState, + $fileName = self::XML_FILE_NAME, + $idAttributes = [], + $domDocumentClass = Dom::class, + $defaultScope = Area::AREA_GLOBAL + ) { + parent::__construct( + $fileResolver, + $converter, + $schemaLocator, + $validationState, + $fileName, + $idAttributes, + $domDocumentClass, + $defaultScope + ); + } +} diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php b/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php new file mode 100644 index 0000000000000..26364951a23d4 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php @@ -0,0 +1,48 @@ +schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_MediaGallery') . '/directory.xsd'; + } + + /** + * Get path to merged config schema + * + * @return string|null + */ + public function getSchema() + { + return $this->schema; + } + + /** + * Get path to per file validation schema + * + * @return string|null + */ + public function getPerFileSchema() + { + return $this->schema; + } +} diff --git a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php index 312d5ab3dcf8a..7e79492f022dc 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php +++ b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php @@ -19,17 +19,15 @@ class IsBlacklisted implements IsBlacklistedInterface { /** - * @var array + * @var Config */ - private $patterns; + private $config; /** - * @param array $patterns + * @param Config $config */ - public function __construct( - array $patterns - ) { - $this->patterns = $patterns; + public function __construct(Config $config) { + $this->config = $config; } /** @@ -40,7 +38,7 @@ public function __construct( */ public function execute(string $path): bool { - foreach ($this->patterns as $pattern) { + foreach ($this->config->get('blacklist/patterns') as $pattern) { if (empty($pattern)) { continue; } diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index ea05da9498607..f06499455770d 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -28,20 +28,6 @@ - - - - /pub\/media\/captcha/ - /pub\/media\/catalog\/product/ - /pub\/media\/customer/ - /pub\/media\/downloadable/ - /pub\/media\/import/ - /pub\/media\/theme/ - /pub\/media\/theme_customization/ - /pub\/media\/tmp/ - - - @@ -50,4 +36,22 @@ + + + directory.xml + Magento\MediaGallery\Model\Directory\Config\Converter + Magento\MediaGallery\Model\Directory\Config\SchemaLocator + + + + + Magento\MediaGallery\Model\Directory\Config\Reader + Media_Gallery_Patterns_CacheId + + + + + Magento\MediaGallery\Model\Directory\Config\Data + + diff --git a/app/code/Magento/MediaGallery/etc/directory.xml b/app/code/Magento/MediaGallery/etc/directory.xml new file mode 100644 index 0000000000000..4bdaeb5edd0c7 --- /dev/null +++ b/app/code/Magento/MediaGallery/etc/directory.xml @@ -0,0 +1,22 @@ + + + + + + /pub\/media\/captcha/ + /pub\/media\/catalog\/product/ + /pub\/media\/customer/ + /pub\/media\/downloadable/ + /pub\/media\/import/ + /pub\/media\/theme/ + /pub\/media\/theme_customization/ + /pub\/media\/tmp/ + /^\./ + + + diff --git a/app/code/Magento/MediaGallery/etc/directory.xsd b/app/code/Magento/MediaGallery/etc/directory.xsd new file mode 100644 index 0000000000000..b9abd04ae1456 --- /dev/null +++ b/app/code/Magento/MediaGallery/etc/directory.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 90bf91d3cd8c5fecc25e32096a812dd5226b4852 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Tue, 7 Apr 2020 13:01:21 +0100 Subject: [PATCH 11/35] Corrected blacklist patterns --- .../Model/Directory/IsBlacklisted.php | 13 ++++++------- app/code/Magento/MediaGallery/etc/directory.xml | 16 ++++++++-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php index 7e79492f022dc..def5a0c817401 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php +++ b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php @@ -10,14 +10,12 @@ use Magento\MediaGalleryApi\Model\Directory\IsBlacklistedInterface; /** - * Directories blacklisted for media gallery. This class should be used for DI configuration. - * - * Please use the interface in the code (for constructor injection) instead of this implementation. - * - * @api + * Check if the path is blacklisted for media gallery. Directory path may be blacklisted if it's reserved by the system */ class IsBlacklisted implements IsBlacklistedInterface { + const XML_PATH_BLACKLIST_PATTERNS = 'blacklist/patterns'; + /** * @var Config */ @@ -26,7 +24,8 @@ class IsBlacklisted implements IsBlacklistedInterface /** * @param Config $config */ - public function __construct(Config $config) { + public function __construct(Config $config) + { $this->config = $config; } @@ -38,7 +37,7 @@ public function __construct(Config $config) { */ public function execute(string $path): bool { - foreach ($this->config->get('blacklist/patterns') as $pattern) { + foreach ($this->config->get(self::XML_PATH_BLACKLIST_PATTERNS) as $pattern) { if (empty($pattern)) { continue; } diff --git a/app/code/Magento/MediaGallery/etc/directory.xml b/app/code/Magento/MediaGallery/etc/directory.xml index 4bdaeb5edd0c7..2eb37aa81ab42 100644 --- a/app/code/Magento/MediaGallery/etc/directory.xml +++ b/app/code/Magento/MediaGallery/etc/directory.xml @@ -8,14 +8,14 @@ - /pub\/media\/captcha/ - /pub\/media\/catalog\/product/ - /pub\/media\/customer/ - /pub\/media\/downloadable/ - /pub\/media\/import/ - /pub\/media\/theme/ - /pub\/media\/theme_customization/ - /pub\/media\/tmp/ + /^captcha/ + /^catalog\/product/ + /^customer/ + /^downloadable/ + /^import/ + /^theme/ + /^theme_customization/ + /^tmp/ /^\./ From 7fd26a92ae5a3c38d156c958356c6afdf40688f7 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Tue, 7 Apr 2020 14:29:50 +0100 Subject: [PATCH 12/35] Added comments and strict types enabling --- .../Magento/MediaGallery/Model/Directory/Config.php | 3 ++- .../Model/Directory/Config/Converter.php | 12 +++++++----- .../MediaGallery/Model/Directory/Config/Reader.php | 5 +++++ .../Model/Directory/Config/SchemaLocator.php | 5 +++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config.php b/app/code/Magento/MediaGallery/Model/Directory/Config.php index 59b37cb4bbd25..7cd83d4edcb32 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config.php @@ -3,13 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\MediaGallery\Model\Directory; use Magento\Framework\Config\DataInterface; /** - * Config of Magento Media Gallery Directory. + * Media gallery directory config */ class Config { diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php b/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php index 564512935a3c4..c0b927cd2d884 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php @@ -3,29 +3,31 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\MediaGallery\Model\Directory\Config; use Magento\Framework\Config\ConverterInterface; /** - * Class Converter + * Media gallery directory config converter */ class Converter implements ConverterInterface { /** * Blacklist tag name */ - private CONST BLACKLIST_TAG_NAME = 'blacklist'; + private const BLACKLIST_TAG_NAME = 'blacklist'; /** * Patterns tag name */ - private CONST PATTERNS_TAG_NAME = 'patterns'; + private const PATTERNS_TAG_NAME = 'patterns'; /** * Pattern tag name */ - private CONST PATTERN_TAG_NAME = 'pattern'; + private const PATTERN_TAG_NAME = 'pattern'; /** * Convert dom node to array @@ -33,7 +35,7 @@ class Converter implements ConverterInterface * @param \DOMDocument $source * @return array */ - public function convert($source) : array + public function convert($source): array { $result = []; diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php b/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php index a502139b44ded..b8f844e26d979 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\MediaGallery\Model\Directory\Config; use Magento\Framework\App\Area; @@ -12,6 +14,9 @@ use Magento\Framework\Config\ValidationStateInterface; use Magento\Framework\Config\Dom; +/** + * Media gallery directory config reader + */ class Reader extends Filesystem implements ReaderInterface { /** diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php b/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php index 26364951a23d4..6661b0d7e95ee 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php @@ -3,12 +3,17 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\MediaGallery\Model\Directory\Config; use Magento\Framework\Module\Dir; use Magento\Framework\Module\Dir\Reader; use Magento\Framework\Config\SchemaLocatorInterface; +/** + * Media gallery directory config schema locator + */ class SchemaLocator implements SchemaLocatorInterface { /** From e1bea53943aeff722bc4c070701640218a62c06b Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 7 Apr 2020 23:16:03 -0500 Subject: [PATCH 13/35] - Fix unit test - Refactoring --- .../MediaGallery/Model/Directory/Config.php | 12 ++++++ .../Model/Directory/Config/Converter.php | 2 +- .../Model/Directory/Config/Reader.php | 43 ------------------- .../Model/Directory/IsBlacklisted.php | 4 +- .../Unit/Model/Asset/Command/SaveTest.php | 1 - .../Model/Directory/IsBlacklistedTest.php | 23 ++++++---- 6 files changed, 28 insertions(+), 57 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config.php b/app/code/Magento/MediaGallery/Model/Directory/Config.php index 7cd83d4edcb32..3e47161f35c06 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config.php @@ -14,6 +14,8 @@ */ class Config { + private const XML_PATH_BLACKLIST_PATTERNS = 'blacklist/patterns'; + /** * @var DataInterface */ @@ -38,4 +40,14 @@ public function get($key = null, $default = null) { return $this->data->get($key, $default); } + + /** + * Returns list of blacklist regexp patterns + * + * @return array + */ + public function getBlacklistPatterns() : array + { + return $this->data->get(self::XML_PATH_BLACKLIST_PATTERNS); + } } diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php b/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php index c0b927cd2d884..91f16d246f636 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config/Converter.php @@ -40,7 +40,7 @@ public function convert($source): array $result = []; if (!$source instanceof \DOMDocument) { - return $result; + throw new \InvalidArgumentException('The source should be instance of DOMDocument'); } foreach ($source->getElementsByTagName(self::BLACKLIST_TAG_NAME) as $blacklist) { diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php b/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php index b8f844e26d979..85f61f712d580 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php @@ -7,12 +7,8 @@ namespace Magento\MediaGallery\Model\Directory\Config; -use Magento\Framework\App\Area; use Magento\Framework\Config\ReaderInterface; use Magento\Framework\Config\Reader\Filesystem; -use Magento\Framework\Config\FileResolverInterface; -use Magento\Framework\Config\ValidationStateInterface; -use Magento\Framework\Config\Dom; /** * Media gallery directory config reader @@ -28,43 +24,4 @@ class Reader extends Filesystem implements ReaderInterface '/config/patterns' => 'patterns', '/config/patterns/pattern' => 'name', ]; - - /** - * XML Configuration file name - */ - private const XML_FILE_NAME = 'directory.xml'; - - /** - * Construct the FileSystem Reader Class - * - * @param \Magento\Framework\Config\FileResolverInterface $fileResolver - * @param Converter $converter - * @param SchemaLocator $schemaLocator - * @param \Magento\Framework\Config\ValidationStateInterface $validationState - * @param string $fileName - * @param array $idAttributes - * @param string $domDocumentClass - * @param string $defaultScope - */ - public function __construct( - FileResolverInterface $fileResolver, - Converter $converter, - SchemaLocator $schemaLocator, - ValidationStateInterface $validationState, - $fileName = self::XML_FILE_NAME, - $idAttributes = [], - $domDocumentClass = Dom::class, - $defaultScope = Area::AREA_GLOBAL - ) { - parent::__construct( - $fileResolver, - $converter, - $schemaLocator, - $validationState, - $fileName, - $idAttributes, - $domDocumentClass, - $defaultScope - ); - } } diff --git a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php index def5a0c817401..3ec50eaac4b9e 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php +++ b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php @@ -14,8 +14,6 @@ */ class IsBlacklisted implements IsBlacklistedInterface { - const XML_PATH_BLACKLIST_PATTERNS = 'blacklist/patterns'; - /** * @var Config */ @@ -37,7 +35,7 @@ public function __construct(Config $config) */ public function execute(string $path): bool { - foreach ($this->config->get(self::XML_PATH_BLACKLIST_PATTERNS) as $pattern) { + foreach ($this->config->getBlacklistPatterns() as $pattern) { if (empty($pattern)) { continue; } diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php index 8af26f0c64b16..16f5e4576d736 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php @@ -7,7 +7,6 @@ namespace Magento\MediaGallery\Test\Unit\Model\Asset\Command; -use Magento\Eav\Helper\Data; use Magento\MediaGallery\Model\Asset\Command\Save; use Magento\MediaGalleryApi\Api\Data\AssetInterface; use Magento\Framework\App\ResourceConnection; diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php index 4742db34cfcab..0871759087468 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php @@ -10,6 +10,7 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use PHPUnit\Framework\TestCase; use Magento\MediaGallery\Model\Directory\IsBlacklisted; +use Magento\MediaGallery\Model\Directory\Config; /** * Test the Excluded model @@ -21,20 +22,24 @@ class IsBlacklistedTest extends TestCase */ private $object; + /** + * @var + */ + private $config; + /** * Initialize basic test class mocks */ protected function setUp(): void { - $this->object = (new ObjectManager($this))->getObject( - IsBlacklisted::class, - [ - 'patterns' => [ - 'tmp' => '/pub\/media\/tmp/', - 'captcha' => '/pub\/media\/captcha/' - ] - ] - ); + $this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); + $this->config->expects($this->at(0))->method('getBlacklistPatterns')->willReturn([ + 'tmp' => '/pub\/media\/tmp/', + 'captcha' => '/pub\/media\/captcha/' + ]); + $this->object = (new ObjectManager($this))->getObject(IsBlacklisted::class, [ + 'config' => $this->config + ]); } /** From 2bd86096ca464ca5a2d9369c778981bc0f510e88 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 7 Apr 2020 23:18:55 -0500 Subject: [PATCH 14/35] - Fix unit test --- .../MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php index 16f5e4576d736..4340a77e0b39a 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php @@ -112,7 +112,7 @@ protected function setUp(): void Save::class, [ 'resourceConnection' => $this->resourceConnectionMock, - 'objectProcessor' => $this->objectProcessor, + 'objectProcessor' => $this->objectProcessor, 'logger' => $this->loggerMock ] ); From e69ee881fde34e5caff736b6a1364f24617115ee Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 7 Apr 2020 23:53:01 -0500 Subject: [PATCH 15/35] - Remove optional example attribute from xsd --- app/code/Magento/MediaGallery/etc/directory.xsd | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/MediaGallery/etc/directory.xsd b/app/code/Magento/MediaGallery/etc/directory.xsd index b9abd04ae1456..4c0b1120db304 100644 --- a/app/code/Magento/MediaGallery/etc/directory.xsd +++ b/app/code/Magento/MediaGallery/etc/directory.xsd @@ -31,7 +31,6 @@ - From 5aceeab83acb63ed233b4cdd028540c12c5cfd6d Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Wed, 8 Apr 2020 01:07:59 -0500 Subject: [PATCH 16/35] - Add rollback for media_asset fixture. - fix typo --- .../File/Command/DeleteByAssertIdTest.php | 4 ++-- .../_files/media_asset_rollback.php | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php index 7eb0d7a886e92..5acfb6170e155 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php @@ -14,7 +14,7 @@ use Magento\MediaGalleryApi\Model\Asset\Command\GetByIdInterface; /** - * Test methods of class DeleteByPath + * Test methods of class DeleteByAssertIdTest */ class DeleteByAssertIdTest extends \PHPUnit\Framework\TestCase { @@ -24,7 +24,7 @@ class DeleteByAssertIdTest extends \PHPUnit\Framework\TestCase private CONST TEST_DIRECTORY_NAME = 'testDirectory'; /** - * Absolute path to the media direcrory + * Absolute path to the media directory */ private static $_mediaPath; diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php new file mode 100644 index 0000000000000..5f26d9350775e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php @@ -0,0 +1,22 @@ +get(DeleteByPathInterface::class); + +try { + $mediaAssetDelete->execute('testDirectory/path.jpg'); +} catch (\Exception $exception) { + +} + From a8ba20347528ee7c951f48d4dc3d10810da9ac92 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Wed, 8 Apr 2020 13:08:57 +0100 Subject: [PATCH 17/35] magento/magento2#27499: Moved configuration xsd to MediaGalleryApi module --- .../MediaGallery/Model/Directory/Config.php | 2 +- .../Model/Directory/Config/Reader.php | 27 ------------- .../Model/Directory/Config/SchemaLocator.php | 2 +- .../Unit/Model/Asset/Command/SaveTest.php | 1 - app/code/Magento/MediaGallery/etc/di.xml | 7 +++- .../Magento/MediaGallery/etc/directory.xml | 2 +- .../etc/directory.xsd | 15 +++++++ .../Directory/Command/CreateByPathTest.php | 19 ++++----- .../Directory/Command/DeleteByPathTest.php | 40 +++++++------------ 9 files changed, 44 insertions(+), 71 deletions(-) delete mode 100644 app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php rename app/code/Magento/{MediaGallery => MediaGalleryApi}/etc/directory.xsd (68%) diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config.php b/app/code/Magento/MediaGallery/Model/Directory/Config.php index 3e47161f35c06..46314be9edfc1 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config.php @@ -48,6 +48,6 @@ public function get($key = null, $default = null) */ public function getBlacklistPatterns() : array { - return $this->data->get(self::XML_PATH_BLACKLIST_PATTERNS); + return $this->get(self::XML_PATH_BLACKLIST_PATTERNS); } } diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php b/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php deleted file mode 100644 index 85f61f712d580..0000000000000 --- a/app/code/Magento/MediaGallery/Model/Directory/Config/Reader.php +++ /dev/null @@ -1,27 +0,0 @@ - 'patterns', - '/config/patterns/pattern' => 'name', - ]; -} diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php b/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php index 6661b0d7e95ee..7fdf414cdd228 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config/SchemaLocator.php @@ -28,7 +28,7 @@ class SchemaLocator implements SchemaLocatorInterface */ public function __construct(Reader $moduleReader) { - $this->schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_MediaGallery') . '/directory.xsd'; + $this->schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_MediaGalleryApi') . '/directory.xsd'; } /** diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php index 4340a77e0b39a..8db0258fe3981 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php @@ -24,7 +24,6 @@ */ class SaveTest extends TestCase { - /** * Constant for tablename of media gallery assets */ diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index 11e63b710697e..bfbab191e68d3 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -34,13 +34,16 @@ - + directory.xml Magento\MediaGallery\Model\Directory\Config\Converter Magento\MediaGallery\Model\Directory\Config\SchemaLocator + + name + - + Magento\MediaGallery\Model\Directory\Config\Reader diff --git a/app/code/Magento/MediaGallery/etc/directory.xml b/app/code/Magento/MediaGallery/etc/directory.xml index 2eb37aa81ab42..c6da55482976e 100644 --- a/app/code/Magento/MediaGallery/etc/directory.xml +++ b/app/code/Magento/MediaGallery/etc/directory.xml @@ -5,7 +5,7 @@ * See COPYING.txt for license details. */ --> - + /^captcha/ diff --git a/app/code/Magento/MediaGallery/etc/directory.xsd b/app/code/Magento/MediaGalleryApi/etc/directory.xsd similarity index 68% rename from app/code/Magento/MediaGallery/etc/directory.xsd rename to app/code/Magento/MediaGalleryApi/etc/directory.xsd index 4c0b1120db304..51ca17809ab78 100644 --- a/app/code/Magento/MediaGallery/etc/directory.xsd +++ b/app/code/Magento/MediaGalleryApi/etc/directory.xsd @@ -16,18 +16,33 @@ + + + Blacklist used for excluding directories from media gallery rendering and operations + + + + + List of directory paths regexp patterns + + + + + Directory path regexp pattern + + diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php index 84861a5375713..ad28d180fb899 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php @@ -4,6 +4,8 @@ * See COPYING.txt for license details. * */ +declare(strict_types=1); + namespace Magento\MediaGallery\Model\Directory\Command; use Magento\Framework\App\Filesystem\DirectoryList; @@ -19,33 +21,26 @@ class CreateByPathTest extends \PHPUnit\Framework\TestCase /** * Test directory name */ - private CONST TEST_DIRECTORY_NAME = 'testCreateDirectory'; + private const TEST_DIRECTORY_NAME = 'testCreateDirectory'; /** * Absolute path to the media direcrory */ - private static $_mediaPath; + private $mediaDirectoryPath; /** * @var CreateByPathInterface */ private $createByPath; - /** - * @inheritdoc - */ - public static function setUpBeforeClass() - { - self::$_mediaPath = Bootstrap::getObjectManager()->get(Filesystem::class) - ->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath(); - } - /** * @inheritdoc */ public function setUp() { $this->createByPath = Bootstrap::getObjectManager()->create(CreateByPathInterface::class); + $this->mediaDirectoryPath = Bootstrap::getObjectManager()->get(Filesystem::class) + ->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath(); } /** @@ -54,7 +49,7 @@ public function setUp() */ public function testCreateDirectory(): void { - $fullPath = self::$_mediaPath . self::TEST_DIRECTORY_NAME; + $fullPath = $this->mediaDirectoryPath . self::TEST_DIRECTORY_NAME; $this->createByPath->execute('', self::TEST_DIRECTORY_NAME); $this->assertFileExists($fullPath); } diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php index 282dbe2ed11d0..01234db0241d7 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php @@ -4,6 +4,8 @@ * See COPYING.txt for license details. * */ +declare(strict_types=1); + namespace Magento\MediaGallery\Model\Directory\Command; use Magento\Framework\App\Filesystem\DirectoryList; @@ -16,31 +18,15 @@ */ class DeleteByPathTest extends \PHPUnit\Framework\TestCase { - /** - * Test directory name - */ - private CONST TEST_DIRECTORY_NAME = 'testDeleteDirectory'; - - /** - * Absolute path to the media direcrory - */ - private static $_mediaPath; - /** * @var DeleteByPathInterface */ private $deleteByPath; /** - * @inheritdoc + * @var string */ - public static function setUpBeforeClass() - { - /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */ - $directory = Bootstrap::getObjectManager()->get(Filesystem::class)->getDirectoryWrite(DirectoryList::MEDIA); - self::$_mediaPath = $directory->getAbsolutePath(); - $directory->create(self::TEST_DIRECTORY_NAME); - } + private $testDirectoryName = 'testDeleteDirectory'; /** * @inheritdoc @@ -51,19 +37,22 @@ public function setUp() } /** - * @return void * @throws \Magento\Framework\Exception\CouldNotDeleteException + * @throws \Magento\Framework\Exception\FileSystemException */ public function testDeleteDirectoryWithExistingDirectoryAndCorrectAbsolutePath(): void { - $fullPath = self::$_mediaPath . self::TEST_DIRECTORY_NAME; + /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */ + $mediaDirectory = Bootstrap::getObjectManager()->get(Filesystem::class) + ->getDirectoryRead(DirectoryList::MEDIA); + $mediaDirectory->create($this->testDirectoryName); + $fullPath = $mediaDirectory->getAbsolutePath($this->testDirectoryName); $this->assertFileExists($fullPath); - $this->deleteByPath->execute(self::TEST_DIRECTORY_NAME); + $this->deleteByPath->execute($this->testDirectoryName); $this->assertFileNotExists($fullPath); } /** - * @return void * @throws \Magento\Framework\Exception\CouldNotDeleteException * @expectedException \Magento\Framework\Exception\CouldNotDeleteException */ @@ -73,7 +62,6 @@ public function testDeleteDirectoryWithRelativePathUnderMediaFolder(): void } /** - * @return void * @throws \Magento\Framework\Exception\CouldNotDeleteException * @expectedException \Magento\Framework\Exception\CouldNotDeleteException */ @@ -85,14 +73,14 @@ public function testDeleteDirectoryThatIsNotAllowed(): void /** * @throws \Magento\Framework\Exception\FileSystemException */ - public static function tearDownAfterClass() + public function tearDown() { $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->get(\Magento\Framework\Filesystem::class); /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */ $directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); - if ($directory->isExist(self::TEST_DIRECTORY_NAME)) { - $directory->delete(self::TEST_DIRECTORY_NAME); + if ($directory->isExist($this->testDirectoryName)) { + $directory->delete($this->testDirectoryName); } } } From 9f4bafce862acdd6e406e73dc24ee8a6e293cebe Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Wed, 8 Apr 2020 21:58:44 +0100 Subject: [PATCH 18/35] magento/magento2#27499: MediaGallery bulk interfaces introduced --- .../Asset/Command/DeleteByDirectoryPath.php | 3 +- .../Model/Asset/Command/DeleteByPath.php | 1 + .../Model/Asset/Command/GetById.php | 1 + .../Model/Asset/Command/GetByPath.php | 3 +- .../MediaGallery/Model/Asset/Command/Save.php | 1 + .../MediaGallery/Model/AssetKeywords.php | 53 ++++++++ .../Model/Directory/Command/CreateByPath.php | 38 ++++-- .../Model/Directory/Command/DeleteByPath.php | 33 +++-- .../Model/Directory/IsBlacklisted.php | 4 +- .../Model/File/Command/DeleteByAssetId.php | 72 ---------- .../Magento/MediaGallery/Model/Keyword.php | 3 +- .../Keyword/Command/GetAssetKeywords.php | 1 + .../Keyword/Command/SaveAssetKeywords.php | 6 +- .../ResourceModel/DeleteAssetsByPaths.php | 100 ++++++++++++++ .../Model/ResourceModel/GetAssetsByIds.php | 80 +++++++++++ .../Model/ResourceModel/GetAssetsByPaths.php | 87 ++++++++++++ .../Keyword/GetAssetsKeywords.php | 128 ++++++++++++++++++ .../Keyword}/SaveAssetLinks.php | 15 +- .../Keyword/SaveAssetsKeywords.php | 128 ++++++++++++++++++ .../Model/ResourceModel/SaveAssets.php | 88 ++++++++++++ .../Keyword/Command/SaveAssetKeywordsTest.php | 2 +- .../Keyword/Command/SaveAssetLinksTest.php | 2 +- app/code/Magento/MediaGallery/etc/di.xml | 15 +- .../CreateDirectoriesByPathsInterface.php} | 9 +- .../Api/Data/AssetKeywordsInterface.php | 48 +++++++ .../Api/DeleteAssetsByPathsInterface.php | 24 ++++ .../DeleteDirectoriesByPathsInterface.php} | 8 +- .../Api/GetAssetsByIdsInterface.php | 25 ++++ .../Api/GetAssetsByPathsInterface.php | 24 ++++ .../Api/GetAssetsKeywordsInterface.php | 23 ++++ .../IsPathBlacklistedInterface.php} | 4 +- .../Api/SaveAssetsInterface.php | 26 ++++ .../Api/SaveAssetsKeywordsInterface.php | 23 ++++ .../DeleteByDirectoryPathInterface.php | 2 +- .../Asset/Command/DeleteByPathInterface.php | 2 +- .../Model/Asset/Command/GetByIdInterface.php | 2 +- .../Asset/Command/GetByPathInterface.php | 2 +- .../Model/Asset/Command/SaveInterface.php | 2 +- .../File/Command/DeleteByAssetIdInterface.php | 24 ---- .../Command/GetAssetKeywordsInterface.php | 2 +- .../Command/SaveAssetKeywordsInterface.php | 2 +- .../Directory/Command/CreateByPathTest.php | 2 +- 42 files changed, 954 insertions(+), 164 deletions(-) create mode 100644 app/code/Magento/MediaGallery/Model/AssetKeywords.php delete mode 100644 app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php create mode 100644 app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php create mode 100644 app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php create mode 100644 app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php create mode 100644 app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php rename app/code/Magento/MediaGallery/Model/{Keyword/Command => ResourceModel/Keyword}/SaveAssetLinks.php (84%) create mode 100644 app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetsKeywords.php create mode 100644 app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php rename app/code/Magento/MediaGalleryApi/{Model/Directory/Command/CreateByPathInterface.php => Api/CreateDirectoriesByPathsInterface.php} (60%) create mode 100644 app/code/Magento/MediaGalleryApi/Api/Data/AssetKeywordsInterface.php create mode 100644 app/code/Magento/MediaGalleryApi/Api/DeleteAssetsByPathsInterface.php rename app/code/Magento/MediaGalleryApi/{Model/Directory/Command/DeleteByPathInterface.php => Api/DeleteDirectoriesByPathsInterface.php} (65%) create mode 100644 app/code/Magento/MediaGalleryApi/Api/GetAssetsByIdsInterface.php create mode 100644 app/code/Magento/MediaGalleryApi/Api/GetAssetsByPathsInterface.php create mode 100644 app/code/Magento/MediaGalleryApi/Api/GetAssetsKeywordsInterface.php rename app/code/Magento/MediaGalleryApi/{Model/Directory/IsBlacklistedInterface.php => Api/IsPathBlacklistedInterface.php} (84%) create mode 100644 app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php create mode 100644 app/code/Magento/MediaGalleryApi/Api/SaveAssetsKeywordsInterface.php delete mode 100644 app/code/Magento/MediaGalleryApi/Model/File/Command/DeleteByAssetIdInterface.php diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByDirectoryPath.php b/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByDirectoryPath.php index a50095fb3d8e7..8487a9cbb46db 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByDirectoryPath.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByDirectoryPath.php @@ -14,9 +14,8 @@ use Psr\Log\LoggerInterface; /** - * Class DeleteByDirectoryPath - * * Remove asset(s) that correspond the provided directory path + * @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead */ class DeleteByDirectoryPath implements DeleteByDirectoryPathInterface { diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php b/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php index c05a08149bfca..eaf47b467e3a9 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php @@ -15,6 +15,7 @@ /** * Class DeleteByPath + * @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead */ class DeleteByPath implements DeleteByPathInterface { diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php index 4475d5570c988..9826ef7725023 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php @@ -17,6 +17,7 @@ /** * Get media asset by id + * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface instead */ class GetById implements GetByIdInterface { diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php index 32c7323c3a511..bebb7ea91c481 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php @@ -16,7 +16,8 @@ use Psr\Log\LoggerInterface; /** - * Class GetListByIds + * Class GetByPath + * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByPathInterface instead */ class GetByPath implements GetByPathInterface { diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php index e017c4c58eb63..5d84b3ae29c80 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php @@ -16,6 +16,7 @@ /** * Class Save + * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetInterface instead */ class Save implements SaveInterface { diff --git a/app/code/Magento/MediaGallery/Model/AssetKeywords.php b/app/code/Magento/MediaGallery/Model/AssetKeywords.php new file mode 100644 index 0000000000000..95a060fccffcd --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/AssetKeywords.php @@ -0,0 +1,53 @@ +getData(self::ASSET_ID); + } + + /** + * @inheritdoc + */ + public function getKeywords(): array + { + return $this->getData(self::KEYWORDS); + } + + /** + * @inheritdoc + */ + public function getExtensionAttributes(): AssetKeywordsExtensionInterface + { + return $this->_getExtensionAttributes(); + } + + /** + * @inheritdoc + */ + public function setExtensionAttributes(AssetKeywordsExtensionInterface $extensionAttributes): void + { + $this->_setExtensionAttributes($extensionAttributes); + } +} diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php index c70f71df02a39..b85a9cf30ef51 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php @@ -9,13 +9,13 @@ use Magento\Cms\Model\Wysiwyg\Images\Storage; use Magento\Framework\Exception\CouldNotSaveException; -use Magento\MediaGalleryApi\Model\Directory\Command\CreateByPathInterface; +use Magento\MediaGalleryApi\Api\CreateDirectoriesByPathsInterface; use Psr\Log\LoggerInterface; /** * Create folder by provided path */ -class CreateByPath implements CreateByPathInterface +class CreateByPath implements CreateDirectoriesByPathsInterface { /** * @var LoggerInterface @@ -40,19 +40,31 @@ public function __construct( } /** - * Create new directory by the provided path in the media storage - * - * @param string $path - * @param string $name - * @throws CouldNotSaveException + * @inheritdoc */ - public function execute(string $path, string $name): void + public function execute(array $paths): void { - try { - $this->storage->createDirectory($name, $this->storage->getCmsWysiwygImages()->getStorageRoot() . $path); - } catch (\Exception $exception) { - $this->logger->critical($exception); - throw new CouldNotSaveException(__('Failed to create the folder'), $exception); + $failedPaths = []; + foreach ($paths as $path) { + try { + $name = end(explode('/', $path)); + $this->storage->createDirectory( + $name, + $this->storage->getCmsWysiwygImages()->getStorageRoot() . $path + ); + } catch (\Exception $exception) { + $this->logger->critical($exception); + $failedPaths[] = $path; + } + } + + if (!empty($failedPaths)) { + throw new CouldNotSaveException( + __( + 'Could not save directories: %paths', + implode(' ,', $failedPaths) + ) + ); } } } diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php index 73f0e08add751..c6b2f396e364e 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php @@ -9,13 +9,13 @@ use Magento\Cms\Model\Wysiwyg\Images\Storage; use Magento\Framework\Exception\CouldNotDeleteException; -use Magento\MediaGalleryApi\Model\Directory\Command\DeleteByPathInterface; +use Magento\MediaGalleryApi\Api\DeleteDirectoriesByPathsInterface; use Psr\Log\LoggerInterface; /** * Delete directory from media storage by path */ -class DeleteByPath implements DeleteByPathInterface +class DeleteByPath implements DeleteDirectoriesByPathsInterface { /** * @var LoggerInterface @@ -40,18 +40,27 @@ public function __construct( } /** - * Removes directory and corresponding thumbnails directory from media storage if not in blacklist - * - * @param string $path - * @throws CouldNotDeleteException + * @inheritdoc */ - public function execute(string $path): void + public function execute(array $paths): void { - try { - $this->storage->deleteDirectory($this->storage->getCmsWysiwygImages()->getStorageRoot() . $path); - } catch (\Exception $exception) { - $this->logger->critical($exception); - throw new CouldNotDeleteException(__('Failed to delete the folder'), $exception); + $failedPaths = []; + foreach ($paths as $path) { + 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', + implode(' ,', $failedPaths) + ) + ); } } } diff --git a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php index 3ec50eaac4b9e..d2e59b5613b4a 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php +++ b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php @@ -7,12 +7,12 @@ namespace Magento\MediaGallery\Model\Directory; -use Magento\MediaGalleryApi\Model\Directory\IsBlacklistedInterface; +use Magento\MediaGalleryApi\Api\IsPathBlacklistedInterface; /** * Check if the path is blacklisted for media gallery. Directory path may be blacklisted if it's reserved by the system */ -class IsBlacklisted implements IsBlacklistedInterface +class IsBlacklisted implements IsPathBlacklistedInterface { /** * @var Config diff --git a/app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php b/app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php deleted file mode 100644 index dff91e73c8c7a..0000000000000 --- a/app/code/Magento/MediaGallery/Model/File/Command/DeleteByAssetId.php +++ /dev/null @@ -1,72 +0,0 @@ -getAssetById = $getAssetById; - $this->imagesStorage = $imagesStorage; - $this->filesystem = $filesystem; - } - - /** - * Delete image by asset ID - * - * @param int $assetId - * @return void - * @throws LocalizedException - */ - public function execute(int $assetId): void - { - $mediaFilePath = $this->getAssetById->execute($assetId)->getPath(); - $mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); - - if (!$mediaDirectory->isFile($mediaFilePath)) { - throw new LocalizedException(__('File "%1" does not exist in media directory.', $mediaFilePath)); - } - - $this->imagesStorage->deleteFile($mediaDirectory->getAbsolutePath() . $mediaFilePath); - } -} diff --git a/app/code/Magento/MediaGallery/Model/Keyword.php b/app/code/Magento/MediaGallery/Model/Keyword.php index c5c60d3152846..18600af0dfc6c 100644 --- a/app/code/Magento/MediaGallery/Model/Keyword.php +++ b/app/code/Magento/MediaGallery/Model/Keyword.php @@ -18,7 +18,6 @@ class Keyword extends AbstractExtensibleModel implements KeywordInterface { private const ID = 'id'; - private const KEYWORD = 'keyword'; /** @@ -40,7 +39,7 @@ public function getId(): ?int */ public function getKeyword(): string { - return (string)$this->getData(self::KEYWORD); + return (string) $this->getData(self::KEYWORD); } /** diff --git a/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php b/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php index 6cd8bd2463a2c..4112b717c24a2 100644 --- a/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php +++ b/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php @@ -16,6 +16,7 @@ /** * Retrieve keywords for the media asset + * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface instead */ class GetAssetKeywords implements GetAssetKeywordsInterface { diff --git a/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php b/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php index b355a9a651cd4..748b1e0d2463a 100644 --- a/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php +++ b/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php @@ -7,16 +7,18 @@ namespace Magento\MediaGallery\Model\Keyword\Command; -use Magento\MediaGalleryApi\Api\Data\KeywordInterface; -use Magento\MediaGalleryApi\Model\Keyword\Command\SaveAssetKeywordsInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Adapter\Pdo\Mysql; use Magento\Framework\Exception\CouldNotSaveException; +use Magento\MediaGallery\Model\ResourceModel\Keyword\SaveAssetLinks; +use Magento\MediaGalleryApi\Api\Data\KeywordInterface; +use Magento\MediaGalleryApi\Model\Keyword\Command\SaveAssetKeywordsInterface; use Psr\Log\LoggerInterface; /** * Class SaveAssetKeywords + * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetKeywordsInterface instead */ class SaveAssetKeywords implements SaveAssetKeywordsInterface { diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php b/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php new file mode 100644 index 0000000000000..c263b3937e0d2 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php @@ -0,0 +1,100 @@ +resourceConnection = $resourceConnection; + $this->logger = $logger; + } + + /** + * @inheritdoc + */ + public function execute(array $paths): void + { + $failedPaths = []; + + foreach ($paths as $path) { + try { + $this->validateDirectoryPath($path); + $this->deleteAssetsByDirectoryPath($path); + } catch (\Exception $exception) { + $this->logger->critical($exception); + $failedPaths[] = $path; + } + } + + if (!empty($failedPaths)) { + throw new CouldNotDeleteException( + __( + 'Could not delete media assets by paths: %paths', + [ + 'paths' => implode(' ,', $failedPaths) + ] + ) + ); + } + } + + private function deleteAssetsByDirectoryPath(string $path) + { + // Make sure that the path has a trailing slash + $path = rtrim($path, '/') . '/'; + + /** @var AdapterInterface $connection */ + $connection = $this->resourceConnection->getConnection(); + $tableName = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET); + $connection->delete($tableName, [self::MEDIA_GALLERY_ASSET_PATH . ' LIKE ?' => $path . '%']); + } + + /** + * Validate the directory path + * + * @param string $path + * @throws CouldNotDeleteException + */ + private function validateDirectoryPath(string $path): void + { + if (!$path || trim($path) === '') { + throw new CouldNotDeleteException(__('Cannot remove assets, the directory path does not exist')); + } + } +} diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php new file mode 100644 index 0000000000000..ec3183e481370 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php @@ -0,0 +1,80 @@ +resourceConnection = $resourceConnection; + $this->assetFactory = $assetFactory; + $this->logger = $logger; + } + + /** + * @inheritdoc + */ + public function execute(array $ids): array + { + try { + $mediaAssetTable = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET); + $connection = $this->resourceConnection->getConnection(); + $select = $connection->select() + ->from(['amg' => $mediaAssetTable]) + ->where('amg.id IN (?)', $ids); + $assetsData = $connection->query($select)->fetchAll(); + } catch (\Exception $exception) { + $this->logger->critical($exception); + throw new LocalizedException(__('Could not retrieve media assets'), $exception); + } + + $assets = []; + + foreach ($assetsData as $assetData) { + $assets[] = $this->assetFactory->create(['data' => $assetData]); + } + + return $assets; + } +} diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php new file mode 100644 index 0000000000000..78aa5fe471df9 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php @@ -0,0 +1,87 @@ +resourceConnection = $resourceConnection; + $this->mediaAssetFactory = $mediaAssetFactory; + $this->logger = $logger; + } + + /** + * @inheritdoc + */ + public function execute(array $paths): array + { + try { + $connection = $this->resourceConnection->getConnection(); + $select = $connection->select() + ->from($this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET)) + ->where(self::MEDIA_GALLERY_ASSET_PATH . ' IN (?)', $paths); + $assetsData = $connection->query($select)->fetchAll(); + } catch (\Exception $exception) { + $this->logger->critical($exception); + throw new LocalizedException( + __( + 'Could not get media assets for paths: %paths', + [ + 'paths' => implode(' ,', $paths) + ] + ) + ); + } + + $assets = []; + + foreach ($assetsData as $assetData) { + $assets[] = $this->mediaAssetFactory->create(['data' => $assetData]); + } + + return $assets; + } +} diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php new file mode 100644 index 0000000000000..a83c6e28b2d94 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php @@ -0,0 +1,128 @@ +assetKeywordsFactory = $assetKeywordsFactory; + $this->resourceConnection = $resourceConnection; + $this->keywordFactory = $keywordFactory; + $this->logger = $logger; + } + + /** + * @inheritdoc + */ + public function execute(array $assetIds): array + { + try { + $this->getAssetKeywords($this->getKeywordsData($assetIds)); + } catch (\Exception $exception) { + $this->logger->critical($exception); + $message = __('An error occurred during get asset keywords: %1', $exception->getMessage()); + throw new IntegrationException($message, $exception); + } + } + + /** + * Load keywords data + * + * @param array $assetIds + * @return array + * @throws \Zend_Db_Statement_Exception + */ + private function getKeywordsData(array $assetIds): array + { + $connection = $this->resourceConnection->getConnection(); + $select = $connection->select() + ->from(['k' => $this->resourceConnection->getTableName(self::TABLE_KEYWORD)]) + ->join(['ak' => self::TABLE_ASSET_KEYWORD], 'k.id = ak.keyword_id') + ->where('ak.asset_id IN (?)', $assetIds); + return $connection->query($select)->fetchAll(); + } + + /** + * Build AssetKeywords objects array + * + * @param array $keywordsData + * @return AssetKeywordsInterface[] + */ + private function getAssetKeywords(array $keywordsData): array + { + $keywordsByAsset = []; + foreach ($keywordsData as $keywordData) { + $keywordsByAsset[$keywordData[self::FIELD_ASSET_ID]][] = $this->keywordFactory->create( + [ + 'data' => $keywordData + ] + ); + } + + $assetKeywords = []; + foreach ($keywordsByAsset as $assetId => $keywords) { + $assetKeywords[] = $this->assetKeywordsFactory->create( + [ + 'data' => [ + 'asset_id' => $assetId, + 'keywords' => $keywords + ] + ] + ); + } + + return $assetKeywords; + } +} diff --git a/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetLinks.php b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetLinks.php similarity index 84% rename from app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetLinks.php rename to app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetLinks.php index 4d3fd2bb5c30d..3437cc1c519e8 100644 --- a/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetLinks.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetLinks.php @@ -5,18 +5,17 @@ */ declare(strict_types=1); -namespace Magento\MediaGallery\Model\Keyword\Command; +namespace Magento\MediaGallery\Model\ResourceModel\Keyword; -use Magento\MediaGalleryApi\Api\Data\KeywordInterface; -use Magento\MediaGalleryApi\Model\Keyword\Command\SaveAssetLinksInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Adapter\Pdo\Mysql; use Magento\Framework\Exception\CouldNotSaveException; +use Magento\MediaGalleryApi\Api\Data\KeywordInterface; use Psr\Log\LoggerInterface; /** - * Class SaveAssetLinks + * Save links between asset and keyword to media_gallery_asset_keyword table */ class SaveAssetLinks { @@ -35,8 +34,6 @@ class SaveAssetLinks private $logger; /** - * SaveAssetLinks constructor. - * * @param ResourceConnection $resourceConnection * @param LoggerInterface $logger */ @@ -76,8 +73,10 @@ public function execute(int $assetId, array $keywordIds): void } } catch (\Exception $exception) { $this->logger->critical($exception); - $message = __('An error occurred during save asset keyword links: %1', $exception->getMessage()); - throw new CouldNotSaveException($message, $exception); + throw new CouldNotSaveException( + __('Could not save asset keyword links'), + $exception + ); } } } diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetsKeywords.php b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetsKeywords.php new file mode 100644 index 0000000000000..cb64c3173dfc9 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetsKeywords.php @@ -0,0 +1,128 @@ +resourceConnection = $resourceConnection; + $this->saveAssetLinks = $saveAssetLinks; + $this->logger = $logger; + } + + /** + * @inheritdoc + */ + public function execute(array $assetKeywords): void + { + $failedAssetIds = []; + foreach ($assetKeywords as $assetKeyword) { + try { + $this->saveAssetKeywords($assetKeyword->getKeywords(), $assetKeyword->getAssetId()); + } catch (\Exception $exception) { + $this->logger->critical($exception); + $failedAssetIds[] = $assetKeyword->getAssetId(); + } + } + + if (!empty($failedAssetIds)) { + throw new CouldNotSaveException( + __('Could not save keywords for asset ids: %ids', ['ids' => implode(' ,', $failedAssetIds)]) + ); + } + } + + /** + * Save asset keywords. + * + * @param KeywordInterface[] $keywords + * @param int $assetId + * @throws CouldNotSaveException + * @throws \Zend_Db_Exception + */ + private function saveAssetKeywords(array $keywords, int $assetId): void + { + $data = []; + foreach ($keywords as $keyword) { + $data[] = $keyword->getKeyword(); + } + + if (empty($data)) { + return; + } + + /** @var Mysql $connection */ + $connection = $this->resourceConnection->getConnection(); + $connection->insertArray( + $this->resourceConnection->getTableName(self::TABLE_KEYWORD), + [self::KEYWORD], + $data, + AdapterInterface::INSERT_IGNORE + ); + + $this->saveAssetLinks->execute($assetId, $this->getKeywordIds($data)); + } + + /** + * Select keywords by names + * + * @param string[] $keywords + * @return int[] + */ + private function getKeywordIds(array $keywords): array + { + $connection = $this->resourceConnection->getConnection(); + $select = $connection->select() + ->from(['k' => $this->resourceConnection->getTableName(self::TABLE_KEYWORD)]) + ->columns(self::ID) + ->where('k.' . self::KEYWORD . ' in (?)', $keywords); + + return $connection->fetchCol($select); + } +} diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php b/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php new file mode 100644 index 0000000000000..e75acca66d0f4 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php @@ -0,0 +1,88 @@ +resourceConnection = $resourceConnection; + $this->objectProcessor = $objectProcessor; + $this->logger = $logger; + } + + /** + * @inheritdoc + */ + public function execute(array $assets): void + { + $connection = $this->resourceConnection->getConnection(); + $tableName = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET); + + $failedAssets = []; + foreach ($assets as $asset) { + try { + $connection->insertOnDuplicate( + $tableName, + array_filter($this->objectProcessor->buildOutputDataArray($asset, AssetInterface::class)) + ); + } catch (\Exception $exception) { + $this->logger->critical($exception); + $failedAssets[] = $asset; + } + } + + if (!empty($failedAssets)) { + throw new CouldNotSaveException( + __( + 'Could not save the media assets: %assets', + [ + 'assets' => $failedAssets + ] + ) + ); + } + } +} diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetKeywordsTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetKeywordsTest.php index a55c60024c08d..031213b873a25 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetKeywordsTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetKeywordsTest.php @@ -13,7 +13,7 @@ use Magento\Framework\DB\Select; use Magento\Framework\Exception\CouldNotSaveException; use Magento\MediaGallery\Model\Keyword\Command\SaveAssetKeywords; -use Magento\MediaGallery\Model\Keyword\Command\SaveAssetLinks; +use Magento\MediaGallery\Model\ResourceModel\Keyword\SaveAssetLinks; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetLinksTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetLinksTest.php index 2981c534586e2..e029ae585169c 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetLinksTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetLinksTest.php @@ -7,10 +7,10 @@ namespace Magento\MediaGallery\Test\Unit\Model\Keyword\Command; -use Magento\MediaGallery\Model\Keyword\Command\SaveAssetLinks; use Magento\Framework\App\ResourceConnection; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\Exception\CouldNotSaveException; +use Magento\MediaGallery\Model\ResourceModel\Keyword\SaveAssetLinks; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index bfbab191e68d3..25f4850427929 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -8,6 +8,7 @@ + @@ -17,14 +18,18 @@ - - - + + - + - + + + + + + createByPath = Bootstrap::getObjectManager()->create(CreateByPathInterface::class); + $this->createByPath = Bootstrap::getObjectManager()->get(CreateByPathInterface::class); $this->mediaDirectoryPath = Bootstrap::getObjectManager()->get(Filesystem::class) ->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath(); } From 9106468b2f4a714a51ca43bafa714ae7e785277a Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Thu, 9 Apr 2020 11:17:22 +0100 Subject: [PATCH 19/35] magento/magento2#27499: Extracted MediaGalleryCatalog module --- app/code/Magento/MediaGallery/composer.json | 3 +- app/code/Magento/MediaGallery/etc/di.xml | 4 -- .../Magento/MediaGallery/etc/directory.xml | 1 - .../Magento/MediaGalleryCatalog/LICENSE.txt | 48 +++++++++++++++++++ .../MediaGalleryCatalog/LICENSE_AFL.txt | 48 +++++++++++++++++++ .../Plugin/Product/Gallery/Processor.php | 20 ++++---- .../Magento/MediaGalleryCatalog/README.md | 17 +++++++ .../Plugin/Product/Gallery/ProcessorTest.php | 9 ++-- .../Magento/MediaGalleryCatalog/composer.json | 23 +++++++++ .../Magento/MediaGalleryCatalog/etc/di.xml | 13 +++++ .../MediaGalleryCatalog/etc/directory.xml | 14 ++++++ .../MediaGalleryCatalog/etc/module.xml | 10 ++++ .../MediaGalleryCatalog/registration.php | 9 ++++ 13 files changed, 196 insertions(+), 23 deletions(-) create mode 100644 app/code/Magento/MediaGalleryCatalog/LICENSE.txt create mode 100644 app/code/Magento/MediaGalleryCatalog/LICENSE_AFL.txt rename app/code/Magento/{MediaGallery => MediaGalleryCatalog}/Plugin/Product/Gallery/Processor.php (70%) create mode 100644 app/code/Magento/MediaGalleryCatalog/README.md rename app/code/Magento/{MediaGallery => MediaGalleryCatalog}/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php (94%) create mode 100644 app/code/Magento/MediaGalleryCatalog/composer.json create mode 100644 app/code/Magento/MediaGalleryCatalog/etc/di.xml create mode 100644 app/code/Magento/MediaGalleryCatalog/etc/directory.xml create mode 100644 app/code/Magento/MediaGalleryCatalog/etc/module.xml create mode 100644 app/code/Magento/MediaGalleryCatalog/registration.php diff --git a/app/code/Magento/MediaGallery/composer.json b/app/code/Magento/MediaGallery/composer.json index 977277d993061..686cec00b7f55 100644 --- a/app/code/Magento/MediaGallery/composer.json +++ b/app/code/Magento/MediaGallery/composer.json @@ -5,8 +5,7 @@ "php": "~7.1.3||~7.2.0||~7.3.0", "magento/framework": "*", "magento/module-media-gallery-api": "*", - "magento/module-cms": "*", - "magento/module-catalog": "*" + "magento/module-cms": "*" }, "type": "magento2-module", "license": [ diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index 25f4850427929..ab49d5fa3b25e 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -31,10 +31,6 @@ - - - diff --git a/app/code/Magento/MediaGallery/etc/directory.xml b/app/code/Magento/MediaGallery/etc/directory.xml index c6da55482976e..92f50b2dd0a30 100644 --- a/app/code/Magento/MediaGallery/etc/directory.xml +++ b/app/code/Magento/MediaGallery/etc/directory.xml @@ -9,7 +9,6 @@ /^captcha/ - /^catalog\/product/ /^customer/ /^downloadable/ /^import/ diff --git a/app/code/Magento/MediaGalleryCatalog/LICENSE.txt b/app/code/Magento/MediaGalleryCatalog/LICENSE.txt new file mode 100644 index 0000000000000..49525fd99da9c --- /dev/null +++ b/app/code/Magento/MediaGalleryCatalog/LICENSE.txt @@ -0,0 +1,48 @@ + +Open Software License ("OSL") v. 3.0 + +This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Open Software License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/MediaGalleryCatalog/LICENSE_AFL.txt b/app/code/Magento/MediaGalleryCatalog/LICENSE_AFL.txt new file mode 100644 index 0000000000000..f39d641b18a19 --- /dev/null +++ b/app/code/Magento/MediaGalleryCatalog/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/MediaGallery/Plugin/Product/Gallery/Processor.php b/app/code/Magento/MediaGalleryCatalog/Plugin/Product/Gallery/Processor.php similarity index 70% rename from app/code/Magento/MediaGallery/Plugin/Product/Gallery/Processor.php rename to app/code/Magento/MediaGalleryCatalog/Plugin/Product/Gallery/Processor.php index 3fbe4e3a91a2b..c595d43009dd4 100644 --- a/app/code/Magento/MediaGallery/Plugin/Product/Gallery/Processor.php +++ b/app/code/Magento/MediaGalleryCatalog/Plugin/Product/Gallery/Processor.php @@ -3,25 +3,24 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); -namespace Magento\MediaGallery\Plugin\Product\Gallery; +namespace Magento\MediaGalleryCatalog\Plugin\Product\Gallery; -use Magento\MediaGalleryApi\Model\Asset\Command\DeleteByPathInterface; +use Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface; use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Gallery\Processor as ProcessorSubject; use Psr\Log\LoggerInterface; /** - * Ensures that metadata is removed from the database when a product image has been deleted. + * Ensures that metadata is removed from the database when an image has been deleted (from legacy media gallery) */ class Processor { /** - * @var DeleteByPathInterface + * @var DeleteAssetsByPathsInterface */ - private $deleteMediaAssetByPath; + private $deleteByPaths; /** * @var LoggerInterface @@ -31,14 +30,14 @@ class Processor /** * Processor constructor. * - * @param DeleteByPathInterface $deleteMediaAssetByPath + * @param DeleteAssetsByPathsInterface $deleteByPaths * @param LoggerInterface $logger */ public function __construct( - DeleteByPathInterface $deleteMediaAssetByPath, + DeleteAssetsByPathsInterface $deleteByPaths, LoggerInterface $logger ) { - $this->deleteMediaAssetByPath = $deleteMediaAssetByPath; + $this->deleteByPaths = $deleteByPaths; $this->logger = $logger; } @@ -49,7 +48,6 @@ public function __construct( * @param ProcessorSubject $result * @param Product $product * @param string $file - * * @return ProcessorSubject * * @SuppressWarnings(PHPMD.UnusedFormalParameter) @@ -65,7 +63,7 @@ public function afterRemoveImage( } try { - $this->deleteMediaAssetByPath->execute($file); + $this->deleteByPaths->execute([$file]); } catch (\Exception $exception) { $this->logger->critical($exception); } diff --git a/app/code/Magento/MediaGalleryCatalog/README.md b/app/code/Magento/MediaGalleryCatalog/README.md new file mode 100644 index 0000000000000..b39b1fae756d5 --- /dev/null +++ b/app/code/Magento/MediaGalleryCatalog/README.md @@ -0,0 +1,17 @@ +# Magento_MediaGalleryCatalog module + +The Magento_MediaGalleryCatalog module is responsible for for catalog gallery processor delete operation handling + +## Installation details + +For information about module installation in Magento 2, see [Enable or disable modules](https://devdocs.magento.com/guides/v2.3/install-gde/install/cli/install-cli-subcommands-enable.html). + +## Extensibility + +Extension developers can interact with the Magento_MediaGallery module. For more information about the Magento extension mechanism, see [Magento plug-ins](https://devdocs.magento.com/guides/v2.3/extension-dev-guide/plugins.html). + +[The Magento dependency injection mechanism](https://devdocs.magento.com/guides/v2.3/extension-dev-guide/depend-inj.html) enables you to override the functionality of the Magento_MediaGallery module. + +## Additional information + +For information about significant changes in patch releases, see [2.3.x Release information](https://devdocs.magento.com/guides/v2.3/release-notes/bk-release-notes.html). diff --git a/app/code/Magento/MediaGallery/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php b/app/code/Magento/MediaGalleryCatalog/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php similarity index 94% rename from app/code/Magento/MediaGallery/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php rename to app/code/Magento/MediaGalleryCatalog/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php index 94c3aaf5c2f19..c16150cbb3ad1 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php +++ b/app/code/Magento/MediaGalleryCatalog/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php @@ -3,16 +3,15 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); -namespace Magento\MediaGallery\Test\Unit\Plugin\Product\Gallery; +namespace Magento\MediaGalleryCatalog\Test\Unit\Plugin\Product\Gallery; use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Gallery\Processor as ProcessorSubject; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\MediaGallery\Plugin\Product\Gallery\Processor; -use Magento\MediaGalleryApi\Model\Asset\Command\DeleteByPathInterface; +use Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; @@ -25,7 +24,7 @@ class ProcessorTest extends TestCase private const STUB_FILE_NAME = 'file'; /** - * @var DeleteByPathInterface|MockObject + * @var DeleteAssetsByPathsInterface|MockObject */ private $deleteMediaAssetByPathMock; @@ -57,7 +56,7 @@ protected function setUp() $this->processorSubjectMock = $this->createMock(ProcessorSubject::class); $this->productMock = $this->createMock(Product::class); - $this->deleteMediaAssetByPathMock = $this->getMockBuilder(DeleteByPathInterface::class) + $this->deleteMediaAssetByPathMock = $this->getMockBuilder(DeleteAssetsByPathsInterface::class) ->disableOriginalConstructor() ->setMethods(['execute']) ->getMockForAbstractClass(); diff --git a/app/code/Magento/MediaGalleryCatalog/composer.json b/app/code/Magento/MediaGalleryCatalog/composer.json new file mode 100644 index 0000000000000..8152fb5aac8bb --- /dev/null +++ b/app/code/Magento/MediaGalleryCatalog/composer.json @@ -0,0 +1,23 @@ +{ + "name": "magento/module-media-gallery", + "description": "Magento module responsible for catalog gallery processor delete operation handling", + "require": { + "php": "~7.1.3||~7.2.0||~7.3.0", + "magento/framework": "*", + "magento/module-media-gallery-api": "*", + "magento/module-catalog": "*" + }, + "type": "magento2-module", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\MediaGalleryCatalog\\": "" + } + } +} diff --git a/app/code/Magento/MediaGalleryCatalog/etc/di.xml b/app/code/Magento/MediaGalleryCatalog/etc/di.xml new file mode 100644 index 0000000000000..41dfeaf14aace --- /dev/null +++ b/app/code/Magento/MediaGalleryCatalog/etc/di.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/app/code/Magento/MediaGalleryCatalog/etc/directory.xml b/app/code/Magento/MediaGalleryCatalog/etc/directory.xml new file mode 100644 index 0000000000000..eaced3f642f70 --- /dev/null +++ b/app/code/Magento/MediaGalleryCatalog/etc/directory.xml @@ -0,0 +1,14 @@ + + + + + + /^catalog\/product/ + + + diff --git a/app/code/Magento/MediaGalleryCatalog/etc/module.xml b/app/code/Magento/MediaGalleryCatalog/etc/module.xml new file mode 100644 index 0000000000000..83f60ded3d35a --- /dev/null +++ b/app/code/Magento/MediaGalleryCatalog/etc/module.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/app/code/Magento/MediaGalleryCatalog/registration.php b/app/code/Magento/MediaGalleryCatalog/registration.php new file mode 100644 index 0000000000000..3c24d0c298f38 --- /dev/null +++ b/app/code/Magento/MediaGalleryCatalog/registration.php @@ -0,0 +1,9 @@ + Date: Thu, 9 Apr 2020 11:55:07 +0100 Subject: [PATCH 20/35] magento/magento2#27499: Corrected services implementation --- .../{CreateByPath.php => CreateByPaths.php} | 2 +- .../{DeleteByPath.php => DeleteByPaths.php} | 2 +- .../ResourceModel/DeleteAssetsByPaths.php | 7 +++- .../Model/ResourceModel/GetAssetsByIds.php | 34 ++++++++++++------- .../Model/ResourceModel/GetAssetsByPaths.php | 32 ++++++++++------- .../Model/ResourceModel/SaveAssets.php | 2 +- .../Plugin/Wysiwyg/Images/Storage.php | 17 +++++++--- app/code/Magento/MediaGallery/etc/di.xml | 4 +-- 8 files changed, 65 insertions(+), 35 deletions(-) rename app/code/Magento/MediaGallery/Model/Directory/Command/{CreateByPath.php => CreateByPaths.php} (96%) rename app/code/Magento/MediaGallery/Model/Directory/Command/{DeleteByPath.php => DeleteByPaths.php} (95%) diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php similarity index 96% rename from app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php rename to app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php index b85a9cf30ef51..a6b09ed8cda62 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPath.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php @@ -15,7 +15,7 @@ /** * Create folder by provided path */ -class CreateByPath implements CreateDirectoriesByPathsInterface +class CreateByPaths implements CreateDirectoriesByPathsInterface { /** * @var LoggerInterface diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php similarity index 95% rename from app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php rename to app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php index c6b2f396e364e..9be25574822ae 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPath.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php @@ -15,7 +15,7 @@ /** * Delete directory from media storage by path */ -class DeleteByPath implements DeleteDirectoriesByPathsInterface +class DeleteByPaths implements DeleteDirectoriesByPathsInterface { /** * @var LoggerInterface diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php b/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php index c263b3937e0d2..d965ed63de5fd 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php @@ -74,7 +74,12 @@ public function execute(array $paths): void } } - private function deleteAssetsByDirectoryPath(string $path) + /** + * Delete assets from database based on the first part (beginning) of the path + * + * @param string $path + */ + private function deleteAssetsByDirectoryPath(string $path): void { // Make sure that the path has a trailing slash $path = rtrim($path, '/') . '/'; diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php index ec3183e481370..89daded071c33 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php @@ -57,24 +57,32 @@ public function __construct( */ public function execute(array $ids): array { + $assets = []; try { - $mediaAssetTable = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET); - $connection = $this->resourceConnection->getConnection(); - $select = $connection->select() - ->from(['amg' => $mediaAssetTable]) - ->where('amg.id IN (?)', $ids); - $assetsData = $connection->query($select)->fetchAll(); + foreach ($this->getAssetsData($ids) as $assetData) { + $assets[] = $this->assetFactory->create(['data' => $assetData]); + } } catch (\Exception $exception) { $this->logger->critical($exception); throw new LocalizedException(__('Could not retrieve media assets'), $exception); } - - $assets = []; - - foreach ($assetsData as $assetData) { - $assets[] = $this->assetFactory->create(['data' => $assetData]); - } - return $assets; } + + /** + * Retrieve assets data from database + * + * @param array $ids + * @return array + * @throws \Zend_Db_Statement_Exception + */ + private function getAssetsData(array $ids): array + { + $mediaAssetTable = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET); + $connection = $this->resourceConnection->getConnection(); + $select = $connection->select() + ->from(['amg' => $mediaAssetTable]) + ->where('amg.id IN (?)', $ids); + return $connection->query($select)->fetchAll(); + } } diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php index 78aa5fe471df9..93c66e9a7fe51 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php @@ -58,12 +58,11 @@ public function __construct( */ public function execute(array $paths): array { + $assets = []; try { - $connection = $this->resourceConnection->getConnection(); - $select = $connection->select() - ->from($this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET)) - ->where(self::MEDIA_GALLERY_ASSET_PATH . ' IN (?)', $paths); - $assetsData = $connection->query($select)->fetchAll(); + foreach ($this->getAssetsData($paths) as $assetData) { + $assets[] = $this->mediaAssetFactory->create(['data' => $assetData]); + } } catch (\Exception $exception) { $this->logger->critical($exception); throw new LocalizedException( @@ -75,13 +74,22 @@ public function execute(array $paths): array ) ); } - - $assets = []; - - foreach ($assetsData as $assetData) { - $assets[] = $this->mediaAssetFactory->create(['data' => $assetData]); - } - return $assets; } + + /** + * Retrieve assets data from database + * + * @param array $paths + * @return array + * @throws \Zend_Db_Statement_Exception + */ + private function getAssetsData(array $paths): array + { + $connection = $this->resourceConnection->getConnection(); + $select = $connection->select() + ->from($this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET)) + ->where(self::MEDIA_GALLERY_ASSET_PATH . ' IN (?)', $paths); + return $connection->query($select)->fetchAll(); + } } diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php b/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php index e75acca66d0f4..84733ca2ff1c6 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php @@ -79,7 +79,7 @@ public function execute(array $assets): void __( 'Could not save the media assets: %assets', [ - 'assets' => $failedAssets + 'assets' => implode(' ,', $failedAssets) ] ) ); diff --git a/app/code/Magento/MediaGallery/Plugin/Wysiwyg/Images/Storage.php b/app/code/Magento/MediaGallery/Plugin/Wysiwyg/Images/Storage.php index 11331e4b9303f..11cb0f0dfd920 100644 --- a/app/code/Magento/MediaGallery/Plugin/Wysiwyg/Images/Storage.php +++ b/app/code/Magento/MediaGallery/Plugin/Wysiwyg/Images/Storage.php @@ -88,7 +88,7 @@ public function afterDeleteFile(StorageSubject $subject, StorageSubject $result, return $result; } - $relativePath = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->getRelativePath($target); + $relativePath = $this->getMediaDirectoryRelativePath($target); if (!$relativePath) { return $result; } @@ -120,13 +120,22 @@ public function afterDeleteDirectory(StorageSubject $subject, $result, $path) } try { - $mediaDirectoryRead = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); - $relativePath = $mediaDirectoryRead->getRelativePath($path); - $this->deleteMediaAssetByDirectoryPath->execute($relativePath); + $this->deleteMediaAssetByDirectoryPath->execute($this->getMediaDirectoryRelativePath($path)); } catch (ValidatorException $exception) { $this->logger->critical($exception); } return $result; } + + /** + * Get path relative to media directory + * + * @param string $path + * @return string + */ + private function getMediaDirectoryRelativePath(string $path): string + { + return $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->getRelativePath($path); + } } diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index ab49d5fa3b25e..4fcc18e29726c 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -19,8 +19,8 @@ - - + + From e7a78fae7c23cbcfab75d126644f558808cbea24 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Thu, 9 Apr 2020 14:16:50 +0100 Subject: [PATCH 21/35] magento/magento2#27499: Fixed directory integration tests --- .../Model/Directory/Command/CreateByPaths.php | 6 +- .../Model/Directory/Command/DeleteByPaths.php | 4 +- .../Keyword/GetAssetsKeywords.php | 5 +- ...teByPathTest.php => CreateByPathsTest.php} | 50 +++++++--- ...teByPathTest.php => DeleteByPathsTest.php} | 53 ++++++---- .../File/Command/DeleteByAssertIdTest.php | 99 ------------------- 6 files changed, 78 insertions(+), 139 deletions(-) rename dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/{CreateByPathTest.php => CreateByPathsTest.php} (58%) rename dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/{DeleteByPathTest.php => DeleteByPathsTest.php} (53%) delete mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php index a6b09ed8cda62..cbd2f08365246 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php @@ -47,7 +47,7 @@ public function execute(array $paths): void $failedPaths = []; foreach ($paths as $path) { try { - $name = end(explode('/', $path)); + $name = basename($path); $this->storage->createDirectory( $name, $this->storage->getCmsWysiwygImages()->getStorageRoot() . $path @@ -62,7 +62,9 @@ public function execute(array $paths): void throw new CouldNotSaveException( __( 'Could not save directories: %paths', - implode(' ,', $failedPaths) + [ + 'paths' => implode(' ,', $failedPaths) + ] ) ); } diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php index 9be25574822ae..b313fdb368e12 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php @@ -58,7 +58,9 @@ public function execute(array $paths): void throw new CouldNotDeleteException( __( 'Could not delete directories: %paths', - implode(' ,', $failedPaths) + [ + 'paths' => implode(' ,', $failedPaths) + ] ) ); } diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php index a83c6e28b2d94..40df55805d955 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php @@ -69,11 +69,10 @@ public function __construct( public function execute(array $assetIds): array { try { - $this->getAssetKeywords($this->getKeywordsData($assetIds)); + return $this->getAssetKeywords($this->getKeywordsData($assetIds)); } catch (\Exception $exception) { $this->logger->critical($exception); - $message = __('An error occurred during get asset keywords: %1', $exception->getMessage()); - throw new IntegrationException($message, $exception); + throw new IntegrationException(__('Could not retrieve asset keywords.'), $exception); } } diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathsTest.php similarity index 58% rename from dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php rename to dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathsTest.php index 63daab064e5e1..c35ba75be34ff 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathsTest.php @@ -10,13 +10,13 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; -use Magento\MediaGalleryApi\Model\Directory\Command\CreateByPathInterface; +use Magento\MediaGalleryApi\Api\CreateDirectoriesByPathsInterface; use Magento\TestFramework\Helper\Bootstrap; /** * Test methods of class CreateByPath */ -class CreateByPathTest extends \PHPUnit\Framework\TestCase +class CreateByPathsTest extends \PHPUnit\Framework\TestCase { /** * Test directory name @@ -24,54 +24,74 @@ class CreateByPathTest extends \PHPUnit\Framework\TestCase private const TEST_DIRECTORY_NAME = 'testCreateDirectory'; /** - * Absolute path to the media direcrory + * Absolute path to the media directory */ private $mediaDirectoryPath; /** - * @var CreateByPathInterface + * @var CreateDirectoriesByPathsInterface */ - private $createByPath; + private $createByPaths; /** * @inheritdoc */ public function setUp() { - $this->createByPath = Bootstrap::getObjectManager()->get(CreateByPathInterface::class); + $this->createByPaths = Bootstrap::getObjectManager()->get(CreateDirectoriesByPathsInterface::class); $this->mediaDirectoryPath = Bootstrap::getObjectManager()->get(Filesystem::class) ->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath(); } /** - * @return void * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function testCreateDirectory(): void { - $fullPath = $this->mediaDirectoryPath . self::TEST_DIRECTORY_NAME; - $this->createByPath->execute('', self::TEST_DIRECTORY_NAME); - $this->assertFileExists($fullPath); + $this->createByPaths->execute([self::TEST_DIRECTORY_NAME]); + $this->assertFileExists($this->mediaDirectoryPath . self::TEST_DIRECTORY_NAME); } /** - * @return void * @throws \Magento\Framework\Exception\CouldNotSaveException * @expectedException \Magento\Framework\Exception\CouldNotSaveException */ public function testCreateDirectoryThatAlreadyExist(): void { - $this->createByPath->execute('', self::TEST_DIRECTORY_NAME); + $this->createByPaths->execute([self::TEST_DIRECTORY_NAME]); + $this->assertFileExists($this->mediaDirectoryPath . self::TEST_DIRECTORY_NAME); + $this->createByPaths->execute([self::TEST_DIRECTORY_NAME]); } /** - * @return void + * @param array $paths * @throws \Magento\Framework\Exception\CouldNotSaveException * @expectedException \Magento\Framework\Exception\CouldNotSaveException + * @dataProvider notAllowedPathsProvider */ - public function testCreateDirectoryWithRelativePath(): void + public function testCreateDirectoryWithRelativePath(array $paths): void { - $this->createByPath->execute('../../pub/', self::TEST_DIRECTORY_NAME); + $this->createByPaths->execute($paths); + } + + /** + * Provider of paths that are not allowed for deletion + * + * @return array + */ + public function notAllowedPathsProvider(): array + { + return [ + [ + ['../../pub/' . self::TEST_DIRECTORY_NAME] + ], + [ + ['theme/' . self::TEST_DIRECTORY_NAME] + ], + [ + ['../../pub/media', 'theme'] + ] + ]; } /** diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathsTest.php similarity index 53% rename from dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php rename to dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathsTest.php index 01234db0241d7..8d9439bbae876 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathsTest.php @@ -10,64 +10,82 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; -use Magento\MediaGalleryApi\Model\Directory\Command\DeleteByPathInterface; +use Magento\MediaGalleryApi\Api\DeleteDirectoriesByPathsInterface; use Magento\TestFramework\Helper\Bootstrap; /** * Test methods of class DeleteByPath */ -class DeleteByPathTest extends \PHPUnit\Framework\TestCase +class DeleteByPathsTest extends \PHPUnit\Framework\TestCase { /** - * @var DeleteByPathInterface + * @var DeleteDirectoriesByPathsInterface */ - private $deleteByPath; + private $deleteByPaths; /** * @var string */ private $testDirectoryName = 'testDeleteDirectory'; + /** + * @var Filesystem + */ + private $filesystem; + /** * @inheritdoc */ public function setUp() { - $this->deleteByPath = Bootstrap::getObjectManager()->create(DeleteByPathInterface::class); + $this->deleteByPaths = Bootstrap::getObjectManager()->get(DeleteDirectoriesByPathsInterface::class); + $this->filesystem = Bootstrap::getObjectManager()->get(Filesystem::class); } /** * @throws \Magento\Framework\Exception\CouldNotDeleteException * @throws \Magento\Framework\Exception\FileSystemException */ - public function testDeleteDirectoryWithExistingDirectoryAndCorrectAbsolutePath(): void + public function testDeleteDirectory(): void { /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */ - $mediaDirectory = Bootstrap::getObjectManager()->get(Filesystem::class) - ->getDirectoryRead(DirectoryList::MEDIA); + $mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); $mediaDirectory->create($this->testDirectoryName); $fullPath = $mediaDirectory->getAbsolutePath($this->testDirectoryName); $this->assertFileExists($fullPath); - $this->deleteByPath->execute($this->testDirectoryName); + $this->deleteByPaths->execute([$this->testDirectoryName]); $this->assertFileNotExists($fullPath); } /** + * @param array $paths * @throws \Magento\Framework\Exception\CouldNotDeleteException * @expectedException \Magento\Framework\Exception\CouldNotDeleteException + * @dataProvider notAllowedPathsProvider */ - public function testDeleteDirectoryWithRelativePathUnderMediaFolder(): void + public function testDeleteDirectoryThatIsNotAllowed(array $paths): void { - $this->deleteByPath->execute('../../pub/media'); + $this->deleteByPaths->execute($paths); } /** - * @throws \Magento\Framework\Exception\CouldNotDeleteException - * @expectedException \Magento\Framework\Exception\CouldNotDeleteException + * Provider of paths that are not allowed for deletion + * + * @return array */ - public function testDeleteDirectoryThatIsNotAllowed(): void + public function notAllowedPathsProvider(): array { - $this->deleteByPath->execute('theme'); + return [ + [ + ['../../pub/media'] + ], + [ + ['theme'] + ], + [ + ['../../pub/media', 'theme'] + ] + ]; } /** @@ -75,10 +93,7 @@ public function testDeleteDirectoryThatIsNotAllowed(): void */ public function tearDown() { - $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get(\Magento\Framework\Filesystem::class); - /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */ - $directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); + $directory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); if ($directory->isExist($this->testDirectoryName)) { $directory->delete($this->testDirectoryName); } diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php deleted file mode 100644 index 5acfb6170e155..0000000000000 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/File/Command/DeleteByAssertIdTest.php +++ /dev/null @@ -1,99 +0,0 @@ -get(Filesystem::class)->getDirectoryWrite(DirectoryList::MEDIA); - self::$_mediaPath = $directory->getAbsolutePath(); - $directory->create(self::TEST_DIRECTORY_NAME); - $directory->touch(self::TEST_DIRECTORY_NAME . '/path.jpg'); - } - - /** - * @inheritdoc - */ - public function setUp() - { - $this->deleteByAssetId = Bootstrap::getObjectManager()->create(DeleteByAssetIdInterface::class); - } - - /** - * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php - * @return void - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function testDeleteByAssetIdWithExistingAsset(): void - { - $fullPath = self::$_mediaPath . self::TEST_DIRECTORY_NAME . '/path.jpg'; - $getById = Bootstrap::getObjectManager()->get(GetByIdInterface::class); - $this->assertFileExists($fullPath); - $this->assertEquals(1, $getById->execute(1)->getId()); - $this->deleteByAssetId->execute(1); - $this->assertFileNotExists($fullPath); - $this->expectException(\Magento\Framework\Exception\NoSuchEntityException::class); - $getById->execute(1); - } - - /** - * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php - * @return void - * @throws \Magento\Framework\Exception\LocalizedException - * @expectedException \Magento\Framework\Exception\LocalizedException - */ - public function testDeleteByAssetIdWithoutAsset(): void - { - $fullPath = self::$_mediaPath . self::TEST_DIRECTORY_NAME . '/path.jpg'; - $this->assertFileNotExists($fullPath); - $this->deleteByAssetId->execute(1); - } - - /** - * @throws \Magento\Framework\Exception\FileSystemException - */ - public static function tearDownAfterClass() - { - $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get(\Magento\Framework\Filesystem::class); - /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */ - $directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); - if ($directory->isExist(self::TEST_DIRECTORY_NAME)) { - $directory->delete(self::TEST_DIRECTORY_NAME); - } - } -} From f4d980a378bfeb44c2ad3774b84fa1dc3c1d4884 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Thu, 9 Apr 2020 19:05:55 +0100 Subject: [PATCH 22/35] magento/magento2#27499: Integration tests --- .../ResourceModel/DeleteAssetsByPaths.php | 3 - .../Keyword/GetAssetsKeywords.php | 2 +- .../Api/SaveAssetsInterface.php | 2 - .../MediaGallery/Model/AssetEndToEndTest.php | 153 +++++++++++++++ .../Directory/Command/CreateByPathsTest.php | 2 +- .../Directory/Command/DeleteByPathsTest.php | 2 +- .../MediaGallery/Model/IsBlacklistedTest.php | 59 ++++++ .../Model/ResourceModel/AssetKeywordsTest.php | 147 +++++++++++++++ .../Model/ResourceModel/AssetsByIdsTest.php | 48 +++++ .../Model/ResourceModel/AssetsTest.php | 174 ++++++++++++++++++ .../Model/ResourceModel/DeleteAssetsTest.php | 101 ++++++++++ .../MediaGallery/_files/media_asset.php | 3 +- .../_files/media_asset_rollback.php | 1 - 13 files changed, 686 insertions(+), 11 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsByIdsTest.php create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php create mode 100644 dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsTest.php diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php b/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php index d965ed63de5fd..031bf25c4e5bb 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php @@ -81,9 +81,6 @@ public function execute(array $paths): void */ private function deleteAssetsByDirectoryPath(string $path): void { - // Make sure that the path has a trailing slash - $path = rtrim($path, '/') . '/'; - /** @var AdapterInterface $connection */ $connection = $this->resourceConnection->getConnection(); $tableName = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET); diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php index 40df55805d955..ab67c23e2cd4e 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php @@ -112,7 +112,7 @@ private function getAssetKeywords(array $keywordsData): array $assetKeywords = []; foreach ($keywordsByAsset as $assetId => $keywords) { - $assetKeywords[] = $this->assetKeywordsFactory->create( + $assetKeywords[$assetId] = $this->assetKeywordsFactory->create( [ 'data' => [ 'asset_id' => $assetId, diff --git a/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php b/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php index 52ff1670ec3ab..35f0da862e8d1 100644 --- a/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php @@ -8,8 +8,6 @@ namespace Magento\MediaGalleryApi\Api; -use Magento\MediaGalleryApi\Api\Data\AssetInterface; - /** * A command which executes the media gallery asset save operation. * @api diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php new file mode 100644 index 0000000000000..cd1c928bf5d0c --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php @@ -0,0 +1,153 @@ +saveAssetsKeywords = Bootstrap::getObjectManager()->get(SaveAssetsKeywordsInterface::class); + $this->getAssetsKeywords = Bootstrap::getObjectManager()->get(GetAssetsKeywordsInterface::class); + $this->assetsKeywordsFactory = Bootstrap::getObjectManager()->get(AssetKeywordsInterfaceFactory::class); + $this->assetFactory = Bootstrap::getObjectManager()->get(AssetInterfaceFactory::class); + $this->keywordFactory = Bootstrap::getObjectManager()->get(KeywordInterfaceFactory::class); + $this->saveAssets = Bootstrap::getObjectManager()->get(SaveAssetsInterface::class); + $this->getAssetsByIds = Bootstrap::getObjectManager()->get(GetAssetsByIdsInterface::class); + $this->getAssetsByPath = Bootstrap::getObjectManager()->get(GetAssetsByPathsInterface::class); + $this->deleteAssetsByPaths = Bootstrap::getObjectManager()->get(DeleteAssetsByPathsInterface::class); + } + + /** + * Testing assets keywords save and get + */ + public function testExecute(): void + { + $keyword1 = $this->keywordFactory->create( + [ + 'data' => [ + 'keyword' => 'pear' + ] + ] + ); + + $keyword2 = $this->keywordFactory->create( + [ + 'data' => [ + 'keyword' => 'plum' + ] + ] + ); + + $asset = $this->assetFactory->create( + [ + 'data' => [ + 'path' => 'fruit.jpg' + ] + ] + ); + $this->saveAssets->execute([$asset]); + $loadedAssets = $this->getAssetsByPath->execute([$asset->getPath()]); + $loadedAsset = $loadedAssets[0]; + + $this->assertEquals(1, count($loadedAssets)); + + $assetKeywords = $this->assetsKeywordsFactory->create( + [ + 'data' => [ + 'asset_id' => $loadedAsset->getId(), + 'keywords' => [ + $keyword1, + $keyword2 + ] + ] + ] + ); + + $this->saveAssetsKeywords->execute([$assetKeywords]); + $loadedAssetKeywords = $this->getAssetsKeywords->execute([$loadedAsset->getId()]); + + $this->assertEquals(1, count($loadedAssetKeywords)); + + /** @var AssetKeywordsInterface $loadedAssetKeywords1 */ + $loadedAssetKeywords1 = current($loadedAssetKeywords); + + $loadedKeywords = $loadedAssetKeywords1->getKeywords(); + + $this->assertEquals(2, count($loadedKeywords)); + + foreach ($loadedKeywords as $theKeyword) { + $this->assertTrue(in_array($theKeyword->getKeyword(), ['pear', 'plum'])); + } + + $this->deleteAssetsByPaths->execute(['fruit.jpg']); + } +} diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathsTest.php index c35ba75be34ff..3511cdec532fa 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathsTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/CreateByPathsTest.php @@ -14,7 +14,7 @@ use Magento\TestFramework\Helper\Bootstrap; /** - * Test methods of class CreateByPath + * Test for CreateDirectoriesByPathsInterface */ class CreateByPathsTest extends \PHPUnit\Framework\TestCase { diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathsTest.php index 8d9439bbae876..3eaf7fbe3538a 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathsTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/Directory/Command/DeleteByPathsTest.php @@ -14,7 +14,7 @@ use Magento\TestFramework\Helper\Bootstrap; /** - * Test methods of class DeleteByPath + * Test for DeleteDirectoriesByPathsInterface */ class DeleteByPathsTest extends \PHPUnit\Framework\TestCase { diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php new file mode 100644 index 0000000000000..e87cbe22ac622 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php @@ -0,0 +1,59 @@ +service = Bootstrap::getObjectManager()->get(IsPathBlacklistedInterface::class); + } + + /** + * Testing the blacklisted paths + * + * @param string $path + * @param bool $isBlacklisted + * @dataProvider pathsProvider + */ + public function testExecute(string $path, bool $isBlacklisted): void + { + $this->assertEquals($isBlacklisted, $this->service->execute($path)); + } + + /** + * Provider of paths and if the path should be in the blacklist + * + * @return array + */ + public function pathsProvider(): array + { + return [ + ['theme', true], + ['.thumbs', true], + ['catalog/product/somedir', true], + ['catalog/category', false] + ]; + } +} diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php new file mode 100644 index 0000000000000..f26ff54eb7bec --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php @@ -0,0 +1,147 @@ +saveAssetsKeywords = Bootstrap::getObjectManager()->get(SaveAssetsKeywordsInterface::class); + $this->getAssetsKeywords = Bootstrap::getObjectManager()->get(GetAssetsKeywordsInterface::class); + $this->assetsKeywordsFactory = Bootstrap::getObjectManager()->get(AssetKeywordsInterfaceFactory::class); + $this->keywordFactory = Bootstrap::getObjectManager()->get(KeywordInterfaceFactory::class); + $this->getAssetsByPath = Bootstrap::getObjectManager()->get(GetAssetsByPathsInterface::class); + } + + /** + * Testing assets keywords save and get + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * @dataProvider keywordsProvider + * @param array $keywords + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function testSaveAndGetKeywords(array $keywords): void + { + $keywords = ['pear', 'plum']; + + $loadedAssets = $this->getAssetsByPath->execute([self::FIXTURE_ASSET_PATH]); + $this->assertEquals(1, count($loadedAssets)); + $loadedAsset = current($loadedAssets); + + $assetKeywords = $this->assetsKeywordsFactory->create( + [ + 'data' => [ + 'asset_id' => $loadedAsset->getId(), + 'keywords' => $this->getKeywords($keywords) + ] + ] + ); + + $this->saveAssetsKeywords->execute([$assetKeywords]); + $loadedAssetKeywords = $this->getAssetsKeywords->execute([$loadedAsset->getId()]); + + $this->assertEquals(1, count($loadedAssetKeywords)); + + /** @var AssetKeywordsInterface $loadedAssetKeyword */ + $loadedAssetKeyword = current($loadedAssetKeywords); + + $loadedKeywords = $loadedAssetKeyword->getKeywords(); + + $this->assertEquals(count($keywords), count($loadedKeywords)); + + $loadedKeywordStrings = []; + foreach ($loadedKeywords as $loadedKeywordObject) { + $loadedKeywordStrings[] = $loadedKeywordObject->getKeyword(); + } + + sort($loadedKeywordStrings); + sort($keywords); + + $this->assertEquals($keywords, $loadedKeywordStrings); + } + + /** + * Data provider of paths matching existing asset + * + * @return array + */ + public function keywordsProvider(): array + { + return [ + [['one-keyword']], + [['кириллица']], + [['plum', 'pear']], + [[]] + ]; + } + + /** + * Create keywords + * + * @param string[] $keywords + * @return KeywordsInterface[] + */ + private function getKeywords(array $keywords): array + { + $keywordObjects = []; + foreach ($keywords as $keyword) { + $keywordObjects[] = $this->keywordFactory->create( + [ + 'data' => [ + 'keyword' => $keyword + ] + ] + ); + } + return $keywordObjects; + } +} diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsByIdsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsByIdsTest.php new file mode 100644 index 0000000000000..ebf4ae94e811a --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsByIdsTest.php @@ -0,0 +1,48 @@ +getAssetsByIds = Bootstrap::getObjectManager()->get(GetAssetsByIdsInterface::class); + } + + /** + * Testing assets keywords save and get + * + * @throws \Magento\Framework\Exception\LocalizedException + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + */ + public function testExecute(): void + { + $assets = $this->getAssetsByIds->execute([self::FIXTURE_ASSET_ID]); + $this->assertEquals(1, count($assets)); + $this->assertEquals($assets[0]->getPath(), self::FIXTURE_ASSET_PATH); + } +} diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php new file mode 100644 index 0000000000000..17a555ac0b66f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php @@ -0,0 +1,174 @@ +assetFactory = Bootstrap::getObjectManager()->get(AssetInterfaceFactory::class); + $this->saveAssets = Bootstrap::getObjectManager()->get(SaveAssetsInterface::class); + $this->getAssetsByIds = Bootstrap::getObjectManager()->get(GetAssetsByIdsInterface::class); + $this->getAssetsByPath = Bootstrap::getObjectManager()->get(GetAssetsByPathsInterface::class); + $this->deleteAssetsByPaths = Bootstrap::getObjectManager()->get(DeleteAssetsByPathsInterface::class); + $this->dataObjectProcessor = Bootstrap::getObjectManager()->get(DataObjectProcessor::class); + } + + /** + * Testing assets keywords save and get + * + * @param array $assetsData + * @throws \Magento\Framework\Exception\CouldNotSaveException + * @throws \Magento\Framework\Exception\LocalizedException + * + * @dataProvider assetsDataProvider + */ + public function testExecute(array $assetsData): void + { + $this->saveAssets->execute($this->getAssets($assetsData)); + + $paths = $this->getKeyValues($assetsData, 'path'); + $loadedAssets = $this->getAssetsByPath->execute($paths); + $loadedPaths = $this->getFieldValues($loadedAssets, 'path'); + + $this->assertEquals(count($assetsData), count($loadedAssets)); + + sort($paths); + sort($loadedPaths); + $this->assertEquals($paths, $loadedPaths); + + $this->deleteAssetsByPaths->execute($paths); + $this->assertEmpty($this->getAssetsByPath->execute($paths)); + } + + /** + * Data provider for testExecute + * + * @return array + */ + public function assetsDataProvider(): array + { + return [ + 'One asset' => [ + 'assetsData' => [ + 'asset1' => [ + 'path' => 'fruit.jpg' + ] + ] + ], + 'Two assets' => [ + 'assetsData' => [ + 'asset1' => [ + 'path' => 'image.jpg' + ], + 'asset2' => [ + 'path' => 'image2.png' + ] + ] + ], + ]; + } + + /** + * Create assets + * + * @param array $assetsData + * @return AssetInterface[] + */ + private function getAssets(array $assetsData): array + { + $assets = []; + foreach ($assetsData as $assetData) { + $assets[] = $this->assetFactory->create( + [ + 'data' => $assetData + ] + ); + } + return $assets; + } + + /** + * Get field values from assets + * + * @param AssetInterface[] $assets + * @param string $fieldName + * @return string[] + */ + private function getFieldValues(array $assets, string $fieldName): array + { + $values = []; + foreach ($assets as $asset) { + $data = $this->dataObjectProcessor->buildOutputDataArray($asset, AssetInterface::class); + $values[] = $data[$fieldName]; + } + return $values; + } + + /** + * Get key values from assets data array + * + * @param array $assetsData + * @param string $key + * @return string[] + */ + private function getKeyValues(array $assetsData, string $key): array + { + $values = []; + foreach ($assetsData as $assetData) { + $values[] = $assetData[$key]; + } + return $values; + } +} diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsTest.php new file mode 100644 index 0000000000000..c9710c0dd4f28 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsTest.php @@ -0,0 +1,101 @@ +getAssetsByPath = Bootstrap::getObjectManager()->get(GetAssetsByPathsInterface::class); + $this->deleteAssetsByPaths = Bootstrap::getObjectManager()->get(DeleteAssetsByPathsInterface::class); + } + + /** + * Test deletion of assets by path + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * + * @param array $paths + * @throws \Magento\Framework\Exception\CouldNotSaveException + * @throws \Magento\Framework\Exception\LocalizedException + * + * @dataProvider matchingPathsProvider + */ + public function testAssetsAreDeleted(array $paths): void + { + $this->deleteAssetsByPaths->execute($paths); + $this->assertEmpty($this->getAssetsByPath->execute([self::FIXTURE_ASSET_PATH])); + } + + /** + * Test scenarios where delete operation should not delete an asset + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * + * @param array $paths + * @throws \Magento\Framework\Exception\CouldNotSaveException + * @throws \Magento\Framework\Exception\LocalizedException + * + * @dataProvider notMatchingPathsProvider + */ + public function testAssetsAreNotDeleted(array $paths): void + { + $this->deleteAssetsByPaths->execute($paths); + $this->assertNotEmpty($this->getAssetsByPath->execute([self::FIXTURE_ASSET_PATH])); + } + + /** + * Data provider of paths matching existing asset + * + * @return array + */ + public function matchingPathsProvider(): array + { + return [ + [['testDirectory/path.jpg']], + [['testDirectory/']], + [['testDirectory']] + ]; + } + + /** + * Data provider of paths not matching existing asset + * + * @return array + */ + public function notMatchingPathsProvider(): array + { + return [ + [['testDirectory/path.png']], + [['anotherDirectory/path.jpg']], + [['path.jpg']] + ]; + } +} diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php index c0a6691e54852..f9ad69220dc4d 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); use Magento\MediaGalleryApi\Api\Data\AssetInterface; @@ -18,7 +17,7 @@ $mediaAsset = $mediaAssetFactory->create( [ 'data' => [ - 'id' => 1, + 'id' => 2020, 'path' => 'testDirectory/path.jpg' ] ] diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php index 5f26d9350775e..0f51c10814029 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); use Magento\MediaGalleryApi\Model\Asset\Command\DeleteByPathInterface; From ce08d3487a9e8543fbfa8766a263609528240e80 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Thu, 9 Apr 2020 19:34:26 +0100 Subject: [PATCH 23/35] magento/magento2#27499: Corrected comments and unit tests --- .../Asset/Command/DeleteByDirectoryPath.php | 1 + .../Model/Asset/Command/DeleteByPath.php | 1 + .../Model/Asset/Command/GetById.php | 1 + .../Model/Asset/Command/GetByPath.php | 3 +- .../MediaGallery/Model/Asset/Command/Save.php | 3 +- .../MediaGallery/Model/AssetKeywords.php | 2 +- .../Model/Directory/Command/CreateByPaths.php | 2 +- .../Model/Directory/Command/DeleteByPaths.php | 2 +- .../Model/ResourceModel/GetAssetsByPaths.php | 2 +- .../Keyword/GetAssetsKeywords.php | 2 +- .../Keyword/SaveAssetsKeywords.php | 2 +- .../Model/Directory/IsBlacklistedTest.php | 9 +- .../File/Command/DeleteByAssetIdTest.php | 103 ------------------ .../Keyword/Command/GetAssetKeywordsTest.php | 2 +- .../Keyword/Command/SaveAssetKeywordsTest.php | 2 +- .../Keyword/Command/SaveAssetLinksTest.php | 2 +- .../Test/Unit/Plugin/Images/StorageTest.php | 3 +- .../Api/CreateDirectoriesByPathsInterface.php | 4 +- .../Api/DeleteAssetsByPathsInterface.php | 4 +- .../Api/DeleteDirectoriesByPathsInterface.php | 4 +- .../Api/GetAssetsByIdsInterface.php | 2 +- .../Api/GetAssetsByPathsInterface.php | 2 +- .../Api/GetAssetsKeywordsInterface.php | 4 +- .../Api/SaveAssetsInterface.php | 4 +- .../Api/SaveAssetsKeywordsInterface.php | 4 +- .../DeleteByDirectoryPathInterface.php | 3 +- .../Asset/Command/DeleteByPathInterface.php | 1 + .../Model/Asset/Command/GetByIdInterface.php | 1 + .../Asset/Command/GetByPathInterface.php | 1 + .../Model/Asset/Command/SaveInterface.php | 3 +- .../Command/GetAssetKeywordsInterface.php | 3 +- .../Command/SaveAssetKeywordsInterface.php | 3 +- .../Plugin/Product/Gallery/ProcessorTest.php | 20 ++-- .../MediaGallery/Model/AssetEndToEndTest.php | 2 +- .../MediaGallery/Model/IsBlacklistedTest.php | 2 +- .../Model/ResourceModel/AssetKeywordsTest.php | 2 +- .../Model/ResourceModel/AssetsByIdsTest.php | 2 +- .../Model/ResourceModel/AssetsTest.php | 2 +- .../Model/ResourceModel/DeleteAssetsTest.php | 2 +- 39 files changed, 60 insertions(+), 157 deletions(-) delete mode 100644 app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByDirectoryPath.php b/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByDirectoryPath.php index 8487a9cbb46db..3abe4cb50f2ea 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByDirectoryPath.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByDirectoryPath.php @@ -16,6 +16,7 @@ /** * Remove asset(s) that correspond the provided directory path * @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead + * @see \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterfac */ class DeleteByDirectoryPath implements DeleteByDirectoryPathInterface { diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php b/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php index eaf47b467e3a9..3abe707fbf863 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php @@ -16,6 +16,7 @@ /** * Class DeleteByPath * @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead + * @see \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface */ class DeleteByPath implements DeleteByPathInterface { diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php index 9826ef7725023..18fd3738580c4 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php @@ -18,6 +18,7 @@ /** * Get media asset by id * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface instead + * @see \Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface */ class GetById implements GetByIdInterface { diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php index bebb7ea91c481..21a27ce500332 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php @@ -17,7 +17,8 @@ /** * Class GetByPath - * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByPathInterface instead + * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface instead + * @see \Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface */ class GetByPath implements GetByPathInterface { diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php index 5d84b3ae29c80..b8a7ae3b624f3 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php @@ -16,7 +16,8 @@ /** * Class Save - * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetInterface instead + * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetsInterface instead + * @see \Magento\MediaGalleryApi\Api\SaveAssetsInterface */ class Save implements SaveInterface { diff --git a/app/code/Magento/MediaGallery/Model/AssetKeywords.php b/app/code/Magento/MediaGallery/Model/AssetKeywords.php index 95a060fccffcd..c4cced87f4d4e 100644 --- a/app/code/Magento/MediaGallery/Model/AssetKeywords.php +++ b/app/code/Magento/MediaGallery/Model/AssetKeywords.php @@ -12,7 +12,7 @@ use Magento\MediaGalleryApi\Api\Data\AssetKeywordsExtensionInterface; /** - * Asset's Keywords + * Asset Id and Keywords combination data object for bulk operations with keyword services */ class AssetKeywords extends AbstractExtensibleModel implements AssetKeywordsInterface { diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php index cbd2f08365246..52459d42086e4 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php @@ -13,7 +13,7 @@ use Psr\Log\LoggerInterface; /** - * Create folder by provided path + * Create directories by provided paths in the media storage */ class CreateByPaths implements CreateDirectoriesByPathsInterface { diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php index b313fdb368e12..10360e3d98926 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php @@ -13,7 +13,7 @@ use Psr\Log\LoggerInterface; /** - * Delete directory from media storage by path + * Delete directory by provided paths in the media storage */ class DeleteByPaths implements DeleteDirectoriesByPathsInterface { diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php index 93c66e9a7fe51..3a94ebd287399 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php @@ -14,7 +14,7 @@ use Psr\Log\LoggerInterface; /** - * Class GetByPath + * Get media assets by paths */ class GetAssetsByPaths implements GetAssetsByPathsInterface { diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php index ab67c23e2cd4e..f9d767d70bed8 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php @@ -17,7 +17,7 @@ use Psr\Log\LoggerInterface; /** - * Retrieve keywords for the media asset + * Retrieve keywords of the media assets */ class GetAssetsKeywords implements GetAssetsKeywordsInterface { diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetsKeywords.php b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetsKeywords.php index cb64c3173dfc9..a97c5f602c5c7 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetsKeywords.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetsKeywords.php @@ -16,7 +16,7 @@ use Psr\Log\LoggerInterface; /** - * Save keywords of assets + * Save keywords of media assets */ class SaveAssetsKeywords implements SaveAssetsKeywordsInterface { diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php index 0871759087468..84240fb9e3fe7 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php @@ -8,22 +8,23 @@ namespace Magento\MediaGallery\Test\Unit\Model\Directory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use PHPUnit\Framework\TestCase; use Magento\MediaGallery\Model\Directory\IsBlacklisted; use Magento\MediaGallery\Model\Directory\Config; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** - * Test the Excluded model + * Test for IsBlacklisted */ class IsBlacklistedTest extends TestCase { /** - * @var + * @var IsBlacklisted */ private $object; /** - * @var + * @var Config|MockObject */ private $config; diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php deleted file mode 100644 index 903b366d0a9fd..0000000000000 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/File/Command/DeleteByAssetIdTest.php +++ /dev/null @@ -1,103 +0,0 @@ -filesystem = $this->createMock(Filesystem::class); - $this->storage = $this->createMock(Storage::class); - $this->getById = $this->createMock(GetByIdInterface::class); - - $this->object = (new ObjectManager($this))->getObject( - DeleteByAssetId::class, - [ - 'filesystem' => $this->filesystem, - 'imagesStorage' => $this->storage, - 'getAssetById' => $this->getById - ] - ); - } - - /** - * Test delete file by asset id - */ - public function testExecute(): void - { - $assetId = 42; - $path = '/file1.jpg'; - $absoluteMediaPath = '/var/www/html/pub/media'; - - $asset = $this->createMock(AssetInterface::class); - $asset->expects($this->once()) - ->method('getPath') - ->willReturn($path); - - $this->getById->expects($this->once()) - ->method('execute') - ->with($assetId) - ->willReturn($asset); - - $directory = $this->createMock(Read::class); - $directory->expects($this->once()) - ->method('isFile') - ->willReturn(true); - $directory->expects($this->once()) - ->method('getAbsolutePath') - ->willReturn($absoluteMediaPath); - - $this->filesystem->expects($this->once()) - ->method('getDirectoryRead') - ->with(DirectoryList::MEDIA) - ->willReturn($directory); - - $this->storage->expects($this->once()) - ->method('deleteFile') - ->with($absoluteMediaPath . $path); - - $this->object->execute($assetId); - } -} diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/GetAssetKeywordsTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/GetAssetKeywordsTest.php index 2ccac4eac8343..0d2d5269c766d 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/GetAssetKeywordsTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/GetAssetKeywordsTest.php @@ -19,7 +19,7 @@ use Psr\Log\LoggerInterface; /** - * GetAssetKeywordsTest + * Test for GetAssetKeywords */ class GetAssetKeywordsTest extends TestCase { diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetKeywordsTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetKeywordsTest.php index 031213b873a25..302c8c8774bc6 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetKeywordsTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetKeywordsTest.php @@ -19,7 +19,7 @@ use Psr\Log\LoggerInterface; /** - * SaveAssetKeywordsTest. + * Test for SaveAssetKeywords */ class SaveAssetKeywordsTest extends TestCase { diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetLinksTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetLinksTest.php index e029ae585169c..fe9202353fa2e 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetLinksTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/SaveAssetLinksTest.php @@ -16,7 +16,7 @@ use Psr\Log\LoggerInterface; /** - * SaveAssetLinksTest. + * Test for SaveAssetLinks */ class SaveAssetLinksTest extends TestCase { diff --git a/app/code/Magento/MediaGallery/Test/Unit/Plugin/Images/StorageTest.php b/app/code/Magento/MediaGallery/Test/Unit/Plugin/Images/StorageTest.php index 4ac448733c47f..817c56b34e348 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Plugin/Images/StorageTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Plugin/Images/StorageTest.php @@ -22,12 +22,11 @@ use Psr\Log\LoggerInterface; /** - * Test the DeleteByDirectoryPath command model + * Test for the Sorage::deleteDirectory after plugin */ class StorageTest extends TestCase { private const NON_STRING_PATH = 2020; - private const NON_EXISTENT_PATH = 'non_existent'; private const INVALID_PATH = '&&'; private const VALID_PATH = 'test-directory-path/'; diff --git a/app/code/Magento/MediaGalleryApi/Api/CreateDirectoriesByPathsInterface.php b/app/code/Magento/MediaGalleryApi/Api/CreateDirectoriesByPathsInterface.php index 51cef91b703ae..65115b940a900 100644 --- a/app/code/Magento/MediaGalleryApi/Api/CreateDirectoriesByPathsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/CreateDirectoriesByPathsInterface.php @@ -8,13 +8,13 @@ namespace Magento\MediaGalleryApi\Api; /** - * Create folder by provided path + * Create folders by provided paths * @api */ interface CreateDirectoriesByPathsInterface { /** - * Create new directory by provided path + * Create new directories by provided paths * * @param string[] $paths * @throws \Magento\Framework\Exception\CouldNotSaveException diff --git a/app/code/Magento/MediaGalleryApi/Api/DeleteAssetsByPathsInterface.php b/app/code/Magento/MediaGalleryApi/Api/DeleteAssetsByPathsInterface.php index 2651638fc024c..5370235a31b95 100644 --- a/app/code/Magento/MediaGalleryApi/Api/DeleteAssetsByPathsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/DeleteAssetsByPathsInterface.php @@ -9,13 +9,13 @@ namespace Magento\MediaGalleryApi\Api; /** - * Delete media asset by exact or directory path + * Delete media assets by exact or directory paths * @api */ interface DeleteAssetsByPathsInterface { /** - * Delete media assets by path + * Delete media assets by paths. Removes all the assets which paths start with provided paths * * @param string[] $paths * @return void diff --git a/app/code/Magento/MediaGalleryApi/Api/DeleteDirectoriesByPathsInterface.php b/app/code/Magento/MediaGalleryApi/Api/DeleteDirectoriesByPathsInterface.php index 397c4b45590a6..5e04976e32c60 100644 --- a/app/code/Magento/MediaGalleryApi/Api/DeleteDirectoriesByPathsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/DeleteDirectoriesByPathsInterface.php @@ -8,13 +8,13 @@ namespace Magento\MediaGalleryApi\Api; /** - * Delete folder by provided path + * Delete folders by provided paths * @api */ interface DeleteDirectoriesByPathsInterface { /** - * Deletes the existing folder + * Deletes the existing folders * * @param string[] $paths * @throws \Magento\Framework\Exception\CouldNotDeleteException diff --git a/app/code/Magento/MediaGalleryApi/Api/GetAssetsByIdsInterface.php b/app/code/Magento/MediaGalleryApi/Api/GetAssetsByIdsInterface.php index a4d56b501b6d0..5df6722a190d4 100644 --- a/app/code/Magento/MediaGalleryApi/Api/GetAssetsByIdsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/GetAssetsByIdsInterface.php @@ -9,7 +9,7 @@ namespace Magento\MediaGalleryApi\Api; /** - * A command represents the get media gallery asset by using media gallery asset id as a filter parameter. + * Get media gallery assets by id attribute * @api */ interface GetAssetsByIdsInterface diff --git a/app/code/Magento/MediaGalleryApi/Api/GetAssetsByPathsInterface.php b/app/code/Magento/MediaGalleryApi/Api/GetAssetsByPathsInterface.php index ef64b73112155..dbaed6e0e9123 100644 --- a/app/code/Magento/MediaGalleryApi/Api/GetAssetsByPathsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/GetAssetsByPathsInterface.php @@ -8,7 +8,7 @@ namespace Magento\MediaGalleryApi\Api; /** - * A command represents the get media gallery asset by using media gallery asset path as a filter parameter. + * Get media gallery assets by paths in media storage * @api */ interface GetAssetsByPathsInterface diff --git a/app/code/Magento/MediaGalleryApi/Api/GetAssetsKeywordsInterface.php b/app/code/Magento/MediaGalleryApi/Api/GetAssetsKeywordsInterface.php index c919d6b4d0fee..99b05291f32a0 100644 --- a/app/code/Magento/MediaGalleryApi/Api/GetAssetsKeywordsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/GetAssetsKeywordsInterface.php @@ -8,13 +8,13 @@ namespace Magento\MediaGalleryApi\Api; /** - * A command represents functionality to get a media gallery asset keywords filtered by media gallery asset id. + * Get a media gallery asset keywords related to media gallery asset ids provided * @api */ interface GetAssetsKeywordsInterface { /** - * Get assets related keywords. + * Get assets related keywords * * @param int[] $assetIds * @return \Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterface[] diff --git a/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php b/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php index 35f0da862e8d1..eb9f7d70bbccf 100644 --- a/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php @@ -9,13 +9,13 @@ namespace Magento\MediaGalleryApi\Api; /** - * A command which executes the media gallery asset save operation. + * Save media gallery assets to the database * @api */ interface SaveAssetsInterface { /** - * Save media asset and return the media asset id + * Save media asset. The saved asset can later be retrieved by path * * @param \Magento\MediaGalleryApi\Api\Data\AssetInterface[] $assets * @throws \Magento\Framework\Exception\CouldNotSaveException diff --git a/app/code/Magento/MediaGalleryApi/Api/SaveAssetsKeywordsInterface.php b/app/code/Magento/MediaGalleryApi/Api/SaveAssetsKeywordsInterface.php index 0aa64710802d5..072ae7a4ec6d5 100644 --- a/app/code/Magento/MediaGalleryApi/Api/SaveAssetsKeywordsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/SaveAssetsKeywordsInterface.php @@ -8,13 +8,13 @@ namespace Magento\MediaGalleryApi\Api; /** - * A command represents the media gallery asset keywords save operation. + * Save keywords related to assets to the database * @api */ interface SaveAssetsKeywordsInterface { /** - * Save asset keywords. + * Save assets keywords * * @param \Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterface[] $assetKeywords * @throws \Magento\Framework\Exception\CouldNotSaveException diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByDirectoryPathInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByDirectoryPathInterface.php index f4189308f12b5..79b209823aeb0 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByDirectoryPathInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByDirectoryPathInterface.php @@ -11,7 +11,8 @@ /** * A command represents the media gallery assets delete action. A media gallery asset is filtered by directory * path value. - * @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead + * @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface instead + * @see \Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface */ interface DeleteByDirectoryPathInterface { diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByPathInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByPathInterface.php index 94641b8135818..f33022e75d2fe 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByPathInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/DeleteByPathInterface.php @@ -11,6 +11,7 @@ /** * A command represents the media gallery asset delete action. A media gallery asset is filtered by path value. * @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead + * @see \Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface */ interface DeleteByPathInterface { diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByIdInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByIdInterface.php index 3a8d0aa9aad98..65cc2e3eae109 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByIdInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByIdInterface.php @@ -11,6 +11,7 @@ /** * A command represents the get media gallery asset by using media gallery asset id as a filter parameter. * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface instead + * @see \Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface */ interface GetByIdInterface { diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php index 092a16ba053e2..d8d5b6773fbbc 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/GetByPathInterface.php @@ -11,6 +11,7 @@ /** * A command represents the get media gallery asset by using media gallery asset path as a filter parameter. * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByPathInterface instead + * @see \Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface */ interface GetByPathInterface { diff --git a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php index 96779238ec942..610ecf0cd22bf 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Asset/Command/SaveInterface.php @@ -12,7 +12,8 @@ /** * A command which executes the media gallery asset save operation. - * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetInterface instead + * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetsInterface instead + * @see \Magento\MediaGalleryApi\Api\SaveAssetsInterface */ interface SaveInterface { diff --git a/app/code/Magento/MediaGalleryApi/Model/Keyword/Command/GetAssetKeywordsInterface.php b/app/code/Magento/MediaGalleryApi/Model/Keyword/Command/GetAssetKeywordsInterface.php index 7f29a6b5f508e..e42c370c1c6f7 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Keyword/Command/GetAssetKeywordsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Keyword/Command/GetAssetKeywordsInterface.php @@ -9,7 +9,8 @@ /** * A command represents functionality to get a media gallery asset keywords filtered by media gallery asset id. - * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface instead + * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsKeywordsInterface instead + * @see \Magento\MediaGalleryApi\Api\GetAssetsKeywordsInterface */ interface GetAssetKeywordsInterface { diff --git a/app/code/Magento/MediaGalleryApi/Model/Keyword/Command/SaveAssetKeywordsInterface.php b/app/code/Magento/MediaGalleryApi/Model/Keyword/Command/SaveAssetKeywordsInterface.php index 05467d9dc0a80..824cbca178988 100644 --- a/app/code/Magento/MediaGalleryApi/Model/Keyword/Command/SaveAssetKeywordsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Model/Keyword/Command/SaveAssetKeywordsInterface.php @@ -9,7 +9,8 @@ /** * A command represents the media gallery asset keywords save operation. - * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetKeywordsInterface instead + * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetsKeywordsInterface instead + * @see \Magento\MediaGalleryApi\Api\SaveAssetsKeywordsInterface */ interface SaveAssetKeywordsInterface { diff --git a/app/code/Magento/MediaGalleryCatalog/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php b/app/code/Magento/MediaGalleryCatalog/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php index c16150cbb3ad1..3a8c9294259f9 100644 --- a/app/code/Magento/MediaGalleryCatalog/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php +++ b/app/code/Magento/MediaGalleryCatalog/Test/Unit/Plugin/Product/Gallery/ProcessorTest.php @@ -10,14 +10,14 @@ use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Gallery\Processor as ProcessorSubject; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; -use Magento\MediaGallery\Plugin\Product\Gallery\Processor; +use Magento\MediaGalleryCatalog\Plugin\Product\Gallery\Processor; use Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; /** - * Unit test for \Magento\MediaGallery\Plugin\Product\Gallery\Processor + * Unit test for \Magento\MediaGalleryCatalog\Plugin\Product\Gallery\Processor */ class ProcessorTest extends TestCase { @@ -56,19 +56,13 @@ protected function setUp() $this->processorSubjectMock = $this->createMock(ProcessorSubject::class); $this->productMock = $this->createMock(Product::class); - $this->deleteMediaAssetByPathMock = $this->getMockBuilder(DeleteAssetsByPathsInterface::class) - ->disableOriginalConstructor() - ->setMethods(['execute']) - ->getMockForAbstractClass(); - $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) - ->disableOriginalConstructor() - ->setMethods(['critical']) - ->getMockForAbstractClass(); + $this->deleteMediaAssetByPathMock = $this->createMock(DeleteAssetsByPathsInterface::class); + $this->loggerMock = $this->createMock(LoggerInterface::class); $this->plugin = (new ObjectManagerHelper($this))->getObject( Processor::class, [ - 'deleteMediaAssetByPath' => $this->deleteMediaAssetByPathMock, + 'deleteByPaths' => $this->deleteMediaAssetByPathMock, 'logger' => $this->loggerMock ] ); @@ -81,7 +75,7 @@ public function testAfterRemoveImageExpectsExecuteCalled() { $this->deleteMediaAssetByPathMock->expects($this->once()) ->method('execute') - ->with(self::STUB_FILE_NAME); + ->with([self::STUB_FILE_NAME]); $this->loggerMock->expects($this->never())->method('critical'); $actualResult = $this->plugin->afterRemoveImage( @@ -117,7 +111,7 @@ public function testAfterRemoveImageExpectsExecuteWillThrowException() { $this->deleteMediaAssetByPathMock->expects($this->once()) ->method('execute') - ->with(self::STUB_FILE_NAME) + ->with([self::STUB_FILE_NAME]) ->willThrowException(new \Exception('Some Exception')); $this->loggerMock->expects($this->once())->method('critical'); diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php index cd1c928bf5d0c..f24a960a29be9 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php @@ -21,7 +21,7 @@ use PHPUnit\Framework\TestCase; /** - * Testing assets keywords save and get + * End to end test for working with assets and keywords */ class AssetEndToEndTest extends TestCase { diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php index e87cbe22ac622..57822d674a842 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php @@ -12,7 +12,7 @@ use PHPUnit\Framework\TestCase; /** - * Test methods of class CreateByPath + * Test for IsPathBlacklistedInterface */ class CreateByPathsTest extends TestCase { diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php index f26ff54eb7bec..02249021f2a50 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php @@ -18,7 +18,7 @@ use PHPUnit\Framework\TestCase; /** - * Testing assets keywords save and get + * Testing assets keywords operation */ class AssetKeywordsTest extends TestCase { diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsByIdsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsByIdsTest.php index ebf4ae94e811a..de0393372d23d 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsByIdsTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsByIdsTest.php @@ -12,7 +12,7 @@ use PHPUnit\Framework\TestCase; /** - * Testing assets keywords save and get + * Test for GetAssetsByIdsInterface */ class AssetsByIdsTest extends TestCase { diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php index 17a555ac0b66f..c32113dfdda33 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php @@ -18,7 +18,7 @@ use PHPUnit\Framework\TestCase; /** - * Testing assets keywords save and get + * Test for assets operations */ class AssetsTest extends TestCase { diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsTest.php index c9710c0dd4f28..0b790730805e9 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsTest.php @@ -13,7 +13,7 @@ use PHPUnit\Framework\TestCase; /** - * Testing delete assets + * Testing delete assets operation */ class DeleteAssetsTest extends TestCase { From 6dfb2cc9f5cfb888a578ab63522cd670fe3cf67b Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Thu, 9 Apr 2020 19:46:28 +0100 Subject: [PATCH 24/35] magento/magento2#27499: Filtering data for insert --- .../MediaGallery/Model/Asset/Command/Save.php | 30 +++++++++++++++++-- .../Model/ResourceModel/SaveAssets.php | 26 +++++++++++++++- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php index b8a7ae3b624f3..0ce0d0c18e6d2 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php @@ -7,11 +7,11 @@ namespace Magento\MediaGallery\Model\Asset\Command; -use Magento\MediaGalleryApi\Api\Data\AssetInterface; -use Magento\MediaGalleryApi\Model\Asset\Command\SaveInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Reflection\DataObjectProcessor; +use Magento\MediaGalleryApi\Api\Data\AssetInterface; +use Magento\MediaGalleryApi\Model\Asset\Command\SaveInterface; use Psr\Log\LoggerInterface; /** @@ -72,7 +72,7 @@ public function execute(AssetInterface $mediaAsset): int $connection->insertOnDuplicate( $tableName, - array_filter($this->objectProcessor->buildOutputDataArray($mediaAsset, AssetInterface::class)) + $this->filterData($this->objectProcessor->buildOutputDataArray($mediaAsset, AssetInterface::class)) ); return (int) $connection->lastInsertId($tableName); } catch (\Exception $exception) { @@ -81,4 +81,28 @@ public function execute(AssetInterface $mediaAsset): int throw new CouldNotSaveException($message, $exception); } } + + /** + * Filter data to get flat array without null values + * + * @param array $data + * @return array + */ + private function filterData(array $data): array + { + $filteredData = []; + foreach ($data as $key => $value) { + if ($value === null) { + continue; + } + if (is_array($value)) { + continue; + } + if (is_object($value)) { + continue; + } + $filteredData[$key] = $value; + } + return $filteredData; + } } diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php b/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php index 84733ca2ff1c6..64689d0ab4275 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php @@ -66,7 +66,7 @@ public function execute(array $assets): void try { $connection->insertOnDuplicate( $tableName, - array_filter($this->objectProcessor->buildOutputDataArray($asset, AssetInterface::class)) + $this->filterData($this->objectProcessor->buildOutputDataArray($asset, AssetInterface::class)) ); } catch (\Exception $exception) { $this->logger->critical($exception); @@ -85,4 +85,28 @@ public function execute(array $assets): void ); } } + + /** + * Filter data to get flat array without null values + * + * @param array $data + * @return array + */ + private function filterData(array $data): array + { + $filteredData = []; + foreach ($data as $key => $value) { + if ($value === null) { + continue; + } + if (is_array($value)) { + continue; + } + if (is_object($value)) { + continue; + } + $filteredData[$key] = $value; + } + return $filteredData; + } } From c13a5fb186e69e89006398a62216ff421d612324 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Tue, 14 Apr 2020 11:11:20 +0100 Subject: [PATCH 25/35] magento/magento#227499: Intorduced ConfigInterface --- .../MediaGallery/Model/Directory/Config.php | 16 ++------------ .../Model/Directory/ConfigInterface.php | 21 +++++++++++++++++++ .../Model/Directory/IsBlacklisted.php | 6 +++--- app/code/Magento/MediaGallery/etc/di.xml | 2 ++ .../Magento/MediaGalleryApi/etc/directory.xsd | 2 +- 5 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 app/code/Magento/MediaGallery/Model/Directory/ConfigInterface.php diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config.php b/app/code/Magento/MediaGallery/Model/Directory/Config.php index 46314be9edfc1..610457ed50de4 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config.php @@ -12,7 +12,7 @@ /** * Media gallery directory config */ -class Config +class Config implements ConfigInterface { private const XML_PATH_BLACKLIST_PATTERNS = 'blacklist/patterns'; @@ -29,18 +29,6 @@ public function __construct(DataInterface $data) $this->data = $data; } - /** - * Get config value by key. - * - * @param string|null $key - * @param string|null $default - * @return array - */ - public function get($key = null, $default = null) - { - return $this->data->get($key, $default); - } - /** * Returns list of blacklist regexp patterns * @@ -48,6 +36,6 @@ public function get($key = null, $default = null) */ public function getBlacklistPatterns() : array { - return $this->get(self::XML_PATH_BLACKLIST_PATTERNS); + return $this->data->get(self::XML_PATH_BLACKLIST_PATTERNS); } } diff --git a/app/code/Magento/MediaGallery/Model/Directory/ConfigInterface.php b/app/code/Magento/MediaGallery/Model/Directory/ConfigInterface.php new file mode 100644 index 0000000000000..80d6c0be6b746 --- /dev/null +++ b/app/code/Magento/MediaGallery/Model/Directory/ConfigInterface.php @@ -0,0 +1,21 @@ +config = $config; } diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index 4fcc18e29726c..6d41971060ddc 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -10,6 +10,8 @@ + + diff --git a/app/code/Magento/MediaGalleryApi/etc/directory.xsd b/app/code/Magento/MediaGalleryApi/etc/directory.xsd index 51ca17809ab78..2ad76c8fcc9f2 100644 --- a/app/code/Magento/MediaGalleryApi/etc/directory.xsd +++ b/app/code/Magento/MediaGalleryApi/etc/directory.xsd @@ -29,7 +29,7 @@ - List of directory paths regexp patterns + List of directory paths RegExp patterns From 30ce748b8dc0b0e61fcd86f65b19014be91ffea4 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 14 Apr 2020 15:38:52 -0500 Subject: [PATCH 26/35] magento/magento2#27499: Code review fixes --- .../MediaGallery/Model/Asset/Command/Save.php | 47 +++++-------------- .../MediaGallery/Model/Directory/Config.php | 19 ++------ .../Model/Directory/IsBlacklisted.php | 11 +++-- .../Model/ResourceModel/SaveAssets.php | 45 +++++------------- .../Model/Directory/IsBlacklistedTest.php | 7 +-- app/code/Magento/MediaGallery/etc/di.xml | 2 + .../Api/CreateDirectoriesByPathsInterface.php | 1 + .../Api/DeleteDirectoriesByPathsInterface.php | 1 + .../Api/IsPathBlacklistedInterface.php | 4 +- .../Api/SaveAssetsInterface.php | 1 + .../Api/SaveAssetsKeywordsInterface.php | 1 + .../BlacklistPatternsConfigInterface.php | 20 ++++++++ ...or.php => RemoveAssetAfterRemoveImage.php} | 2 +- ...hp => RemoveAssetAfterRemoveImageTest.php} | 8 ++-- .../Magento/MediaGalleryCatalog/etc/di.xml | 3 +- 15 files changed, 74 insertions(+), 98 deletions(-) create mode 100644 app/code/Magento/MediaGalleryApi/Model/BlacklistPatternsConfigInterface.php rename app/code/Magento/MediaGalleryCatalog/Plugin/Product/Gallery/{Processor.php => RemoveAssetAfterRemoveImage.php} (98%) rename app/code/Magento/MediaGalleryCatalog/Test/Unit/Plugin/Product/Gallery/{ProcessorTest.php => RemoveAssetAfterRemoveImageTest.php} (94%) diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php index 0ce0d0c18e6d2..b445e9000313c 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php @@ -28,11 +28,6 @@ class Save implements SaveInterface */ private $resourceConnection; - /** - * @var DataObjectProcessor - */ - private $objectProcessor; - /** * @var LoggerInterface */ @@ -42,16 +37,13 @@ class Save implements SaveInterface * Save constructor. * * @param ResourceConnection $resourceConnection - * @param DataObjectProcessor $objectProcessor * @param LoggerInterface $logger */ public function __construct( ResourceConnection $resourceConnection, - DataObjectProcessor $objectProcessor, LoggerInterface $logger ) { $this->resourceConnection = $resourceConnection; - $this->objectProcessor = $objectProcessor; $this->logger = $logger; } @@ -72,37 +64,24 @@ public function execute(AssetInterface $mediaAsset): int $connection->insertOnDuplicate( $tableName, - $this->filterData($this->objectProcessor->buildOutputDataArray($mediaAsset, AssetInterface::class)) + [ + 'id' => $mediaAsset->getId(), + 'path' => $mediaAsset->getPath(), + 'title' => $mediaAsset->getTitle(), + 'source' => $mediaAsset->getSource(), + 'content_type' => $mediaAsset->getContentType(), + 'width' => $mediaAsset->getWidth(), + 'height' => $mediaAsset->getHeight(), + 'size' => $mediaAsset->getSize(), + 'created_at' => $mediaAsset->getCreatedAt(), + 'updated_at' => $mediaAsset->getUpdatedAt(), + ] ); - return (int) $connection->lastInsertId($tableName); + return (int)$connection->lastInsertId($tableName); } catch (\Exception $exception) { $this->logger->critical($exception); $message = __('An error occurred during media asset save: %1', $exception->getMessage()); throw new CouldNotSaveException($message, $exception); } } - - /** - * Filter data to get flat array without null values - * - * @param array $data - * @return array - */ - private function filterData(array $data): array - { - $filteredData = []; - foreach ($data as $key => $value) { - if ($value === null) { - continue; - } - if (is_array($value)) { - continue; - } - if (is_object($value)) { - continue; - } - $filteredData[$key] = $value; - } - return $filteredData; - } } diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config.php b/app/code/Magento/MediaGallery/Model/Directory/Config.php index 46314be9edfc1..67695080b185f 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Config.php @@ -8,11 +8,12 @@ namespace Magento\MediaGallery\Model\Directory; use Magento\Framework\Config\DataInterface; +use Magento\MediaGalleryApi\Model\BlacklistPatternsConfigInterface; /** * Media gallery directory config */ -class Config +class Config implements BlacklistPatternsConfigInterface { private const XML_PATH_BLACKLIST_PATTERNS = 'blacklist/patterns'; @@ -29,25 +30,13 @@ public function __construct(DataInterface $data) $this->data = $data; } - /** - * Get config value by key. - * - * @param string|null $key - * @param string|null $default - * @return array - */ - public function get($key = null, $default = null) - { - return $this->data->get($key, $default); - } - /** * Returns list of blacklist regexp patterns * * @return array */ - public function getBlacklistPatterns() : array + public function get() : array { - return $this->get(self::XML_PATH_BLACKLIST_PATTERNS); + return $this->data->get(self::XML_PATH_BLACKLIST_PATTERNS); } } diff --git a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php index d2e59b5613b4a..4ca7527ef724b 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php +++ b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php @@ -8,6 +8,7 @@ namespace Magento\MediaGallery\Model\Directory; use Magento\MediaGalleryApi\Api\IsPathBlacklistedInterface; +use Magento\MediaGalleryApi\Model\BlacklistPatternsConfigInterface; /** * Check if the path is blacklisted for media gallery. Directory path may be blacklisted if it's reserved by the system @@ -15,14 +16,14 @@ class IsBlacklisted implements IsPathBlacklistedInterface { /** - * @var Config + * @var BlacklistPatternsConfigInterface */ private $config; - /** - * @param Config $config + /* + * @param BlacklistPatternsConfigInterface $config */ - public function __construct(Config $config) + public function __construct(BlacklistPatternsConfigInterface $config) { $this->config = $config; } @@ -35,7 +36,7 @@ public function __construct(Config $config) */ public function execute(string $path): bool { - foreach ($this->config->getBlacklistPatterns() as $pattern) { + foreach ($this->config->get() as $pattern) { if (empty($pattern)) { continue; } diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php b/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php index 64689d0ab4275..33b5403fda497 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php @@ -26,11 +26,6 @@ class SaveAssets implements SaveAssetsInterface */ private $resourceConnection; - /** - * @var DataObjectProcessor - */ - private $objectProcessor; - /** * @var LoggerInterface */ @@ -40,16 +35,13 @@ class SaveAssets implements SaveAssetsInterface * Save constructor. * * @param ResourceConnection $resourceConnection - * @param DataObjectProcessor $objectProcessor * @param LoggerInterface $logger */ public function __construct( ResourceConnection $resourceConnection, - DataObjectProcessor $objectProcessor, LoggerInterface $logger ) { $this->resourceConnection = $resourceConnection; - $this->objectProcessor = $objectProcessor; $this->logger = $logger; } @@ -66,7 +58,18 @@ public function execute(array $assets): void try { $connection->insertOnDuplicate( $tableName, - $this->filterData($this->objectProcessor->buildOutputDataArray($asset, AssetInterface::class)) + [ + 'id' => $asset->getId(), + 'path' => $asset->getPath(), + 'title' => $asset->getTitle(), + 'source' => $asset->getSource(), + 'content_type' => $asset->getContentType(), + 'width' => $asset->getWidth(), + 'height' => $asset->getHeight(), + 'size' => $asset->getSize(), + 'created_at' => $asset->getCreatedAt(), + 'updated_at' => $asset->getUpdatedAt(), + ] ); } catch (\Exception $exception) { $this->logger->critical($exception); @@ -85,28 +88,4 @@ public function execute(array $assets): void ); } } - - /** - * Filter data to get flat array without null values - * - * @param array $data - * @return array - */ - private function filterData(array $data): array - { - $filteredData = []; - foreach ($data as $key => $value) { - if ($value === null) { - continue; - } - if (is_array($value)) { - continue; - } - if (is_object($value)) { - continue; - } - $filteredData[$key] = $value; - } - return $filteredData; - } } diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php index 84240fb9e3fe7..549974d27b58f 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php @@ -10,6 +10,7 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\MediaGallery\Model\Directory\IsBlacklisted; use Magento\MediaGallery\Model\Directory\Config; +use Magento\MediaGalleryApi\Model\BlacklistPatternsConfigInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -24,7 +25,7 @@ class IsBlacklistedTest extends TestCase private $object; /** - * @var Config|MockObject + * @var BlacklistPatternsConfigInterface|MockObject */ private $config; @@ -33,8 +34,8 @@ class IsBlacklistedTest extends TestCase */ protected function setUp(): void { - $this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); - $this->config->expects($this->at(0))->method('getBlacklistPatterns')->willReturn([ + $this->config = $this->getMockBuilder(BlacklistPatternsConfigInterface::class)->disableOriginalConstructor()->getMock(); + $this->config->expects($this->at(0))->method('get')->willReturn([ 'tmp' => '/pub\/media\/tmp/', 'captcha' => '/pub\/media\/captcha/' ]); diff --git a/app/code/Magento/MediaGallery/etc/di.xml b/app/code/Magento/MediaGallery/etc/di.xml index 4fcc18e29726c..73360197bed77 100644 --- a/app/code/Magento/MediaGallery/etc/di.xml +++ b/app/code/Magento/MediaGallery/etc/di.xml @@ -56,4 +56,6 @@ Magento\MediaGallery\Model\Directory\Config\Data + + diff --git a/app/code/Magento/MediaGalleryApi/Api/CreateDirectoriesByPathsInterface.php b/app/code/Magento/MediaGalleryApi/Api/CreateDirectoriesByPathsInterface.php index 65115b940a900..a0a1ec891237f 100644 --- a/app/code/Magento/MediaGalleryApi/Api/CreateDirectoriesByPathsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/CreateDirectoriesByPathsInterface.php @@ -17,6 +17,7 @@ interface CreateDirectoriesByPathsInterface * Create new directories by provided paths * * @param string[] $paths + * @return void * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function execute(array $paths): void; diff --git a/app/code/Magento/MediaGalleryApi/Api/DeleteDirectoriesByPathsInterface.php b/app/code/Magento/MediaGalleryApi/Api/DeleteDirectoriesByPathsInterface.php index 5e04976e32c60..fe3be88fa0073 100644 --- a/app/code/Magento/MediaGalleryApi/Api/DeleteDirectoriesByPathsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/DeleteDirectoriesByPathsInterface.php @@ -17,6 +17,7 @@ interface DeleteDirectoriesByPathsInterface * Deletes the existing folders * * @param string[] $paths + * @return void * @throws \Magento\Framework\Exception\CouldNotDeleteException */ public function execute(array $paths): void; diff --git a/app/code/Magento/MediaGalleryApi/Api/IsPathBlacklistedInterface.php b/app/code/Magento/MediaGalleryApi/Api/IsPathBlacklistedInterface.php index b2e5afabee11e..cbd23ec3fbde7 100644 --- a/app/code/Magento/MediaGalleryApi/Api/IsPathBlacklistedInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/IsPathBlacklistedInterface.php @@ -8,7 +8,9 @@ namespace Magento\MediaGalleryApi\Api; /** - * Directory paths that are reserved by system and not be included in the media gallery + * Check if the path is blacklisted for media gallery. + * + * Directory path may be blacklisted if it's reserved by the system. * @api */ interface IsPathBlacklistedInterface diff --git a/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php b/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php index eb9f7d70bbccf..c63f7bd8c0818 100644 --- a/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/SaveAssetsInterface.php @@ -18,6 +18,7 @@ interface SaveAssetsInterface * Save media asset. The saved asset can later be retrieved by path * * @param \Magento\MediaGalleryApi\Api\Data\AssetInterface[] $assets + * @return void * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function execute(array $assets): void; diff --git a/app/code/Magento/MediaGalleryApi/Api/SaveAssetsKeywordsInterface.php b/app/code/Magento/MediaGalleryApi/Api/SaveAssetsKeywordsInterface.php index 072ae7a4ec6d5..04efe7d32ccc1 100644 --- a/app/code/Magento/MediaGalleryApi/Api/SaveAssetsKeywordsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/SaveAssetsKeywordsInterface.php @@ -17,6 +17,7 @@ interface SaveAssetsKeywordsInterface * Save assets keywords * * @param \Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterface[] $assetKeywords + * @return void * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function execute(array $assetKeywords): void; diff --git a/app/code/Magento/MediaGalleryApi/Model/BlacklistPatternsConfigInterface.php b/app/code/Magento/MediaGalleryApi/Model/BlacklistPatternsConfigInterface.php new file mode 100644 index 0000000000000..b4710f32e0c46 --- /dev/null +++ b/app/code/Magento/MediaGalleryApi/Model/BlacklistPatternsConfigInterface.php @@ -0,0 +1,20 @@ +loggerMock = $this->createMock(LoggerInterface::class); $this->plugin = (new ObjectManagerHelper($this))->getObject( - Processor::class, + RemoveAssetAfterRemoveImage::class, [ 'deleteByPaths' => $this->deleteMediaAssetByPathMock, 'logger' => $this->loggerMock diff --git a/app/code/Magento/MediaGalleryCatalog/etc/di.xml b/app/code/Magento/MediaGalleryCatalog/etc/di.xml index 41dfeaf14aace..8145134025990 100644 --- a/app/code/Magento/MediaGalleryCatalog/etc/di.xml +++ b/app/code/Magento/MediaGalleryCatalog/etc/di.xml @@ -7,7 +7,6 @@ --> - + From 6a94b59b22a17d20459a66c82df8515dacd09c98 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 14 Apr 2020 15:44:18 -0500 Subject: [PATCH 27/35] magento/magento2#27499: Code review fixes --- ...Config.php => BlacklistPatternsConfig.php} | 2 +- .../Model/Directory/ConfigInterface.php | 21 ------------------- .../Model/Directory/IsBlacklistedTest.php | 1 - app/code/Magento/MediaGallery/etc/di.xml | 7 ++----- 4 files changed, 3 insertions(+), 28 deletions(-) rename app/code/Magento/MediaGallery/Model/Directory/{Config.php => BlacklistPatternsConfig.php} (91%) delete mode 100644 app/code/Magento/MediaGallery/Model/Directory/ConfigInterface.php diff --git a/app/code/Magento/MediaGallery/Model/Directory/Config.php b/app/code/Magento/MediaGallery/Model/Directory/BlacklistPatternsConfig.php similarity index 91% rename from app/code/Magento/MediaGallery/Model/Directory/Config.php rename to app/code/Magento/MediaGallery/Model/Directory/BlacklistPatternsConfig.php index 67695080b185f..8fdd4f70d5060 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Config.php +++ b/app/code/Magento/MediaGallery/Model/Directory/BlacklistPatternsConfig.php @@ -13,7 +13,7 @@ /** * Media gallery directory config */ -class Config implements BlacklistPatternsConfigInterface +class BlacklistPatternsConfig implements BlacklistPatternsConfigInterface { private const XML_PATH_BLACKLIST_PATTERNS = 'blacklist/patterns'; diff --git a/app/code/Magento/MediaGallery/Model/Directory/ConfigInterface.php b/app/code/Magento/MediaGallery/Model/Directory/ConfigInterface.php deleted file mode 100644 index 80d6c0be6b746..0000000000000 --- a/app/code/Magento/MediaGallery/Model/Directory/ConfigInterface.php +++ /dev/null @@ -1,21 +0,0 @@ - - - - @@ -53,11 +50,11 @@ Media_Gallery_Patterns_CacheId - + Magento\MediaGallery\Model\Directory\Config\Data - + From e3ea27dfe78b6e7c7b5996ce668f008dc61926b2 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Wed, 15 Apr 2020 15:46:29 -0500 Subject: [PATCH 28/35] magento/magento2#27499: Code review fixes. --- .../MediaGallery/Model/Asset/Command/Save.php | 34 ++++++++++-------- .../Model/ResourceModel/SaveAssets.php | 35 +++++++++++-------- .../Magento/MediaGallery/etc/db_schema.xml | 3 ++ 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php index b445e9000313c..168fb479d3cdd 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php @@ -61,22 +61,26 @@ public function execute(AssetInterface $mediaAsset): int /** @var \Magento\Framework\DB\Adapter\Pdo\Mysql $connection */ $connection = $this->resourceConnection->getConnection(); $tableName = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET); + $record = [ + 'id' => $mediaAsset->getId(), + 'path' => $mediaAsset->getPath(), + 'title' => $mediaAsset->getTitle(), + 'source' => $mediaAsset->getSource(), + 'content_type' => $mediaAsset->getContentType(), + 'width' => $mediaAsset->getWidth(), + 'height' => $mediaAsset->getHeight(), + 'size' => $mediaAsset->getSize(), + ]; - $connection->insertOnDuplicate( - $tableName, - [ - 'id' => $mediaAsset->getId(), - 'path' => $mediaAsset->getPath(), - 'title' => $mediaAsset->getTitle(), - 'source' => $mediaAsset->getSource(), - 'content_type' => $mediaAsset->getContentType(), - 'width' => $mediaAsset->getWidth(), - 'height' => $mediaAsset->getHeight(), - 'size' => $mediaAsset->getSize(), - 'created_at' => $mediaAsset->getCreatedAt(), - 'updated_at' => $mediaAsset->getUpdatedAt(), - ] - ); + if ($mediaAsset->getCreatedAt()) { + $record['created_at'] = $mediaAsset->getCreatedAt(); + } + + if ($mediaAsset->getUpdatedAt()) { + $record['updated_at'] = $mediaAsset->getUpdatedAt(); + } + + $connection->insertOnDuplicate($tableName, $record); return (int)$connection->lastInsertId($tableName); } catch (\Exception $exception) { $this->logger->critical($exception); diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php b/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php index 33b5403fda497..ec08addf93462 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/SaveAssets.php @@ -56,21 +56,26 @@ public function execute(array $assets): void $failedAssets = []; foreach ($assets as $asset) { try { - $connection->insertOnDuplicate( - $tableName, - [ - 'id' => $asset->getId(), - 'path' => $asset->getPath(), - 'title' => $asset->getTitle(), - 'source' => $asset->getSource(), - 'content_type' => $asset->getContentType(), - 'width' => $asset->getWidth(), - 'height' => $asset->getHeight(), - 'size' => $asset->getSize(), - 'created_at' => $asset->getCreatedAt(), - 'updated_at' => $asset->getUpdatedAt(), - ] - ); + $record = [ + 'id' => $asset->getId(), + 'path' => $asset->getPath(), + 'title' => $asset->getTitle(), + 'source' => $asset->getSource(), + 'content_type' => $asset->getContentType(), + 'width' => $asset->getWidth(), + 'height' => $asset->getHeight(), + 'size' => $asset->getSize(), + ]; + + if ($asset->getCreatedAt()) { + $record['created_at'] = $asset->getCreatedAt(); + } + + if ($asset->getUpdatedAt()) { + $record['updated_at'] = $asset->getUpdatedAt(); + } + + $connection->insertOnDuplicate($tableName, $record); } catch (\Exception $exception) { $this->logger->critical($exception); $failedAssets[] = $asset; diff --git a/app/code/Magento/MediaGallery/etc/db_schema.xml b/app/code/Magento/MediaGallery/etc/db_schema.xml index 8bcad28de2a8e..13e619dd9e74a 100644 --- a/app/code/Magento/MediaGallery/etc/db_schema.xml +++ b/app/code/Magento/MediaGallery/etc/db_schema.xml @@ -26,6 +26,9 @@ + + + From 024300a40743a953f459dcc9eab3b2aedd7c77e5 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Thu, 16 Apr 2020 13:01:16 -0500 Subject: [PATCH 29/35] Updated MediaGallery modules and marked as API --- app/code/Magento/MediaGalleryCatalog/etc/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/MediaGalleryCatalog/etc/di.xml b/app/code/Magento/MediaGalleryCatalog/etc/di.xml index 8145134025990..bdfdf2c5ef959 100644 --- a/app/code/Magento/MediaGalleryCatalog/etc/di.xml +++ b/app/code/Magento/MediaGalleryCatalog/etc/di.xml @@ -7,6 +7,6 @@ --> - + From 01ac38b82ec697e136a80f70e2f5c744c464b1f6 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Thu, 16 Apr 2020 13:43:49 -0500 Subject: [PATCH 30/35] Updated MediaGallery modules and marked as API --- .../MediaGallery/Model/Directory/Command/CreateByPaths.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php index 52459d42086e4..aed624bce5d21 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php @@ -48,9 +48,11 @@ public function execute(array $paths): void foreach ($paths as $path) { try { $name = basename($path); + $folder = str_replace($name, '', $path); + $this->storage->createDirectory( $name, - $this->storage->getCmsWysiwygImages()->getStorageRoot() . $path + $this->storage->getCmsWysiwygImages()->getStorageRoot() . $folder ); } catch (\Exception $exception) { $this->logger->critical($exception); From 1c7fd0ab9bf9aacd074fd8fa56b5993860bee2fe Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Thu, 16 Apr 2020 15:15:52 -0500 Subject: [PATCH 31/35] Eliminate AbstractExtensibleModel usage --- app/code/Magento/MediaGallery/Model/Asset.php | 144 +++++++++++++----- .../Model/Asset/Command/DeleteByPath.php | 3 +- .../Model/Asset/Command/GetById.php | 15 +- .../Model/Asset/Command/GetByPath.php | 20 ++- .../MediaGallery/Model/Asset/Command/Save.php | 6 +- .../MediaGallery/Model/AssetKeywords.php | 46 ++++-- .../Model/Directory/Command/CreateByPaths.php | 2 + .../Model/Directory/IsBlacklisted.php | 2 +- .../Magento/MediaGallery/Model/Keyword.php | 52 +++++-- .../Keyword/Command/GetAssetKeywords.php | 7 +- .../Keyword/Command/SaveAssetKeywords.php | 4 +- .../Model/ResourceModel/GetAssetsByIds.php | 15 +- .../Model/ResourceModel/GetAssetsByPaths.php | 15 +- .../Keyword/GetAssetsKeywords.php | 10 +- .../Unit/Model/Asset/Command/SaveTest.php | 34 +++-- .../Model/Directory/IsBlacklistedTest.php | 4 +- .../MediaGallery/etc/db_schema_whitelist.json | 3 +- .../Api/Data/AssetInterface.php | 14 +- .../Api/Data/AssetKeywordsInterface.php | 7 +- .../Api/Data/KeywordInterface.php | 6 +- .../Magento/MediaGalleryCatalog/composer.json | 2 +- .../MediaGallery/Model/AssetEndToEndTest.php | 23 +-- .../MediaGallery/Model/IsBlacklistedTest.php | 2 +- .../Model/ResourceModel/AssetKeywordsTest.php | 12 +- .../Model/ResourceModel/AssetsTest.php | 9 +- .../MediaGallery/_files/media_asset.php | 8 +- .../_files/media_asset_rollback.php | 1 - 27 files changed, 324 insertions(+), 142 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Asset.php b/app/code/Magento/MediaGallery/Model/Asset.php index 8e232ff0336d9..ff6ba8e372024 100644 --- a/app/code/Magento/MediaGallery/Model/Asset.php +++ b/app/code/Magento/MediaGallery/Model/Asset.php @@ -10,36 +10,112 @@ use Magento\MediaGalleryApi\Api\Data\AssetExtensionInterface; use Magento\MediaGalleryApi\Api\Data\AssetInterface; -use Magento\Framework\Model\AbstractExtensibleModel; /** * Media Gallery Asset */ -class Asset extends AbstractExtensibleModel implements AssetInterface +class Asset implements AssetInterface { - private const ID = 'id'; - private const PATH = 'path'; - private const TITLE = 'title'; - private const SOURCE = 'source'; - private const CONTENT_TYPE = 'content_type'; - private const WIDTH = 'width'; - private const HEIGHT = 'height'; - private const SIZE = 'size'; - private const CREATED_AT = 'created_at'; - private const UPDATED_AT = 'updated_at'; + /** + * @var int|null + */ + private $id; + + /** + * @var string + */ + private $path; + + /** + * @var string|null + */ + private $title; + + /** + * @var string|null + */ + private $source; + + /** + * @var string + */ + private $contentType; + + /** + * @var int + */ + private $width; + + /** + * @var int + */ + private $height; + + /** + * @var int + */ + private $size; + + /** + * @var string|null + */ + private $createdAt; + + /** + * @var string|null + */ + private $updatedAt; + + /** + * @var AssetExtensionInterface|null + */ + private $extensionAttributes; + + /** + * @param string $path + * @param string $contentType + * @param int $width + * @param int $height + * @param int $size + * @param int|null $id + * @param string|null $title + * @param string|null $source + * @param string|null $createdAt + * @param string|null $updatedAt + * @param AssetExtensionInterface|null $extensionAttributes + */ + public function __construct( + string $path, + string $contentType, + int $width, + int $height, + int $size, + ?int $id = null, + ?string $title = null, + ?string $source = null, + ?string $createdAt = null, + ?string $updatedAt = null, + ?AssetExtensionInterface $extensionAttributes = null + ) { + $this->path = $path; + $this->contentType = $contentType; + $this->width = $width; + $this->height = $height; + $this->size = $size; + $this->id = $id; + $this->title = $title; + $this->source = $source; + $this->createdAt = $createdAt; + $this->updatedAt = $updatedAt; + $this->extensionAttributes = $extensionAttributes; + } /** * @inheritdoc */ public function getId(): ?int { - $id = $this->getData(self::ID); - - if (!$id) { - return null; - } - - return (int) $id; + return $this->id; } /** @@ -47,7 +123,7 @@ public function getId(): ?int */ public function getPath(): string { - return (string) $this->getData(self::PATH); + return $this->path; } /** @@ -55,7 +131,7 @@ public function getPath(): string */ public function getTitle(): ?string { - return $this->getData(self::TITLE); + return $this->title; } /** @@ -63,7 +139,7 @@ public function getTitle(): ?string */ public function getSource(): ?string { - return $this->getData(self::SOURCE); + return $this->source; } /** @@ -71,7 +147,7 @@ public function getSource(): ?string */ public function getContentType(): string { - return (string) $this->getData(self::CONTENT_TYPE); + return $this->contentType; } /** @@ -79,7 +155,7 @@ public function getContentType(): string */ public function getWidth(): int { - return (int) $this->getData(self::WIDTH); + return $this->width; } /** @@ -87,7 +163,7 @@ public function getWidth(): int */ public function getHeight(): int { - return (int) $this->getData(self::HEIGHT); + return $this->height; } /** @@ -95,38 +171,38 @@ public function getHeight(): int */ public function getSize(): int { - return (int) $this->getData(self::SIZE); + return $this->size; } /** * @inheritdoc */ - public function getCreatedAt(): string + public function getCreatedAt(): ?string { - return (string) $this->getData(self::CREATED_AT); + return $this->createdAt; } /** * @inheritdoc */ - public function getUpdatedAt(): string + public function getUpdatedAt(): ?string { - return (string) $this->getData(self::UPDATED_AT); + return $this->updatedAt; } /** * @inheritdoc */ - public function getExtensionAttributes(): AssetExtensionInterface + public function getExtensionAttributes(): ?AssetExtensionInterface { - return $this->_getExtensionAttributes(); + return $this->extensionAttributes; } /** * @inheritdoc */ - public function setExtensionAttributes(AssetExtensionInterface $extensionAttributes): void + public function setExtensionAttributes(?AssetExtensionInterface $extensionAttributes): void { - $this->_setExtensionAttributes($extensionAttributes); + $this->extensionAttributes = $extensionAttributes; } } diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php b/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php index 3abe707fbf863..fc8e5d7c84bfd 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php @@ -14,7 +14,8 @@ use Psr\Log\LoggerInterface; /** - * Class DeleteByPath + * Delete media asset by path + * * @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead * @see \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface */ diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php index 18fd3738580c4..b2f900233e46a 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php @@ -89,7 +89,20 @@ public function execute(int $mediaAssetId): AssetInterface } try { - return $this->assetFactory->create(['data' => $mediaAssetData]); + return $this->assetFactory->create( + [ + 'id' => $mediaAssetData['id'], + 'path' => $mediaAssetData['path'], + 'title' => $mediaAssetData['title'], + 'source' => $mediaAssetData['source'], + 'contentType' => $mediaAssetData['content_type'], + 'width' => $mediaAssetData['width'], + 'height' => $mediaAssetData['height'], + 'size' => $mediaAssetData['size'], + 'createdAt' => $mediaAssetData['created_at'], + 'updatedAt' => $mediaAssetData['updated_at'], + ] + ); } catch (\Exception $exception) { $this->logger->critical($exception); $message = __( diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php b/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php index 21a27ce500332..d9faad62b2cd1 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php @@ -16,7 +16,8 @@ use Psr\Log\LoggerInterface; /** - * Class GetByPath + * Provide media asset by path + * * @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface instead * @see \Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface */ @@ -59,7 +60,7 @@ public function __construct( } /** - * Return media asset asset list + * Return media asset * * @param string $path * @@ -80,7 +81,20 @@ public function execute(string $path): AssetInterface throw new NoSuchEntityException($message); } - return $this->mediaAssetFactory->create(['data' => $data]); + return $this->mediaAssetFactory->create( + [ + 'id' => $data['id'], + 'path' => $data['path'], + 'title' => $data['title'], + 'source' => $data['source'], + 'contentType' => $data['content_type'], + 'width' => $data['width'], + 'height' => $data['height'], + 'size' => $data['size'], + 'createdAt' => $data['created_at'], + 'updatedAt' => $data['updated_at'], + ] + ); } catch (\Exception $exception) { $this->logger->critical($exception); $message = __('An error occurred during get media asset list: %1', $exception->getMessage()); diff --git a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php index 168fb479d3cdd..1710176c1b3af 100644 --- a/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php +++ b/app/code/Magento/MediaGallery/Model/Asset/Command/Save.php @@ -9,13 +9,13 @@ use Magento\Framework\App\ResourceConnection; use Magento\Framework\Exception\CouldNotSaveException; -use Magento\Framework\Reflection\DataObjectProcessor; use Magento\MediaGalleryApi\Api\Data\AssetInterface; use Magento\MediaGalleryApi\Model\Asset\Command\SaveInterface; use Psr\Log\LoggerInterface; /** - * Class Save + * Save media asset + * * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetsInterface instead * @see \Magento\MediaGalleryApi\Api\SaveAssetsInterface */ @@ -48,7 +48,7 @@ public function __construct( } /** - * Save media assets + * Save media asset * * @param AssetInterface $mediaAsset * diff --git a/app/code/Magento/MediaGallery/Model/AssetKeywords.php b/app/code/Magento/MediaGallery/Model/AssetKeywords.php index c4cced87f4d4e..4ffea9551263c 100644 --- a/app/code/Magento/MediaGallery/Model/AssetKeywords.php +++ b/app/code/Magento/MediaGallery/Model/AssetKeywords.php @@ -7,24 +7,50 @@ namespace Magento\MediaGallery\Model; -use Magento\Framework\Model\AbstractExtensibleModel; use Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterface; use Magento\MediaGalleryApi\Api\Data\AssetKeywordsExtensionInterface; /** * Asset Id and Keywords combination data object for bulk operations with keyword services */ -class AssetKeywords extends AbstractExtensibleModel implements AssetKeywordsInterface +class AssetKeywords implements AssetKeywordsInterface { - private const ASSET_ID = 'asset_id'; - private const KEYWORDS = 'keywords'; + /** + * @var int + */ + private $assetId; + + /** + * @var array + */ + private $keywords; + + /** + * @var AssetKeywordsExtensionInterface|null + */ + private $extensionAttributes; + + /** + * @param int $assetId + * @param array $keywords + * @param AssetKeywordsExtensionInterface|null $extensionAttributes + */ + public function __construct( + int $assetId, + array $keywords, + ?AssetKeywordsExtensionInterface $extensionAttributes = null + ) { + $this->assetId = $assetId; + $this->keywords = $keywords; + $this->extensionAttributes = $extensionAttributes; + } /** * @inheritdoc */ public function getAssetId(): int { - return (int) $this->getData(self::ASSET_ID); + return $this->assetId; } /** @@ -32,22 +58,22 @@ public function getAssetId(): int */ public function getKeywords(): array { - return $this->getData(self::KEYWORDS); + return $this->keywords; } /** * @inheritdoc */ - public function getExtensionAttributes(): AssetKeywordsExtensionInterface + public function getExtensionAttributes(): ?AssetKeywordsExtensionInterface { - return $this->_getExtensionAttributes(); + return $this->extensionAttributes; } /** * @inheritdoc */ - public function setExtensionAttributes(AssetKeywordsExtensionInterface $extensionAttributes): void + public function setExtensionAttributes(?AssetKeywordsExtensionInterface $extensionAttributes): void { - $this->_setExtensionAttributes($extensionAttributes); + $this->extensionAttributes = $extensionAttributes; } } diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php index aed624bce5d21..cba101a18a39a 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php @@ -47,7 +47,9 @@ public function execute(array $paths): void $failedPaths = []; foreach ($paths as $path) { try { + //phpcs:ignore Magento2.Functions.DiscouragedFunction $name = basename($path); + //phpcs:ignore Magento2.Functions.DiscouragedFunction $folder = str_replace($name, '', $path); $this->storage->createDirectory( diff --git a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php index 4ca7527ef724b..0191b357aaefa 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php +++ b/app/code/Magento/MediaGallery/Model/Directory/IsBlacklisted.php @@ -20,7 +20,7 @@ class IsBlacklisted implements IsPathBlacklistedInterface */ private $config; - /* + /** * @param BlacklistPatternsConfigInterface $config */ public function __construct(BlacklistPatternsConfigInterface $config) diff --git a/app/code/Magento/MediaGallery/Model/Keyword.php b/app/code/Magento/MediaGallery/Model/Keyword.php index 18600af0dfc6c..5d3afd2096a62 100644 --- a/app/code/Magento/MediaGallery/Model/Keyword.php +++ b/app/code/Magento/MediaGallery/Model/Keyword.php @@ -10,28 +10,48 @@ use Magento\MediaGalleryApi\Api\Data\KeywordExtensionInterface; use Magento\MediaGalleryApi\Api\Data\KeywordInterface; -use Magento\Framework\Model\AbstractExtensibleModel; /** * Asset's Keyword */ -class Keyword extends AbstractExtensibleModel implements KeywordInterface +class Keyword implements KeywordInterface { - private const ID = 'id'; - private const KEYWORD = 'keyword'; + /** + * @var int + */ + private $id; + + /** + * @var string + */ + private $keyword; + + /** + * @var KeywordExtensionInterface|null + */ + private $extensionAttributes; + + /** + * @param string $keyword + * @param int|null $id + * @param KeywordExtensionInterface|null $extensionAttributes + */ + public function __construct( + string $keyword, + ?int $id = null, + ?KeywordExtensionInterface $extensionAttributes = null + ) { + $this->keyword = $keyword; + $this->id = $id; + $this->extensionAttributes = $extensionAttributes; + } /** * @inheritdoc */ public function getId(): ?int { - $id = $this->getData(self::ID); - - if (!$id) { - return null; - } - - return (int) $id; + return $this->id; } /** @@ -39,22 +59,22 @@ public function getId(): ?int */ public function getKeyword(): string { - return (string) $this->getData(self::KEYWORD); + return $this->keyword; } /** * @inheritdoc */ - public function getExtensionAttributes(): KeywordExtensionInterface + public function getExtensionAttributes(): ?KeywordExtensionInterface { - return $this->_getExtensionAttributes(); + return $this->extensionAttributes; } /** * @inheritdoc */ - public function setExtensionAttributes(KeywordExtensionInterface $extensionAttributes): void + public function setExtensionAttributes(?KeywordExtensionInterface $extensionAttributes): void { - $this->_setExtensionAttributes($extensionAttributes); + $this->extensionAttributes = $extensionAttributes; } } diff --git a/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php b/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php index 4112b717c24a2..27d32e5444f4b 100644 --- a/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php +++ b/app/code/Magento/MediaGallery/Model/Keyword/Command/GetAssetKeywords.php @@ -76,7 +76,12 @@ public function execute(int $assetId): array $keywords = []; foreach ($data as $keywordData) { - $keywords[] = $this->assetKeywordFactory->create(['data' => $keywordData]); + $keywords[] = $this->assetKeywordFactory->create( + [ + 'id' => $keywordData['id'], + 'keyword' => $keywordData['keyword'], + ] + ); } return $keywords; diff --git a/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php b/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php index 748b1e0d2463a..d3a5eab36de06 100644 --- a/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php +++ b/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php @@ -17,7 +17,7 @@ use Psr\Log\LoggerInterface; /** - * Class SaveAssetKeywords + * Save asset keywords * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetKeywordsInterface instead */ class SaveAssetKeywords implements SaveAssetKeywordsInterface @@ -42,8 +42,6 @@ class SaveAssetKeywords implements SaveAssetKeywordsInterface private $logger; /** - * SaveAssetKeywords constructor. - * * @param ResourceConnection $resourceConnection * @param SaveAssetLinks $saveAssetLinks * @param LoggerInterface $logger diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php index 89daded071c33..53185939b2283 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByIds.php @@ -60,7 +60,20 @@ public function execute(array $ids): array $assets = []; try { foreach ($this->getAssetsData($ids) as $assetData) { - $assets[] = $this->assetFactory->create(['data' => $assetData]); + $assets[] = $this->assetFactory->create( + [ + 'id' => $assetData['id'], + 'path' => $assetData['path'], + 'title' => $assetData['title'], + 'source' => $assetData['source'], + 'contentType' => $assetData['content_type'], + 'width' => $assetData['width'], + 'height' => $assetData['height'], + 'size' => $assetData['size'], + 'createdAt' => $assetData['created_at'], + 'updatedAt' => $assetData['updated_at'], + ] + ); } } catch (\Exception $exception) { $this->logger->critical($exception); diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php index 3a94ebd287399..5593083d9673a 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php @@ -61,7 +61,20 @@ public function execute(array $paths): array $assets = []; try { foreach ($this->getAssetsData($paths) as $assetData) { - $assets[] = $this->mediaAssetFactory->create(['data' => $assetData]); + $assets[] = $this->mediaAssetFactory->create( + [ + 'id' => $assetData['id'], + 'path' => $assetData['path'], + 'title' => $assetData['title'], + 'source' => $assetData['source'], + 'contentType' => $assetData['content_type'], + 'width' => $assetData['width'], + 'height' => $assetData['height'], + 'size' => $assetData['size'], + 'createdAt' => $assetData['created_at'], + 'updatedAt' => $assetData['updated_at'], + ] + ); } } catch (\Exception $exception) { $this->logger->critical($exception); diff --git a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php index f9d767d70bed8..11b0a0fa3a359 100644 --- a/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php +++ b/app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/GetAssetsKeywords.php @@ -10,7 +10,6 @@ use Magento\Framework\Exception\IntegrationException; use Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterface; use Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterfaceFactory; -use Magento\MediaGalleryApi\Api\Data\KeywordInterface; use Magento\MediaGalleryApi\Api\Data\KeywordInterfaceFactory; use Magento\MediaGalleryApi\Api\GetAssetsKeywordsInterface; use Magento\Framework\App\ResourceConnection; @@ -105,7 +104,8 @@ private function getAssetKeywords(array $keywordsData): array foreach ($keywordsData as $keywordData) { $keywordsByAsset[$keywordData[self::FIELD_ASSET_ID]][] = $this->keywordFactory->create( [ - 'data' => $keywordData + 'id' => $keywordData['id'], + 'keyword' => $keywordData['keyword'], ] ); } @@ -114,10 +114,8 @@ private function getAssetKeywords(array $keywordsData): array foreach ($keywordsByAsset as $assetId => $keywords) { $assetKeywords[$assetId] = $this->assetKeywordsFactory->create( [ - 'data' => [ - 'asset_id' => $assetId, - 'keywords' => $keywords - ] + 'assetId' => $assetId, + 'keywords' => $keywords ] ); } diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php index 8db0258fe3981..6f82d2f2a5cb3 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/SaveTest.php @@ -48,12 +48,14 @@ class SaveTest extends TestCase * Constant for image data */ private const IMAGE_DATA = [ + 'id' => null, 'path' => '/test/path', 'title' => 'Test Title', 'source' => 'Adobe Stock', 'content_type' => 'image/jpeg', 'height' => 4863, - 'width' => 12129 + 'width' => 12129, + 'size' => 300, ]; /** @@ -125,11 +127,16 @@ public function testSuccessfulExecute(): void $this->resourceConnectionMock->expects(self::once())->method('getConnection'); $this->resourceConnectionMock->expects(self::once())->method('getTableName'); - $this->objectProcessor - ->expects(self::once()) - ->method('buildOutputDataArray') - ->with($this->mediaAssetMock, AssetInterface::class) - ->willReturn(self::IMAGE_DATA); + $this->mediaAssetMock->expects(self::once())->method('getId')->willReturn(self::IMAGE_DATA['id']); + $this->mediaAssetMock->expects(self::once())->method('getPath')->willReturn(self::IMAGE_DATA['path']); + $this->mediaAssetMock->expects(self::once())->method('getTitle')->willReturn(self::IMAGE_DATA['title']); + $this->mediaAssetMock->expects(self::once())->method('getSource')->willReturn(self::IMAGE_DATA['source']); + $this->mediaAssetMock->expects(self::once())->method('getWidth')->willReturn(self::IMAGE_DATA['width']); + $this->mediaAssetMock->expects(self::once())->method('getHeight')->willReturn(self::IMAGE_DATA['height']); + $this->mediaAssetMock->expects(self::once())->method('getSize')->willReturn(self::IMAGE_DATA['size']); + $this->mediaAssetMock->expects(self::once()) + ->method('getContentType') + ->willReturn(self::IMAGE_DATA['content_type']); $this->adapterMock ->expects(self::once()) @@ -154,11 +161,16 @@ public function testExceptionExecute(): void $this->resourceConnectionMock->expects(self::once())->method('getConnection'); $this->resourceConnectionMock->expects(self::once())->method('getTableName'); - $this->objectProcessor - ->expects(self::once()) - ->method('buildOutputDataArray') - ->with($this->mediaAssetMock, AssetInterface::class) - ->willReturn(self::IMAGE_DATA); + $this->mediaAssetMock->expects(self::once())->method('getId')->willReturn(self::IMAGE_DATA['id']); + $this->mediaAssetMock->expects(self::once())->method('getPath')->willReturn(self::IMAGE_DATA['path']); + $this->mediaAssetMock->expects(self::once())->method('getTitle')->willReturn(self::IMAGE_DATA['title']); + $this->mediaAssetMock->expects(self::once())->method('getSource')->willReturn(self::IMAGE_DATA['source']); + $this->mediaAssetMock->expects(self::once())->method('getWidth')->willReturn(self::IMAGE_DATA['width']); + $this->mediaAssetMock->expects(self::once())->method('getHeight')->willReturn(self::IMAGE_DATA['height']); + $this->mediaAssetMock->expects(self::once())->method('getSize')->willReturn(self::IMAGE_DATA['size']); + $this->mediaAssetMock->expects(self::once()) + ->method('getContentType') + ->willReturn(self::IMAGE_DATA['content_type']); $this->adapterMock ->expects(self::once()) diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php index a60c4d75aee7d..5b069dcc70030 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Directory/IsBlacklistedTest.php @@ -33,7 +33,9 @@ class IsBlacklistedTest extends TestCase */ protected function setUp(): void { - $this->config = $this->getMockBuilder(BlacklistPatternsConfigInterface::class)->disableOriginalConstructor()->getMock(); + $this->config = $this->getMockBuilder(BlacklistPatternsConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); $this->config->expects($this->at(0))->method('get')->willReturn([ 'tmp' => '/pub\/media\/tmp/', 'captcha' => '/pub\/media\/captcha/' diff --git a/app/code/Magento/MediaGallery/etc/db_schema_whitelist.json b/app/code/Magento/MediaGallery/etc/db_schema_whitelist.json index 9e187e6dea4a5..8f5098caa9753 100644 --- a/app/code/Magento/MediaGallery/etc/db_schema_whitelist.json +++ b/app/code/Magento/MediaGallery/etc/db_schema_whitelist.json @@ -14,7 +14,8 @@ }, "index": { "MEDIA_GALLERY_ID": true, - "MEDIA_GALLERY_ASSET_ID": true + "MEDIA_GALLERY_ASSET_ID": true, + "MEDIA_GALLERY_ASSET_TITLE": true }, "constraint": { "MEDIA_GALLERY_ID_PATH_TITLE_CONTENT_TYPE_WIDTH_HEIGHT": true, diff --git a/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php b/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php index c3454400b2995..5df420a274933 100644 --- a/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/Data/AssetInterface.php @@ -76,29 +76,29 @@ public function getSize(): int; /** * Get created at * - * @return string + * @return string|null */ - public function getCreatedAt(): string; + public function getCreatedAt(): ?string; /** * Get updated at * - * @return string + * @return string|null */ - public function getUpdatedAt(): string; + public function getUpdatedAt(): ?string; /** * Retrieve existing extension attributes object or create a new one. * * @return \Magento\MediaGalleryApi\Api\Data\AssetExtensionInterface|null */ - public function getExtensionAttributes(): AssetExtensionInterface; + public function getExtensionAttributes(): ?AssetExtensionInterface; /** * Set extension attributes * - * @param \Magento\MediaGalleryApi\Api\Data\AssetExtensionInterface $extensionAttributes + * @param \Magento\MediaGalleryApi\Api\Data\AssetExtensionInterface|null $extensionAttributes * @return void */ - public function setExtensionAttributes(AssetExtensionInterface $extensionAttributes): void; + public function setExtensionAttributes(?AssetExtensionInterface $extensionAttributes): void; } diff --git a/app/code/Magento/MediaGalleryApi/Api/Data/AssetKeywordsInterface.php b/app/code/Magento/MediaGalleryApi/Api/Data/AssetKeywordsInterface.php index e4356f05a1ece..1c18225470493 100644 --- a/app/code/Magento/MediaGalleryApi/Api/Data/AssetKeywordsInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/Data/AssetKeywordsInterface.php @@ -30,19 +30,18 @@ public function getAssetId(): int; */ public function getKeywords(): array; - /** * Get extension attributes * * @return \Magento\MediaGalleryApi\Api\Data\AssetKeywordsExtensionInterface|null */ - public function getExtensionAttributes(): AssetKeywordsExtensionInterface; + public function getExtensionAttributes(): ?AssetKeywordsExtensionInterface; /** * Set extension attributes * - * @param \Magento\MediaGalleryApi\Api\Data\AssetKeywordsExtensionInterface $extensionAttributes + * @param \Magento\MediaGalleryApi\Api\Data\AssetKeywordsExtensionInterface|null $extensionAttributes * @return void */ - public function setExtensionAttributes(AssetKeywordsExtensionInterface $extensionAttributes): void; + public function setExtensionAttributes(?AssetKeywordsExtensionInterface $extensionAttributes): void; } diff --git a/app/code/Magento/MediaGalleryApi/Api/Data/KeywordInterface.php b/app/code/Magento/MediaGalleryApi/Api/Data/KeywordInterface.php index 7f19e53d6e380..3cba118e03a1a 100644 --- a/app/code/Magento/MediaGalleryApi/Api/Data/KeywordInterface.php +++ b/app/code/Magento/MediaGalleryApi/Api/Data/KeywordInterface.php @@ -35,13 +35,13 @@ public function getKeyword(): string; * * @return \Magento\MediaGalleryApi\Api\Data\KeywordExtensionInterface|null */ - public function getExtensionAttributes(): KeywordExtensionInterface; + public function getExtensionAttributes(): ?KeywordExtensionInterface; /** * Set extension attributes * - * @param \Magento\MediaGalleryApi\Api\Data\KeywordExtensionInterface $extensionAttributes + * @param \Magento\MediaGalleryApi\Api\Data\KeywordExtensionInterface|null $extensionAttributes * @return void */ - public function setExtensionAttributes(KeywordExtensionInterface $extensionAttributes): void; + public function setExtensionAttributes(?KeywordExtensionInterface $extensionAttributes): void; } diff --git a/app/code/Magento/MediaGalleryCatalog/composer.json b/app/code/Magento/MediaGalleryCatalog/composer.json index 8152fb5aac8bb..ed3eb63ac970a 100644 --- a/app/code/Magento/MediaGalleryCatalog/composer.json +++ b/app/code/Magento/MediaGalleryCatalog/composer.json @@ -1,5 +1,5 @@ { - "name": "magento/module-media-gallery", + "name": "magento/module-media-gallery-catalog", "description": "Magento module responsible for catalog gallery processor delete operation handling", "require": { "php": "~7.1.3||~7.2.0||~7.3.0", diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php index f24a960a29be9..4d30646d596b6 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php @@ -93,25 +93,20 @@ public function testExecute(): void { $keyword1 = $this->keywordFactory->create( [ - 'data' => [ - 'keyword' => 'pear' - ] + 'keyword' => 'pear' ] ); $keyword2 = $this->keywordFactory->create( [ - 'data' => [ - 'keyword' => 'plum' - ] + 'keyword' => 'plum' ] ); $asset = $this->assetFactory->create( [ - 'data' => [ - 'path' => 'fruit.jpg' - ] + 'path' => 'fruit.jpg', + 'contentType' => 'image' ] ); $this->saveAssets->execute([$asset]); @@ -122,12 +117,10 @@ public function testExecute(): void $assetKeywords = $this->assetsKeywordsFactory->create( [ - 'data' => [ - 'asset_id' => $loadedAsset->getId(), - 'keywords' => [ - $keyword1, - $keyword2 - ] + 'assetId' => $loadedAsset->getId(), + 'keywords' => [ + $keyword1, + $keyword2 ] ] ); diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php index 57822d674a842..47ff2b3a94aa3 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/IsBlacklistedTest.php @@ -14,7 +14,7 @@ /** * Test for IsPathBlacklistedInterface */ -class CreateByPathsTest extends TestCase +class IsBlacklistedTest extends TestCase { /** diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php index 02249021f2a50..f6b9ed5e1ff75 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetKeywordsTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\MediaGallery\Model; +namespace Magento\MediaGallery\Model\ResourceModel; use Behat\Gherkin\Keywords\KeywordsInterface; use Magento\MediaGalleryApi\Api\Data\KeywordInterfaceFactory; @@ -79,10 +79,8 @@ public function testSaveAndGetKeywords(array $keywords): void $assetKeywords = $this->assetsKeywordsFactory->create( [ - 'data' => [ - 'asset_id' => $loadedAsset->getId(), - 'keywords' => $this->getKeywords($keywords) - ] + 'assetId' => $loadedAsset->getId(), + 'keywords' => $this->getKeywords($keywords) ] ); @@ -136,9 +134,7 @@ private function getKeywords(array $keywords): array foreach ($keywords as $keyword) { $keywordObjects[] = $this->keywordFactory->create( [ - 'data' => [ - 'keyword' => $keyword - ] + 'keyword' => $keyword ] ); } diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php index c32113dfdda33..8af8a31356dd3 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php @@ -103,17 +103,20 @@ public function assetsDataProvider(): array 'One asset' => [ 'assetsData' => [ 'asset1' => [ - 'path' => 'fruit.jpg' + 'path' => 'fruit.jpg', + 'contentType' => 'image' ] ] ], 'Two assets' => [ 'assetsData' => [ 'asset1' => [ - 'path' => 'image.jpg' + 'path' => 'image.jpg', + 'contentType' => 'image' ], 'asset2' => [ - 'path' => 'image2.png' + 'path' => 'image2.png', + 'contentType' => 'image' ] ] ], diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php index f9ad69220dc4d..f332bfde37422 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php @@ -16,13 +16,11 @@ /** @var AssetInterface $mediaAsset */ $mediaAsset = $mediaAssetFactory->create( [ - 'data' => [ - 'id' => 2020, - 'path' => 'testDirectory/path.jpg' - ] + 'id' => 2020, + 'path' => 'testDirectory/path.jpg', + 'contentType' => 'image' ] ); /** @var SaveInterface $mediaSave */ $mediaSave = $objectManager->get(SaveInterface::class); $mediaId = $mediaSave->execute($mediaAsset); - diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php index 0f51c10814029..76756e912b3b5 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset_rollback.php @@ -18,4 +18,3 @@ } catch (\Exception $exception) { } - From 9a7a1c5137a6949bf9dbfbdc3e0f0b30df5506cc Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Sat, 18 Apr 2020 19:37:16 +0100 Subject: [PATCH 32/35] Fixed unit tests --- ...tionDuringMediaAssetInitializationTest.php | 35 +++++++++++-------- .../Command/GetByIdExceptionOnGetDataTest.php | 16 +++++++-- .../Asset/Command/GetByIdSuccessfulTest.php | 16 +++++++-- .../Keyword/Command/GetAssetKeywordsTest.php | 29 +++++++++++++-- 4 files changed, 73 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php index 49a5421e623a5..834e8027584dc 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionDuringMediaAssetInitializationTest.php @@ -23,9 +23,19 @@ */ class GetByIdExceptionDuringMediaAssetInitializationTest extends \PHPUnit\Framework\TestCase { - private const MEDIA_ASSET_STUB_ID = 1; - - private const MEDIA_ASSET_DATA = ['id' => 1]; + private const MEDIA_ASSET_STUB_ID = 45; + private const MEDIA_ASSET_DATA = [ + 'id' => 45, + 'path' => 'img.jpg', + 'title' => 'Img', + 'source' => 'Adobe Stock', + 'content_type' => 'image/jpeg', + 'width' => 420, + 'height' => 240, + 'size' => 12877, + 'created_at' => '2020', + 'updated_at' => '2020' + ]; /** * @var GetById|MockObject @@ -47,11 +57,6 @@ class GetByIdExceptionDuringMediaAssetInitializationTest extends \PHPUnit\Framew */ private $selectStub; - /** - * @var Statement|MockObject - */ - private $statementMock; - /** * @var LoggerInterface|MockObject */ @@ -81,8 +86,6 @@ protected function setUp(): void $this->selectStub->method('from')->willReturnSelf(); $this->selectStub->method('where')->willReturnSelf(); $this->adapter->method('select')->willReturn($this->selectStub); - - $this->statementMock = $this->getMockBuilder(\Zend_Db_Statement_Interface::class)->getMock(); } /** @@ -90,10 +93,14 @@ protected function setUp(): void */ public function testErrorDuringMediaAssetInitializationException(): void { - $this->statementMock->method('fetch')->willReturn(self::MEDIA_ASSET_DATA); - $this->adapter->method('query')->willReturn($this->statementMock); - - $this->assetFactory->expects($this->once())->method('create')->willThrowException(new \Exception()); + $statementMock = $this->createMock(\Zend_Db_Statement_Interface::class); + $statementMock->method('fetch') + ->willReturn(self::MEDIA_ASSET_DATA); + $this->adapter->method('query')->willReturn($statementMock); + + $this->assetFactory->expects($this->once()) + ->method('create') + ->willThrowException(new \Exception()); $this->expectException(IntegrationException::class); $this->logger->expects($this->any()) diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php index f76552487e0f7..19c295424cbf9 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdExceptionOnGetDataTest.php @@ -23,9 +23,19 @@ */ class GetByIdExceptionOnGetDataTest extends \PHPUnit\Framework\TestCase { - private const MEDIA_ASSET_STUB_ID = 1; - - private const MEDIA_ASSET_DATA = ['id' => 1]; + private const MEDIA_ASSET_STUB_ID = 45; + private const MEDIA_ASSET_DATA = [ + 'id' => 45, + 'path' => 'img.jpg', + 'title' => 'Img', + 'source' => 'Adobe Stock', + 'content_type' => 'image/jpeg', + 'width' => 420, + 'height' => 240, + 'size' => 12877, + 'created_at' => '2020', + 'updated_at' => '2020' + ]; /** * @var GetById|MockObject diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php index c9e8416c53156..410dd5bef18c8 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Asset/Command/GetByIdSuccessfulTest.php @@ -23,9 +23,19 @@ */ class GetByIdSuccessfulTest extends \PHPUnit\Framework\TestCase { - private const MEDIA_ASSET_STUB_ID = 1; - - private const MEDIA_ASSET_DATA = ['id' => 1]; + private const MEDIA_ASSET_STUB_ID = 45; + private const MEDIA_ASSET_DATA = [ + 'id' => 45, + 'path' => 'img.jpg', + 'title' => 'Img', + 'source' => 'Adobe Stock', + 'content_type' => 'image/jpeg', + 'width' => 420, + 'height' => 240, + 'size' => 12877, + 'created_at' => '2020', + 'updated_at' => '2020' + ]; /** * @var GetById|MockObject diff --git a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/GetAssetKeywordsTest.php b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/GetAssetKeywordsTest.php index 0d2d5269c766d..930068aebb3fe 100644 --- a/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/GetAssetKeywordsTest.php +++ b/app/code/Magento/MediaGallery/Test/Unit/Model/Keyword/Command/GetAssetKeywordsTest.php @@ -83,9 +83,32 @@ public function testFind(array $databaseQueryResult, int $expectedNumberOfFoundK public function casesProvider(): array { return [ - 'not_found' => [[],0], - 'find_one_keyword' => [['keywordRawData'],1], - 'find_several_keywords' => [['keywordRawData', 'keywordRawData'],2], + 'not_found' => [ + [], + 0 + ], + 'find_one_keyword' => [ + [ + [ + 'id' => 1, + 'keyword' => 'keywordRawData' + ] + ], + 1 + ], + 'find_several_keywords' => [ + [ + [ + 'id' => 1, + 'keyword' => 'keywordRawData' + ], + [ + 'id' => 2, + 'keyword' => 'keywordRawData2' + ] + ], + 2 + ], ]; } From 21955c58a037aebf08e8d7968c75673af6833ce7 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Sat, 18 Apr 2020 19:58:16 +0100 Subject: [PATCH 33/35] Fixed integration tests --- app/code/Magento/MediaGallery/Model/Asset.php | 1 + .../Keyword/Command/SaveAssetKeywords.php | 2 +- .../MediaGallery/Model/AssetEndToEndTest.php | 7 ++++- .../Model/ResourceModel/AssetsTest.php | 29 +++++++++++++------ .../MediaGallery/_files/media_asset.php | 7 ++++- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Asset.php b/app/code/Magento/MediaGallery/Model/Asset.php index ff6ba8e372024..0e20d6432beee 100644 --- a/app/code/Magento/MediaGallery/Model/Asset.php +++ b/app/code/Magento/MediaGallery/Model/Asset.php @@ -13,6 +13,7 @@ /** * Media Gallery Asset + * @SuppressWarnings(PHPMD.ExcessiveParameterList */ class Asset implements AssetInterface { diff --git a/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php b/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php index d3a5eab36de06..f21db25bac767 100644 --- a/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php +++ b/app/code/Magento/MediaGallery/Model/Keyword/Command/SaveAssetKeywords.php @@ -17,7 +17,7 @@ use Psr\Log\LoggerInterface; /** - * Save asset keywords + * Save media asset keywords to database * @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetKeywordsInterface instead */ class SaveAssetKeywords implements SaveAssetKeywordsInterface diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php index 4d30646d596b6..61b3c22c3ca54 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/AssetEndToEndTest.php @@ -106,7 +106,12 @@ public function testExecute(): void $asset = $this->assetFactory->create( [ 'path' => 'fruit.jpg', - 'contentType' => 'image' + 'title' => 'Img', + 'source' => 'Local', + 'contentType' => 'image/jpeg', + 'width' => 420, + 'height' => 240, + 'size' => 12877 ] ); $this->saveAssets->execute([$asset]); diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php index 8af8a31356dd3..8aec9454951f9 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/Model/ResourceModel/AssetsTest.php @@ -104,7 +104,12 @@ public function assetsDataProvider(): array 'assetsData' => [ 'asset1' => [ 'path' => 'fruit.jpg', - 'contentType' => 'image' + 'title' => 'Img', + 'source' => 'Local', + 'contentType' => 'image/jpeg', + 'width' => 420, + 'height' => 240, + 'size' => 12877 ] ] ], @@ -112,11 +117,21 @@ public function assetsDataProvider(): array 'assetsData' => [ 'asset1' => [ 'path' => 'image.jpg', - 'contentType' => 'image' + 'title' => 'Img', + 'source' => 'Local', + 'contentType' => 'image/jpeg', + 'width' => 420, + 'height' => 240, + 'size' => 12877 ], 'asset2' => [ - 'path' => 'image2.png', - 'contentType' => 'image' + 'path' => 'image2.jpg', + 'title' => 'Img', + 'source' => 'Local', + 'contentType' => 'image/jpeg', + 'width' => 420, + 'height' => 240, + 'size' => 12877 ] ] ], @@ -133,11 +148,7 @@ private function getAssets(array $assetsData): array { $assets = []; foreach ($assetsData as $assetData) { - $assets[] = $this->assetFactory->create( - [ - 'data' => $assetData - ] - ); + $assets[] = $this->assetFactory->create($assetData); } return $assets; } diff --git a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php index f332bfde37422..0a2a00c254975 100644 --- a/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php +++ b/dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php @@ -18,7 +18,12 @@ [ 'id' => 2020, 'path' => 'testDirectory/path.jpg', - 'contentType' => 'image' + 'contentType' => 'image', + 'title' => 'Img', + 'source' => 'Local', + 'width' => 420, + 'height' => 240, + 'size' => 12877 ] ); /** @var SaveInterface $mediaSave */ From c0065901fdb9bdf98a61f62b1aaeed0502089b8d Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Sat, 18 Apr 2020 21:57:25 +0100 Subject: [PATCH 34/35] Added blacklist to directory operations --- app/code/Magento/MediaGallery/Model/Asset.php | 2 +- .../Model/Directory/Command/CreateByPaths.php | 15 ++++++++++++++- .../Model/Directory/Command/DeleteByPaths.php | 15 ++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/MediaGallery/Model/Asset.php b/app/code/Magento/MediaGallery/Model/Asset.php index 0e20d6432beee..78b9477a70b08 100644 --- a/app/code/Magento/MediaGallery/Model/Asset.php +++ b/app/code/Magento/MediaGallery/Model/Asset.php @@ -13,7 +13,7 @@ /** * Media Gallery Asset - * @SuppressWarnings(PHPMD.ExcessiveParameterList + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ class Asset implements AssetInterface { diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php index cba101a18a39a..bfb6b677ce19c 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php @@ -10,6 +10,7 @@ use Magento\Cms\Model\Wysiwyg\Images\Storage; use Magento\Framework\Exception\CouldNotSaveException; use Magento\MediaGalleryApi\Api\CreateDirectoriesByPathsInterface; +use Magento\MediaGalleryApi\Api\IsPathBlacklistedInterface; use Psr\Log\LoggerInterface; /** @@ -27,16 +28,24 @@ class CreateByPaths implements CreateDirectoriesByPathsInterface */ private $storage; + /** + * @var IsPathBlacklistedInterface + */ + private $isPathBlacklisted; + /** * @param LoggerInterface $logger * @param Storage $storage + * @param IsPathBlacklistedInterface $isPathBlacklisted */ public function __construct( LoggerInterface $logger, - Storage $storage + Storage $storage, + IsPathBlacklistedInterface $isPathBlacklisted ) { $this->logger = $logger; $this->storage = $storage; + $this->isPathBlacklisted = $isPathBlacklisted; } /** @@ -46,6 +55,10 @@ public function execute(array $paths): void { $failedPaths = []; foreach ($paths as $path) { + if ($this->isPathBlacklisted->execute($path)) { + $failedPaths[] = $path; + continue; + } try { //phpcs:ignore Magento2.Functions.DiscouragedFunction $name = basename($path); diff --git a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php index 10360e3d98926..d46fb854fff22 100644 --- a/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php +++ b/app/code/Magento/MediaGallery/Model/Directory/Command/DeleteByPaths.php @@ -10,6 +10,7 @@ use Magento\Cms\Model\Wysiwyg\Images\Storage; use Magento\Framework\Exception\CouldNotDeleteException; use Magento\MediaGalleryApi\Api\DeleteDirectoriesByPathsInterface; +use Magento\MediaGalleryApi\Api\IsPathBlacklistedInterface; use Psr\Log\LoggerInterface; /** @@ -27,16 +28,24 @@ class DeleteByPaths implements DeleteDirectoriesByPathsInterface */ private $storage; + /** + * @var IsPathBlacklistedInterface + */ + private $isPathBlacklisted; + /** * @param LoggerInterface $logger * @param Storage $storage + * @param IsPathBlacklistedInterface $isPathBlacklisted */ public function __construct( LoggerInterface $logger, - Storage $storage + Storage $storage, + IsPathBlacklistedInterface $isPathBlacklisted ) { $this->logger = $logger; $this->storage = $storage; + $this->isPathBlacklisted = $isPathBlacklisted; } /** @@ -46,6 +55,10 @@ public function execute(array $paths): void { $failedPaths = []; foreach ($paths as $path) { + if ($this->isPathBlacklisted->execute($path)) { + $failedPaths[] = $path; + continue; + } try { $this->storage->deleteDirectory($this->storage->getCmsWysiwygImages()->getStorageRoot() . $path); } catch (\Exception $exception) { From 8b3c9b1df5c8584e757670a8d5b9cfc307a5b6f5 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Sun, 19 Apr 2020 12:36:29 +0100 Subject: [PATCH 35/35] Added MediaGalleryCatalog to composer.json --- composer.json | 1 + composer.lock | 708 +++++++++++++++++++++++++++++--------------------- 2 files changed, 413 insertions(+), 296 deletions(-) diff --git a/composer.json b/composer.json index 5223fa2a0aca4..63876202fbed8 100644 --- a/composer.json +++ b/composer.json @@ -195,6 +195,7 @@ "magento/module-layered-navigation": "*", "magento/module-media-gallery": "*", "magento/module-media-gallery-api": "*", + "magento/module-media-gallery-catalog": "*", "magento/module-media-storage": "*", "magento/module-message-queue": "*", "magento/module-msrp": "*", diff --git a/composer.lock b/composer.lock index 37849c7c21a29..f1095dc95b150 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1f11bed01d000a3d3eeda8b462e29f75", + "content-hash": "b7ee4a27d76ea68e295d5025c986854d", "packages": [ { "name": "braintree/braintree_php", @@ -201,16 +201,16 @@ }, { "name": "composer/ca-bundle", - "version": "1.2.6", + "version": "1.2.7", "source": { "type": "git", "url": "https://github.com/composer/ca-bundle.git", - "reference": "47fe531de31fca4a1b997f87308e7d7804348f7e" + "reference": "95c63ab2117a72f48f5a55da9740a3273d45b7fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/ca-bundle/zipball/47fe531de31fca4a1b997f87308e7d7804348f7e", - "reference": "47fe531de31fca4a1b997f87308e7d7804348f7e", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/95c63ab2117a72f48f5a55da9740a3273d45b7fd", + "reference": "95c63ab2117a72f48f5a55da9740a3273d45b7fd", "shasum": "" }, "require": { @@ -253,20 +253,30 @@ "ssl", "tls" ], - "time": "2020-01-13T10:02:55+00:00" + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2020-04-08T08:27:21+00:00" }, { "name": "composer/composer", - "version": "1.10.1", + "version": "1.10.5", "source": { "type": "git", "url": "https://github.com/composer/composer.git", - "reference": "b912a45da3e2b22f5cb5a23e441b697a295ba011" + "reference": "7a4d5b6aa30d2118af27c04f5e897b57156ccfa9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/composer/zipball/b912a45da3e2b22f5cb5a23e441b697a295ba011", - "reference": "b912a45da3e2b22f5cb5a23e441b697a295ba011", + "url": "https://api.github.com/repos/composer/composer/zipball/7a4d5b6aa30d2118af27c04f5e897b57156ccfa9", + "reference": "7a4d5b6aa30d2118af27c04f5e897b57156ccfa9", "shasum": "" }, "require": { @@ -333,7 +343,7 @@ "dependency", "package" ], - "time": "2020-03-13T19:34:27+00:00" + "time": "2020-04-10T09:44:22+00:00" }, { "name": "composer/semver", @@ -698,23 +708,24 @@ }, { "name": "guzzlehttp/guzzle", - "version": "6.5.2", + "version": "6.5.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "43ece0e75098b7ecd8d13918293029e555a50f82" + "reference": "aab4ebd862aa7d04f01a4b51849d657db56d882e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/43ece0e75098b7ecd8d13918293029e555a50f82", - "reference": "43ece0e75098b7ecd8d13918293029e555a50f82", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/aab4ebd862aa7d04f01a4b51849d657db56d882e", + "reference": "aab4ebd862aa7d04f01a4b51849d657db56d882e", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/promises": "^1.0", "guzzlehttp/psr7": "^1.6.1", - "php": ">=5.5" + "php": ">=5.5", + "symfony/polyfill-intl-idn": "^1.11" }, "require-dev": { "ext-curl": "*", @@ -722,7 +733,6 @@ "psr/log": "^1.1" }, "suggest": { - "ext-intl": "Required for Internationalized Domain Name (IDN) support", "psr/log": "Required for using the Log middleware" }, "type": "library", @@ -761,7 +771,7 @@ "rest", "web service" ], - "time": "2019-12-23T11:57:10+00:00" + "time": "2020-04-18T10:38:46+00:00" }, { "name": "guzzlehttp/promises", @@ -1243,16 +1253,16 @@ }, { "name": "laminas/laminas-db", - "version": "2.11.2", + "version": "2.11.3", "source": { "type": "git", "url": "https://github.com/laminas/laminas-db.git", - "reference": "76f9527da996c2fef32ef1f3a939e18ca5e9d962" + "reference": "6c4238918b9204db1eb8cafae2c1940d40f4c007" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-db/zipball/76f9527da996c2fef32ef1f3a939e18ca5e9d962", - "reference": "76f9527da996c2fef32ef1f3a939e18ca5e9d962", + "url": "https://api.github.com/repos/laminas/laminas-db/zipball/6c4238918b9204db1eb8cafae2c1940d40f4c007", + "reference": "6c4238918b9204db1eb8cafae2c1940d40f4c007", "shasum": "" }, "require": { @@ -1261,7 +1271,7 @@ "php": "^5.6 || ^7.0" }, "replace": { - "zendframework/zend-db": "self.version" + "zendframework/zend-db": "^2.11.0" }, "require-dev": { "laminas/laminas-coding-standard": "~1.0.0", @@ -1301,7 +1311,7 @@ "db", "laminas" ], - "time": "2020-01-14T13:07:26+00:00" + "time": "2020-03-29T12:08:51+00:00" }, { "name": "laminas/laminas-dependency-plugin", @@ -1402,16 +1412,16 @@ }, { "name": "laminas/laminas-diactoros", - "version": "1.8.7p1", + "version": "1.8.7p2", "source": { "type": "git", "url": "https://github.com/laminas/laminas-diactoros.git", - "reference": "56a9aca1f89231763d24d2ae13531b97fa5f4029" + "reference": "6991c1af7c8d2c8efee81b22ba97024781824aaa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-diactoros/zipball/56a9aca1f89231763d24d2ae13531b97fa5f4029", - "reference": "56a9aca1f89231763d24d2ae13531b97fa5f4029", + "url": "https://api.github.com/repos/laminas/laminas-diactoros/zipball/6991c1af7c8d2c8efee81b22ba97024781824aaa", + "reference": "6991c1af7c8d2c8efee81b22ba97024781824aaa", "shasum": "" }, "require": { @@ -1423,7 +1433,7 @@ "psr/http-message-implementation": "1.0" }, "replace": { - "zendframework/zend-diactoros": "self.version" + "zendframework/zend-diactoros": "~1.8.7.0" }, "require-dev": { "ext-dom": "*", @@ -1473,7 +1483,7 @@ "psr", "psr-7" ], - "time": "2020-01-07T19:25:17+00:00" + "time": "2020-03-23T15:28:28+00:00" }, { "name": "laminas/laminas-escaper", @@ -1584,16 +1594,16 @@ }, { "name": "laminas/laminas-feed", - "version": "2.12.1", + "version": "2.12.2", "source": { "type": "git", "url": "https://github.com/laminas/laminas-feed.git", - "reference": "c9356994eb80d0f6b46d7e12ba048d450bf0cd72" + "reference": "8a193ac96ebcb3e16b6ee754ac2a889eefacb654" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-feed/zipball/c9356994eb80d0f6b46d7e12ba048d450bf0cd72", - "reference": "c9356994eb80d0f6b46d7e12ba048d450bf0cd72", + "url": "https://api.github.com/repos/laminas/laminas-feed/zipball/8a193ac96ebcb3e16b6ee754ac2a889eefacb654", + "reference": "8a193ac96ebcb3e16b6ee754ac2a889eefacb654", "shasum": "" }, "require": { @@ -1605,7 +1615,7 @@ "php": "^5.6 || ^7.0" }, "replace": { - "zendframework/zend-feed": "self.version" + "zendframework/zend-feed": "^2.12.0" }, "require-dev": { "laminas/laminas-cache": "^2.7.2", @@ -1647,20 +1657,20 @@ "feed", "laminas" ], - "time": "2020-03-23T10:40:31+00:00" + "time": "2020-03-29T12:36:29+00:00" }, { "name": "laminas/laminas-filter", - "version": "2.9.3", + "version": "2.9.4", "source": { "type": "git", "url": "https://github.com/laminas/laminas-filter.git", - "reference": "52b5cdbef8902280996e687e7352a648a8e22f31" + "reference": "3c4476e772a062cef7531c6793377ae585d89c82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-filter/zipball/52b5cdbef8902280996e687e7352a648a8e22f31", - "reference": "52b5cdbef8902280996e687e7352a648a8e22f31", + "url": "https://api.github.com/repos/laminas/laminas-filter/zipball/3c4476e772a062cef7531c6793377ae585d89c82", + "reference": "3c4476e772a062cef7531c6793377ae585d89c82", "shasum": "" }, "require": { @@ -1672,7 +1682,7 @@ "laminas/laminas-validator": "<2.10.1" }, "replace": { - "zendframework/zend-filter": "self.version" + "zendframework/zend-filter": "^2.9.2" }, "require-dev": { "laminas/laminas-coding-standard": "~1.0.0", @@ -1716,20 +1726,20 @@ "filter", "laminas" ], - "time": "2020-01-07T20:43:53+00:00" + "time": "2020-03-29T12:41:29+00:00" }, { "name": "laminas/laminas-form", - "version": "2.14.4", + "version": "2.14.5", "source": { "type": "git", "url": "https://github.com/laminas/laminas-form.git", - "reference": "8b985f74bfe32910edb4ba9503877c4310228cd2" + "reference": "3e22e09751cf6ae031be87a44e092e7925ce5b7b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-form/zipball/8b985f74bfe32910edb4ba9503877c4310228cd2", - "reference": "8b985f74bfe32910edb4ba9503877c4310228cd2", + "url": "https://api.github.com/repos/laminas/laminas-form/zipball/3e22e09751cf6ae031be87a44e092e7925ce5b7b", + "reference": "3e22e09751cf6ae031be87a44e092e7925ce5b7b", "shasum": "" }, "require": { @@ -1740,7 +1750,7 @@ "php": "^5.6 || ^7.0" }, "replace": { - "zendframework/zend-form": "self.version" + "zendframework/zend-form": "^2.14.3" }, "require-dev": { "doctrine/annotations": "~1.0", @@ -1798,7 +1808,7 @@ "form", "laminas" ], - "time": "2020-03-18T22:38:54+00:00" + "time": "2020-03-29T12:46:16+00:00" }, { "name": "laminas/laminas-http", @@ -1924,16 +1934,16 @@ }, { "name": "laminas/laminas-i18n", - "version": "2.10.2", + "version": "2.10.3", "source": { "type": "git", "url": "https://github.com/laminas/laminas-i18n.git", - "reference": "9699c98d97d2f519def3da8d4128dfe6e6ad11bf" + "reference": "94ff957a1366f5be94f3d3a9b89b50386649e3ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-i18n/zipball/9699c98d97d2f519def3da8d4128dfe6e6ad11bf", - "reference": "9699c98d97d2f519def3da8d4128dfe6e6ad11bf", + "url": "https://api.github.com/repos/laminas/laminas-i18n/zipball/94ff957a1366f5be94f3d3a9b89b50386649e3ae", + "reference": "94ff957a1366f5be94f3d3a9b89b50386649e3ae", "shasum": "" }, "require": { @@ -1946,7 +1956,7 @@ "phpspec/prophecy": "<1.9.0" }, "replace": { - "zendframework/zend-i18n": "self.version" + "zendframework/zend-i18n": "^2.10.1" }, "require-dev": { "laminas/laminas-cache": "^2.6.1", @@ -1995,7 +2005,7 @@ "i18n", "laminas" ], - "time": "2020-03-20T11:57:14+00:00" + "time": "2020-03-29T12:51:08+00:00" }, { "name": "laminas/laminas-inputfilter", @@ -2362,16 +2372,16 @@ }, { "name": "laminas/laminas-mime", - "version": "2.7.3", + "version": "2.7.4", "source": { "type": "git", "url": "https://github.com/laminas/laminas-mime.git", - "reference": "e844abb02e868fae154207929190292ad25057cc" + "reference": "e45a7d856bf7b4a7b5bd00d6371f9961dc233add" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-mime/zipball/e844abb02e868fae154207929190292ad25057cc", - "reference": "e844abb02e868fae154207929190292ad25057cc", + "url": "https://api.github.com/repos/laminas/laminas-mime/zipball/e45a7d856bf7b4a7b5bd00d6371f9961dc233add", + "reference": "e45a7d856bf7b4a7b5bd00d6371f9961dc233add", "shasum": "" }, "require": { @@ -2380,7 +2390,7 @@ "php": "^5.6 || ^7.0" }, "replace": { - "zendframework/zend-mime": "self.version" + "zendframework/zend-mime": "^2.7.2" }, "require-dev": { "laminas/laminas-coding-standard": "~1.0.0", @@ -2412,7 +2422,7 @@ "laminas", "mime" ], - "time": "2020-03-06T08:38:03+00:00" + "time": "2020-03-29T13:12:07+00:00" }, { "name": "laminas/laminas-modulemanager", @@ -2797,16 +2807,16 @@ }, { "name": "laminas/laminas-session", - "version": "2.9.2", + "version": "2.9.3", "source": { "type": "git", "url": "https://github.com/laminas/laminas-session.git", - "reference": "fdba34c1b257235dba2fff6ed4df1844390f85f6" + "reference": "519e8966146536cd97c1cc3d59a21b095fb814d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-session/zipball/fdba34c1b257235dba2fff6ed4df1844390f85f6", - "reference": "fdba34c1b257235dba2fff6ed4df1844390f85f6", + "url": "https://api.github.com/repos/laminas/laminas-session/zipball/519e8966146536cd97c1cc3d59a21b095fb814d7", + "reference": "519e8966146536cd97c1cc3d59a21b095fb814d7", "shasum": "" }, "require": { @@ -2816,7 +2826,7 @@ "php": "^5.6 || ^7.0" }, "replace": { - "zendframework/zend-session": "self.version" + "zendframework/zend-session": "^2.9.1" }, "require-dev": { "container-interop/container-interop": "^1.1", @@ -2864,7 +2874,7 @@ "laminas", "session" ], - "time": "2020-03-06T09:44:45+00:00" + "time": "2020-03-29T13:26:04+00:00" }, { "name": "laminas/laminas-soap", @@ -3078,16 +3088,16 @@ }, { "name": "laminas/laminas-validator", - "version": "2.13.2", + "version": "2.13.4", "source": { "type": "git", "url": "https://github.com/laminas/laminas-validator.git", - "reference": "e7bf6a2eedc0508ebde0ebc66662efeb0abbcb2c" + "reference": "93593684e70b8ed1e870cacd34ca32b0c0ace185" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-validator/zipball/e7bf6a2eedc0508ebde0ebc66662efeb0abbcb2c", - "reference": "e7bf6a2eedc0508ebde0ebc66662efeb0abbcb2c", + "url": "https://api.github.com/repos/laminas/laminas-validator/zipball/93593684e70b8ed1e870cacd34ca32b0c0ace185", + "reference": "93593684e70b8ed1e870cacd34ca32b0c0ace185", "shasum": "" }, "require": { @@ -3097,7 +3107,7 @@ "php": "^7.1" }, "replace": { - "zendframework/zend-validator": "self.version" + "zendframework/zend-validator": "^2.13.0" }, "require-dev": { "laminas/laminas-cache": "^2.6.1", @@ -3153,7 +3163,7 @@ "laminas", "validator" ], - "time": "2020-03-16T11:38:27+00:00" + "time": "2020-03-31T18:57:01+00:00" }, { "name": "laminas/laminas-view", @@ -3248,16 +3258,16 @@ }, { "name": "laminas/laminas-zendframework-bridge", - "version": "1.0.2", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/laminas/laminas-zendframework-bridge.git", - "reference": "faf68f6109ceeff24241226033ab59640c7eb63b" + "reference": "bfbbdb6c998d50dbf69d2187cb78a5f1fa36e1e9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-zendframework-bridge/zipball/faf68f6109ceeff24241226033ab59640c7eb63b", - "reference": "faf68f6109ceeff24241226033ab59640c7eb63b", + "url": "https://api.github.com/repos/laminas/laminas-zendframework-bridge/zipball/bfbbdb6c998d50dbf69d2187cb78a5f1fa36e1e9", + "reference": "bfbbdb6c998d50dbf69d2187cb78a5f1fa36e1e9", "shasum": "" }, "require": { @@ -3296,7 +3306,7 @@ "laminas", "zf" ], - "time": "2020-03-26T16:07:12+00:00" + "time": "2020-04-03T16:01:00+00:00" }, { "name": "magento/composer", @@ -3863,16 +3873,16 @@ }, { "name": "phpseclib/phpseclib", - "version": "2.0.26", + "version": "2.0.27", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "09655fcc1f8bab65727be036b28f6f20311c126c" + "reference": "34620af4df7d1988d8f0d7e91f6c8a3bf931d8dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/09655fcc1f8bab65727be036b28f6f20311c126c", - "reference": "09655fcc1f8bab65727be036b28f6f20311c126c", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/34620af4df7d1988d8f0d7e91f6c8a3bf931d8dc", + "reference": "34620af4df7d1988d8f0d7e91f6c8a3bf931d8dc", "shasum": "" }, "require": { @@ -3951,7 +3961,7 @@ "x.509", "x509" ], - "time": "2020-03-13T04:15:39+00:00" + "time": "2020-04-04T23:17:33+00:00" }, { "name": "psr/container", @@ -4362,16 +4372,16 @@ }, { "name": "symfony/console", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "4fa15ae7be74e53f6ec8c83ed403b97e23b665e9" + "reference": "10bb3ee3c97308869d53b3e3d03f6ac23ff985f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/4fa15ae7be74e53f6ec8c83ed403b97e23b665e9", - "reference": "4fa15ae7be74e53f6ec8c83ed403b97e23b665e9", + "url": "https://api.github.com/repos/symfony/console/zipball/10bb3ee3c97308869d53b3e3d03f6ac23ff985f7", + "reference": "10bb3ee3c97308869d53b3e3d03f6ac23ff985f7", "shasum": "" }, "require": { @@ -4434,20 +4444,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2020-02-24T13:10:00+00:00" + "time": "2020-03-30T11:41:10+00:00" }, { "name": "symfony/css-selector", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "d0a6dd288fa8848dcc3d1f58b94de6a7cc5d2d22" + "reference": "afc26133a6fbdd4f8842e38893e0ee4685c7c94b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/d0a6dd288fa8848dcc3d1f58b94de6a7cc5d2d22", - "reference": "d0a6dd288fa8848dcc3d1f58b94de6a7cc5d2d22", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/afc26133a6fbdd4f8842e38893e0ee4685c7c94b", + "reference": "afc26133a6fbdd4f8842e38893e0ee4685c7c94b", "shasum": "" }, "require": { @@ -4487,20 +4497,34 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2020-02-04T09:01:01+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "4ad8e149799d3128621a3a1f70e92b9897a8930d" + "reference": "abc8e3618bfdb55e44c8c6a00abd333f831bbfed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/4ad8e149799d3128621a3a1f70e92b9897a8930d", - "reference": "4ad8e149799d3128621a3a1f70e92b9897a8930d", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/abc8e3618bfdb55e44c8c6a00abd333f831bbfed", + "reference": "abc8e3618bfdb55e44c8c6a00abd333f831bbfed", "shasum": "" }, "require": { @@ -4557,7 +4581,21 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2020-02-04T09:32:40+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/event-dispatcher-contracts", @@ -4619,16 +4657,16 @@ }, { "name": "symfony/filesystem", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "266c9540b475f26122b61ef8b23dd9198f5d1cfd" + "reference": "fe297193bf2e6866ed900ed2d5869362768df6a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/266c9540b475f26122b61ef8b23dd9198f5d1cfd", - "reference": "266c9540b475f26122b61ef8b23dd9198f5d1cfd", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/fe297193bf2e6866ed900ed2d5869362768df6a7", + "reference": "fe297193bf2e6866ed900ed2d5869362768df6a7", "shasum": "" }, "require": { @@ -4665,20 +4703,20 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2020-01-21T08:20:44+00:00" + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/finder", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "ea69c129aed9fdeca781d4b77eb20b62cf5d5357" + "reference": "5729f943f9854c5781984ed4907bbb817735776b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/ea69c129aed9fdeca781d4b77eb20b62cf5d5357", - "reference": "ea69c129aed9fdeca781d4b77eb20b62cf5d5357", + "url": "https://api.github.com/repos/symfony/finder/zipball/5729f943f9854c5781984ed4907bbb817735776b", + "reference": "5729f943f9854c5781984ed4907bbb817735776b", "shasum": "" }, "require": { @@ -4714,7 +4752,21 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2020-02-14T07:42:58+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/polyfill-ctype", @@ -4774,6 +4826,68 @@ ], "time": "2020-02-27T09:26:54+00:00" }, + { + "name": "symfony/polyfill-intl-idn", + "version": "v1.15.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-idn.git", + "reference": "47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf", + "reference": "47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/polyfill-mbstring": "^1.3", + "symfony/polyfill-php72": "^1.10" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.15-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Idn\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Laurent Bassin", + "email": "laurent@bassin.info" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "idn", + "intl", + "polyfill", + "portable", + "shim" + ], + "time": "2020-03-09T19:04:49+00:00" + }, { "name": "symfony/polyfill-mbstring", "version": "v1.15.0", @@ -4833,6 +4947,61 @@ ], "time": "2020-03-09T19:04:49+00:00" }, + { + "name": "symfony/polyfill-php72", + "version": "v1.15.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "37b0976c78b94856543260ce09b460a7bc852747" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/37b0976c78b94856543260ce09b460a7bc852747", + "reference": "37b0976c78b94856543260ce09b460a7bc852747", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.15-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2020-02-27T09:26:54+00:00" + }, { "name": "symfony/polyfill-php73", "version": "v1.15.0", @@ -4893,16 +5062,16 @@ }, { "name": "symfony/process", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "bf9166bac906c9e69fb7a11d94875e7ced97bcd7" + "reference": "3e40e87a20eaf83a1db825e1fa5097ae89042db3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/bf9166bac906c9e69fb7a11d94875e7ced97bcd7", - "reference": "bf9166bac906c9e69fb7a11d94875e7ced97bcd7", + "url": "https://api.github.com/repos/symfony/process/zipball/3e40e87a20eaf83a1db825e1fa5097ae89042db3", + "reference": "3e40e87a20eaf83a1db825e1fa5097ae89042db3", "shasum": "" }, "require": { @@ -4938,7 +5107,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2020-02-07T20:06:44+00:00" + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/service-contracts", @@ -5414,16 +5583,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.133.45", + "version": "3.134.8", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "928a23e2ee7e195a66f93d0758895e26958c3b7d" + "reference": "8a9b598a0ede2165be5988899dcebead6fcc4d41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/928a23e2ee7e195a66f93d0758895e26958c3b7d", - "reference": "928a23e2ee7e195a66f93d0758895e26958c3b7d", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/8a9b598a0ede2165be5988899dcebead6fcc4d41", + "reference": "8a9b598a0ede2165be5988899dcebead6fcc4d41", "shasum": "" }, "require": { @@ -5494,7 +5663,7 @@ "s3", "sdk" ], - "time": "2020-03-26T18:12:15+00:00" + "time": "2020-04-17T18:11:57+00:00" }, { "name": "behat/gherkin", @@ -5969,20 +6138,21 @@ }, { "name": "doctrine/annotations", - "version": "v1.8.0", + "version": "1.10.1", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc" + "reference": "5eb79f3dbdffed6544e1fc287572c0f462bd29bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/904dca4eb10715b92569fbcd79e201d5c349b6bc", - "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/5eb79f3dbdffed6544e1fc287572c0f462bd29bb", + "reference": "5eb79f3dbdffed6544e1fc287572c0f462bd29bb", "shasum": "" }, "require": { "doctrine/lexer": "1.*", + "ext-tokenizer": "*", "php": "^7.1" }, "require-dev": { @@ -5992,7 +6162,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.9.x-dev" } }, "autoload": { @@ -6033,7 +6203,7 @@ "docblock", "parser" ], - "time": "2019-10-01T18:55:10+00:00" + "time": "2020-04-02T12:33:25+00:00" }, { "name": "doctrine/cache", @@ -6567,16 +6737,16 @@ }, { "name": "league/flysystem", - "version": "1.0.66", + "version": "1.0.67", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "021569195e15f8209b1c4bebb78bd66aa4f08c21" + "reference": "5b1f36c75c4bdde981294c2a0ebdb437ee6f275e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/021569195e15f8209b1c4bebb78bd66aa4f08c21", - "reference": "021569195e15f8209b1c4bebb78bd66aa4f08c21", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/5b1f36c75c4bdde981294c2a0ebdb437ee6f275e", + "reference": "5b1f36c75c4bdde981294c2a0ebdb437ee6f275e", "shasum": "" }, "require": { @@ -6647,7 +6817,7 @@ "sftp", "storage" ], - "time": "2020-03-17T18:58:12+00:00" + "time": "2020-04-16T13:21:26+00:00" }, { "name": "lusitanian/oauth", @@ -8970,16 +9140,16 @@ }, { "name": "symfony/browser-kit", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/browser-kit.git", - "reference": "090ce406505149d6852a7c03b0346dec3b8cf612" + "reference": "e4b0dc1b100bf75b5717c5b451397f230a618a42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/browser-kit/zipball/090ce406505149d6852a7c03b0346dec3b8cf612", - "reference": "090ce406505149d6852a7c03b0346dec3b8cf612", + "url": "https://api.github.com/repos/symfony/browser-kit/zipball/e4b0dc1b100bf75b5717c5b451397f230a618a42", + "reference": "e4b0dc1b100bf75b5717c5b451397f230a618a42", "shasum": "" }, "require": { @@ -9025,20 +9195,34 @@ ], "description": "Symfony BrowserKit Component", "homepage": "https://symfony.com", - "time": "2020-02-23T10:00:59+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-03-28T10:15:50+00:00" }, { "name": "symfony/config", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "cbfef5ae91ccd3b06621c18d58cd355c68c87ae9" + "reference": "3f4a3de1af498ed0ea653d4dc2317794144e6ca4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/cbfef5ae91ccd3b06621c18d58cd355c68c87ae9", - "reference": "cbfef5ae91ccd3b06621c18d58cd355c68c87ae9", + "url": "https://api.github.com/repos/symfony/config/zipball/3f4a3de1af498ed0ea653d4dc2317794144e6ca4", + "reference": "3f4a3de1af498ed0ea653d4dc2317794144e6ca4", "shasum": "" }, "require": { @@ -9089,20 +9273,20 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2020-02-04T09:32:40+00:00" + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/dependency-injection", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "ebb2e882e8c9e2eb990aa61ddcd389848466e342" + "reference": "755b18859be26b90f4bf63753432d3387458bf31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/ebb2e882e8c9e2eb990aa61ddcd389848466e342", - "reference": "ebb2e882e8c9e2eb990aa61ddcd389848466e342", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/755b18859be26b90f4bf63753432d3387458bf31", + "reference": "755b18859be26b90f4bf63753432d3387458bf31", "shasum": "" }, "require": { @@ -9162,20 +9346,20 @@ ], "description": "Symfony DependencyInjection Component", "homepage": "https://symfony.com", - "time": "2020-02-29T09:50:10+00:00" + "time": "2020-03-30T10:09:30+00:00" }, { "name": "symfony/dom-crawler", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", - "reference": "11dcf08f12f29981bf770f097a5d64d65bce5929" + "reference": "4d0fb3374324071ecdd94898367a3fa4b5563162" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/11dcf08f12f29981bf770f097a5d64d65bce5929", - "reference": "11dcf08f12f29981bf770f097a5d64d65bce5929", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/4d0fb3374324071ecdd94898367a3fa4b5563162", + "reference": "4d0fb3374324071ecdd94898367a3fa4b5563162", "shasum": "" }, "require": { @@ -9223,20 +9407,34 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "time": "2020-02-29T10:05:28+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-03-29T19:12:22+00:00" }, { "name": "symfony/http-foundation", - "version": "v5.0.5", + "version": "v5.0.7", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "6f9c2ba72f4295d7ce6cf9f79dbb18036291d335" + "reference": "26fb006a2c7b6cdd23d52157b05f8414ffa417b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/6f9c2ba72f4295d7ce6cf9f79dbb18036291d335", - "reference": "6f9c2ba72f4295d7ce6cf9f79dbb18036291d335", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/26fb006a2c7b6cdd23d52157b05f8414ffa417b6", + "reference": "26fb006a2c7b6cdd23d52157b05f8414ffa417b6", "shasum": "" }, "require": { @@ -9278,20 +9476,20 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2020-02-14T07:43:07+00:00" + "time": "2020-03-30T14:14:32+00:00" }, { "name": "symfony/mime", - "version": "v5.0.5", + "version": "v5.0.7", "source": { "type": "git", "url": "https://github.com/symfony/mime.git", - "reference": "9b3e5b5e58c56bbd76628c952d2b78556d305f3c" + "reference": "481b7d6da88922fb1e0d86a943987722b08f3955" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mime/zipball/9b3e5b5e58c56bbd76628c952d2b78556d305f3c", - "reference": "9b3e5b5e58c56bbd76628c952d2b78556d305f3c", + "url": "https://api.github.com/repos/symfony/mime/zipball/481b7d6da88922fb1e0d86a943987722b08f3955", + "reference": "481b7d6da88922fb1e0d86a943987722b08f3955", "shasum": "" }, "require": { @@ -9340,20 +9538,20 @@ "mime", "mime-type" ], - "time": "2020-02-04T09:41:09+00:00" + "time": "2020-03-27T16:56:45+00:00" }, { "name": "symfony/options-resolver", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "9a02d6662660fe7bfadad63b5f0b0718d4c8b6b0" + "reference": "9072131b5e6e21203db3249c7db26b52897bc73e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/9a02d6662660fe7bfadad63b5f0b0718d4c8b6b0", - "reference": "9a02d6662660fe7bfadad63b5f0b0718d4c8b6b0", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/9072131b5e6e21203db3249c7db26b52897bc73e", + "reference": "9072131b5e6e21203db3249c7db26b52897bc73e", "shasum": "" }, "require": { @@ -9394,69 +9592,21 @@ "configuration", "options" ], - "time": "2020-01-04T13:00:46+00:00" - }, - { - "name": "symfony/polyfill-intl-idn", - "version": "v1.15.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf", - "reference": "47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "symfony/polyfill-mbstring": "^1.3", - "symfony/polyfill-php72": "^1.10" - }, - "suggest": { - "ext-intl": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.15-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Intl\\Idn\\": "" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ { - "name": "Laurent Bassin", - "email": "laurent@bassin.info" + "url": "https://github.com/fabpot", + "type": "github" }, { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" } ], - "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "idn", - "intl", - "polyfill", - "portable", - "shim" - ], - "time": "2020-03-09T19:04:49+00:00" + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/polyfill-php70", @@ -9517,73 +9667,18 @@ ], "time": "2020-02-27T09:26:54+00:00" }, - { - "name": "symfony/polyfill-php72", - "version": "v1.15.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "37b0976c78b94856543260ce09b460a7bc852747" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/37b0976c78b94856543260ce09b460a7bc852747", - "reference": "37b0976c78b94856543260ce09b460a7bc852747", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.15-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php72\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "time": "2020-02-27T09:26:54+00:00" - }, { "name": "symfony/stopwatch", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "abc08d7c48987829bac301347faa10f7e8bbf4fb" + "reference": "e0324d3560e4128270e3f08617480d9233d81cfc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/abc08d7c48987829bac301347faa10f7e8bbf4fb", - "reference": "abc08d7c48987829bac301347faa10f7e8bbf4fb", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/e0324d3560e4128270e3f08617480d9233d81cfc", + "reference": "e0324d3560e4128270e3f08617480d9233d81cfc", "shasum": "" }, "require": { @@ -9620,20 +9715,34 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2020-01-04T13:00:46+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-03-27T16:54:36+00:00" }, { "name": "symfony/yaml", - "version": "v4.4.5", + "version": "v4.4.7", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "94d005c176db2080e98825d98e01e8b311a97a88" + "reference": "ef166890d821518106da3560086bfcbeb4fadfec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/94d005c176db2080e98825d98e01e8b311a97a88", - "reference": "94d005c176db2080e98825d98e01e8b311a97a88", + "url": "https://api.github.com/repos/symfony/yaml/zipball/ef166890d821518106da3560086bfcbeb4fadfec", + "reference": "ef166890d821518106da3560086bfcbeb4fadfec", "shasum": "" }, "require": { @@ -9679,7 +9788,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2020-02-03T10:46:43+00:00" + "time": "2020-03-30T11:41:10+00:00" }, { "name": "theseer/fdomdocument", @@ -9763,16 +9872,16 @@ }, { "name": "vlucas/phpdotenv", - "version": "v2.6.1", + "version": "v2.6.3", "source": { "type": "git", "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "2a7dcf7e3e02dc5e701004e51a6f304b713107d5" + "reference": "df4c4d08a639be4ef5d6d1322868f9e477553679" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/2a7dcf7e3e02dc5e701004e51a6f304b713107d5", - "reference": "2a7dcf7e3e02dc5e701004e51a6f304b713107d5", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/df4c4d08a639be4ef5d6d1322868f9e477553679", + "reference": "df4c4d08a639be4ef5d6d1322868f9e477553679", "shasum": "" }, "require": { @@ -9780,8 +9889,14 @@ "symfony/polyfill-ctype": "^1.9" }, "require-dev": { + "ext-filter": "*", + "ext-pcre": "*", "phpunit/phpunit": "^4.8.35 || ^5.0" }, + "suggest": { + "ext-filter": "Required to use the boolean validator.", + "ext-pcre": "Required to use most of the library." + }, "type": "library", "extra": { "branch-alias": { @@ -9810,20 +9925,20 @@ "env", "environment" ], - "time": "2019-01-29T11:11:52+00:00" + "time": "2020-04-12T15:11:38+00:00" }, { "name": "webmozart/assert", - "version": "1.7.0", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "aed98a490f9a8f78468232db345ab9cf606cf598" + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/aed98a490f9a8f78468232db345ab9cf606cf598", - "reference": "aed98a490f9a8f78468232db345ab9cf606cf598", + "url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6", + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6", "shasum": "" }, "require": { @@ -9831,7 +9946,7 @@ "symfony/polyfill-ctype": "^1.8" }, "conflict": { - "vimeo/psalm": "<3.6.0" + "vimeo/psalm": "<3.9.1" }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^7.5.13" @@ -9858,7 +9973,7 @@ "check", "validate" ], - "time": "2020-02-14T12:15:55+00:00" + "time": "2020-04-18T12:12:48+00:00" }, { "name": "weew/helpers-array", @@ -9926,5 +10041,6 @@ "ext-zip": "*", "lib-libxml": "*" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" }