Skip to content

Commit b579ccf

Browse files
committed
Merge branch 'media-gallery-synchronization-metadata' of github.com:sivaschenko/magento2 into asi-delivery-24
2 parents 619bd28 + d99fd2b commit b579ccf

File tree

21 files changed

+466
-166
lines changed

21 files changed

+466
-166
lines changed

app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
use Magento\Framework\Filesystem\Driver\File;
1515
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
1616
use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory;
17-
use Magento\MediaGalleryMetadataApi\Api\ExtractMetadataInterface;
1817
use Magento\MediaGallerySynchronization\Model\Filesystem\GetFileInfo;
19-
use Magento\MediaGallerySynchronization\Model\GetContentHash;
18+
use Magento\MediaGallerySynchronizationApi\Model\CreateAssetFromFileInterface;
2019

2120
/**
2221
* Create media asset object based on the file information
2322
*/
24-
class CreateAssetFromFile
23+
class CreateAssetFromFile implements CreateAssetFromFileInterface
2524
{
2625
/**
2726
* @var Filesystem
@@ -43,11 +42,6 @@ class CreateAssetFromFile
4342
*/
4443
private $getContentHash;
4544

46-
/**
47-
* @var ExtractMetadataInterface
48-
*/
49-
private $extractMetadata;
50-
5145
/**
5246
* @var GetFileInfo
5347
*/
@@ -58,46 +52,36 @@ class CreateAssetFromFile
5852
* @param File $driver
5953
* @param AssetInterfaceFactory $assetFactory
6054
* @param GetContentHash $getContentHash
61-
* @param ExtractMetadataInterface $extractMetadata
6255
* @param GetFileInfo $getFileInfo
6356
*/
6457
public function __construct(
6558
Filesystem $filesystem,
6659
File $driver,
6760
AssetInterfaceFactory $assetFactory,
6861
GetContentHash $getContentHash,
69-
ExtractMetadataInterface $extractMetadata,
7062
GetFileInfo $getFileInfo
7163
) {
7264
$this->filesystem = $filesystem;
7365
$this->driver = $driver;
7466
$this->assetFactory = $assetFactory;
7567
$this->getContentHash = $getContentHash;
76-
$this->extractMetadata = $extractMetadata;
7768
$this->getFileInfo = $getFileInfo;
7869
}
7970

8071
/**
81-
* Create and format media asset object
82-
*
83-
* @param string $path
84-
* @return AssetInterface
85-
* @throws FileSystemException
72+
* @inheritdoc
8673
*/
8774
public function execute(string $path): AssetInterface
8875
{
8976
$absolutePath = $this->getMediaDirectory()->getAbsolutePath($path);
9077
$file = $this->getFileInfo->execute($absolutePath);
9178
[$width, $height] = getimagesize($absolutePath);
9279

93-
$metadata = $this->extractMetadata->execute($absolutePath);
94-
9580
return $this->assetFactory->create(
9681
[
9782
'id' => null,
9883
'path' => $path,
99-
'title' => $metadata->getTitle() ?: $file->getBasename(),
100-
'description' => $metadata->getDescription(),
84+
'title' => $file->getBasename(),
10185
'width' => $width,
10286
'height' => $height,
10387
'hash' => $this->getHash($path),

app/code/Magento/MediaGallerySynchronization/Model/GetAssetFromPath.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
1313
use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory;
1414
use Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface;
15+
use Magento\MediaGallerySynchronizationApi\Model\CreateAssetFromFileInterface;
1516

1617
/**
1718
* Create media asset object based on the file information
@@ -29,19 +30,19 @@ class GetAssetFromPath
2930
private $assetFactory;
3031

3132
/**
32-
* @var CreateAssetFromFile
33+
* @var CreateAssetFromFileInterface
3334
*/
3435
private $createAssetFromFile;
3536

3637
/**
3738
* @param AssetInterfaceFactory $assetFactory
3839
* @param GetAssetsByPathsInterface $getMediaGalleryAssetByPath
39-
* @param CreateAssetFromFile $createAssetFromFile
40+
* @param CreateAssetFromFileInterface $createAssetFromFile
4041
*/
4142
public function __construct(
4243
AssetInterfaceFactory $assetFactory,
4344
GetAssetsByPathsInterface $getMediaGalleryAssetByPath,
44-
CreateAssetFromFile $createAssetFromFile
45+
CreateAssetFromFileInterface $createAssetFromFile
4546
) {
4647
$this->assetFactory = $assetFactory;
4748
$this->getAssetsByPaths = $getMediaGalleryAssetByPath;

app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/SynchronizeFilesTest.php

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

1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Framework\Exception\FileSystemException;
12+
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\Filesystem;
1314
use Magento\Framework\Filesystem\Directory\WriteInterface;
1415
use Magento\Framework\Filesystem\DriverInterface;
15-
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
16-
use Magento\MediaGalleryApi\Api\Data\KeywordInterface;
1716
use Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface;
1817
use Magento\MediaGallerySynchronizationApi\Api\SynchronizeFilesInterface;
19-
use Magento\MediaGalleryApi\Api\GetAssetsKeywordsInterface;
2018
use Magento\TestFramework\Helper\Bootstrap;
2119
use PHPUnit\Framework\TestCase;
2220

@@ -45,11 +43,6 @@ class SynchronizeFilesTest extends TestCase
4543
*/
4644
private $mediaDirectory;
4745

48-
/**
49-
* @var GetAssetsKeywordsInterface
50-
*/
51-
private $getAssetKeywords;
52-
5346
/**
5447
* @inheritdoc
5548
*/
@@ -58,7 +51,6 @@ protected function setUp(): void
5851
$this->driver = Bootstrap::getObjectManager()->get(DriverInterface::class);
5952
$this->synchronizeFiles = Bootstrap::getObjectManager()->get(SynchronizeFilesInterface::class);
6053
$this->getAssetsByPath = Bootstrap::getObjectManager()->get(GetAssetsByPathsInterface::class);
61-
$this->getAssetKeywords = Bootstrap::getObjectManager()->get(GetAssetsKeywordsInterface::class);
6254
$this->mediaDirectory = Bootstrap::getObjectManager()->get(Filesystem::class)
6355
->getDirectoryWrite(DirectoryList::MEDIA);
6456
}
@@ -67,18 +59,16 @@ protected function setUp(): void
6759
* Test for SynchronizeFiles::execute
6860
*
6961
* @dataProvider filesProvider
70-
* @param null|string $file
71-
* @param null|string $title
72-
* @param null|string $description
73-
* @param null|array $keywords
62+
* @param string $file
63+
* @param string $title
64+
* @param string $source
7465
* @throws FileSystemException
75-
* @throws \Magento\Framework\Exception\LocalizedException
66+
* @throws LocalizedException
7667
*/
7768
public function testExecute(
78-
?string $file,
79-
?string $title,
80-
?string $description,
81-
?array $keywords
69+
string $file,
70+
string $title,
71+
string $source
8272
): void {
8373
$path = realpath(__DIR__ . '/../_files/' . $file);
8474
$modifiableFilePath = $this->mediaDirectory->getAbsolutePath($file);
@@ -89,12 +79,10 @@ public function testExecute(
8979

9080
$this->synchronizeFiles->execute([$file]);
9181

92-
$loadedAssets = $this->getAssetsByPath->execute([$file])[0];
93-
$loadedKeywords = $this->getKeywords($loadedAssets) ?: null;
82+
$loadedAsset = $this->getAssetsByPath->execute([$file])[0];
9483

95-
$this->assertEquals($title, $loadedAssets->getTitle());
96-
$this->assertEquals($description, $loadedAssets->getDescription());
97-
$this->assertEquals($keywords, $loadedKeywords);
84+
$this->assertEquals($title, $loadedAsset->getTitle());
85+
$this->assertEquals($source, $loadedAsset->getSource());
9886

9987
$this->driver->deleteFile($modifiableFilePath);
10088
}
@@ -110,42 +98,8 @@ public function filesProvider(): array
11098
[
11199
'/magento.jpg',
112100
'magento',
113-
null,
114-
null
115-
],
116-
[
117-
'/magento_metadata.jpg',
118-
'Title of the magento image',
119-
'Description of the magento image',
120-
[
121-
'magento',
122-
'mediagallerymetadata'
123-
]
101+
'Local'
124102
]
125103
];
126104
}
127-
128-
/**
129-
* Key asset keywords
130-
*
131-
* @param AssetInterface $asset
132-
* @return string[]
133-
*/
134-
private function getKeywords(AssetInterface $asset): array
135-
{
136-
$assetKeywords = $this->getAssetKeywords->execute([$asset->getId()]);
137-
138-
if (empty($assetKeywords)) {
139-
return [];
140-
}
141-
142-
$keywords = current($assetKeywords)->getKeywords();
143-
144-
return array_map(
145-
function (KeywordInterface $keyword) {
146-
return $keyword->getKeyword();
147-
},
148-
$keywords
149-
);
150-
}
151105
}

app/code/Magento/MediaGallerySynchronization/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"magento/framework": "*",
77
"magento/module-media-gallery-api": "*",
88
"magento/module-media-gallery-synchronization-api": "*",
9-
"magento/framework-message-queue": "*",
10-
"magento/module-media-gallery-metadata-api": "*"
9+
"magento/framework-message-queue": "*"
1110
},
1211
"type": "magento2-module",
1312
"license": [

app/code/Magento/MediaGallerySynchronization/etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
<preference for="Magento\MediaGallerySynchronizationApi\Api\SynchronizeInterface" type="Magento\MediaGallerySynchronization\Model\Synchronize"/>
1010
<preference for="Magento\MediaGallerySynchronizationApi\Model\FetchBatchesInterface" type="Magento\MediaGallerySynchronization\Model\FetchBatches"/>
1111
<preference for="Magento\MediaGallerySynchronizationApi\Api\SynchronizeFilesInterface" type="Magento\MediaGallerySynchronization\Model\SynchronizeFiles"/>
12+
<preference for="Magento\MediaGallerySynchronizationApi\Model\CreateAssetFromFileInterface" type="Magento\MediaGallerySynchronization\Model\CreateAssetFromFile"/>
1213
<type name="Magento\MediaGallerySynchronizationApi\Model\ImportFilesComposite">
1314
<arguments>
1415
<argument name="importers" xsi:type="array">
15-
<item name="0" xsi:type="object">Magento\MediaGallerySynchronization\Model\ImportMediaAsset</item>
16-
<item name="1" xsi:type="object">Magento\MediaGallerySynchronization\Model\ImportImageFileKeywords</item>
16+
<item name="10" xsi:type="object">Magento\MediaGallerySynchronization\Model\ImportMediaAsset</item>
1717
</argument>
1818
</arguments>
1919
</type>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaGallerySynchronizationApi\Model;
9+
10+
use Magento\Framework\Exception\FileSystemException;
11+
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
12+
13+
/**
14+
* Create media asset object from the media file
15+
*/
16+
interface CreateAssetFromFileInterface
17+
{
18+
/**
19+
* Create media asset object from the media file
20+
*
21+
* @param string $path
22+
* @return AssetInterface
23+
* @throws FileSystemException
24+
*/
25+
public function execute(string $path): AssetInterface;
26+
}

app/code/Magento/MediaGallerySynchronizationApi/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"description": "Magento module responsible for the media gallery synchronization implementation API",
44
"require": {
55
"php": "~7.3.0||~7.4.0",
6-
"magento/framework": "*"
6+
"magento/framework": "*",
7+
"magento/module-media-gallery-api": "*"
78
},
89
"type": "magento2-module",
910
"license": [

0 commit comments

Comments
 (0)