Skip to content

Commit

Permalink
ENGCOM-7954: Apply review suggestion to the media modules #29396
Browse files Browse the repository at this point in the history
 - Merge Pull Request #29396 from sivaschenko/magento2:media-review-suggestions
 - Merged commits:
   1. 1a7149b
  • Loading branch information
magento-engcom-team committed Aug 5, 2020
2 parents 00f8a8c + 1a7149b commit 4e891cc
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 130 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Magento\MediaContentSynchronizationApi\Model;

use Magento\MediaContentSynchronizationApi\Api\SynchronizerInterface;
use Magento\MediaContentSynchronizationApi\Api\SynchronizeInterface;

/**
* A pool that handles content and assets synchronization.
Expand All @@ -18,20 +18,20 @@ class SynchronizerPool
/**
* Content with assets synchronizers
*
* @var SynchronizerInterface[]
* @var SynchronizeInterface[]
*/
private $synchronizers;

/**
* @param SynchronizerInterface[] $synchronizers
* @param SynchronizeInterface[] $synchronizers
*/
public function __construct(
array $synchronizers = []
) {
foreach ($synchronizers as $synchronizer) {
if (!$synchronizer instanceof SynchronizerInterface) {
if (!$synchronizer instanceof SynchronizeInterface) {
throw new \InvalidArgumentException(
get_class($synchronizer) . ' must implement ' . SynchronizerInterface::class
get_class($synchronizer) . ' must implement ' . SynchronizeInterface::class
);
}
}
Expand All @@ -42,7 +42,7 @@ public function __construct(
/**
* Get all synchronizers from the pool
*
* @return SynchronizerInterface[]
* @return SynchronizeInterface[]
*/
public function get(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory;
use Magento\MediaContentApi\Api\UpdateContentAssetLinksInterface;
use Magento\MediaContentApi\Model\GetEntityContentsInterface;
use Magento\MediaContentSynchronizationApi\Api\SynchronizerInterface;
use Magento\MediaContentSynchronizationApi\Api\SynchronizeInterface;
use Magento\MediaGallerySynchronizationApi\Model\FetchBatchesInterface;

/**
* Synchronize category content with assets
*/
class Category implements SynchronizerInterface
class Category implements SynchronizeInterface
{
private const CONTENT_TYPE = 'catalog_category';
private const TYPE = 'entityType';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory;
use Magento\MediaContentApi\Api\UpdateContentAssetLinksInterface;
use Magento\MediaContentApi\Model\GetEntityContentsInterface;
use Magento\MediaContentSynchronizationApi\Api\SynchronizerInterface;
use Magento\MediaContentSynchronizationApi\Api\SynchronizeInterface;
use Magento\MediaGallerySynchronizationApi\Model\FetchBatchesInterface;

/**
* Synchronize product content with assets
*/
class Product implements SynchronizerInterface
class Product implements SynchronizeInterface
{
private const CONTENT_TYPE = 'catalog_product';
private const TYPE = 'entityType';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory;
use Magento\MediaContentApi\Api\UpdateContentAssetLinksInterface;
use Magento\MediaContentSynchronizationApi\Api\SynchronizerInterface;
use Magento\MediaContentSynchronizationApi\Api\SynchronizeInterface;
use Magento\MediaGallerySynchronizationApi\Model\FetchBatchesInterface;

/**
* Synchronize block content with assets
*/
class Block implements SynchronizerInterface
class Block implements SynchronizeInterface
{
private const CONTENT_TYPE = 'cms_block';
private const TYPE = 'entityType';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory;
use Magento\MediaContentApi\Api\UpdateContentAssetLinksInterface;
use Magento\MediaContentSynchronizationApi\Api\SynchronizerInterface;
use Magento\MediaContentSynchronizationApi\Api\SynchronizeInterface;
use Magento\MediaGallerySynchronizationApi\Model\FetchBatchesInterface;

/**
* Synchronize page content with assets
*/
class Page implements SynchronizerInterface
class Page implements SynchronizeInterface
{
private const CONTENT_TYPE = 'cms_page';
private const TYPE = 'entityType';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,12 @@ public function __construct(
public function execute(string $path): MetadataInterface
{
try {
return $this->extractMetadata($path);
return $this->readSegments($this->fileReader->execute($path));
} catch (\Exception $exception) {
return $this->metadataFactory->create();
}
}

/**
* Extract metadata from file
*
* @param string $path
* @return MetadataInterface
*/
private function extractMetadata(string $path): MetadataInterface
{
try {
$file = $this->fileReader->execute($path);
} catch (\Exception $exception) {
throw new LocalizedException(
__('Could not parse the image file for metadata: %path', ['path' => $path])
);
}

return $this->readSegments($file);
}

/**
* Read file segments by given segmentReader
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory;
use Magento\MediaGalleryMetadataApi\Api\ExtractMetadataInterface;
use Magento\MediaGallerySynchronization\Model\Filesystem\SplFileInfoFactory;
use Magento\MediaGallerySynchronizationApi\Model\GetContentHashInterface;
use Magento\MediaGallerySynchronization\Model\GetContentHash;

/**
* Create media asset object based on the file information
Expand Down Expand Up @@ -50,7 +50,7 @@ class CreateAssetFromFile
private $assetFactory;

/**
* @var GetContentHashInterface
* @var GetContentHash
*/
private $getContentHash;

Expand All @@ -69,7 +69,7 @@ class CreateAssetFromFile
* @param File $driver
* @param TimezoneInterface $date
* @param AssetInterfaceFactory $assetFactory
* @param GetContentHashInterface $getContentHash
* @param GetContentHash $getContentHash
* @param ExtractMetadataInterface $extractMetadata
* @param SplFileInfoFactory $splFileInfoFactory
*/
Expand All @@ -78,7 +78,7 @@ public function __construct(
File $driver,
TimezoneInterface $date,
AssetInterfaceFactory $assetFactory,
GetContentHashInterface $getContentHash,
GetContentHash $getContentHash,
ExtractMetadataInterface $extractMetadata,
SplFileInfoFactory $splFileInfoFactory
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

namespace Magento\MediaGallerySynchronization\Model;

use Magento\MediaGallerySynchronizationApi\Model\GetContentHashInterface;

/**
* Get hashed value of image content.
*/
class GetContentHash implements GetContentHashInterface
class GetContentHash
{
/**
* Return the hash value of the given filepath.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\MediaGallerySynchronizationApi\Model\GetContentHashInterface;
use Magento\MediaGallerySynchronization\Model\GetContentHash;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

/**
* Test for GetContentHashInterface.
* Test for GetContentHash.
*/
class GetContentHashTest extends TestCase
{
/**
* @var GetContentHashInterface
* @var GetContentHash
*/
private $getContentHash;

Expand All @@ -33,12 +33,12 @@ class GetContentHashTest extends TestCase
*/
protected function setUp(): void
{
$this->getContentHash = Bootstrap::getObjectManager()->get(GetContentHashInterface::class);
$this->getContentHash = Bootstrap::getObjectManager()->get(GetContentHash::class);
$this->driver = Bootstrap::getObjectManager()->get(DriverInterface::class);
}

/**
* Test for GetContentHashInterface::execute
* Test for GetContentHash::execute
*
* @dataProvider filesProvider
* @param string $firstFile
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/MediaGallerySynchronization/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<preference for="Magento\MediaGallerySynchronizationApi\Api\SynchronizeInterface" type="Magento\MediaGallerySynchronization\Model\Synchronize"/>
<preference for="Magento\MediaGallerySynchronizationApi\Model\FetchBatchesInterface" type="Magento\MediaGallerySynchronization\Model\FetchBatches"/>
<preference for="Magento\MediaGallerySynchronizationApi\Api\SynchronizeFilesInterface" type="Magento\MediaGallerySynchronization\Model\SynchronizeFiles"/>
<preference for="Magento\MediaGallerySynchronizationApi\Model\GetContentHashInterface" type="Magento\MediaGallerySynchronization\Model\GetContentHash"/>
<type name="Magento\MediaGallerySynchronizationApi\Model\ImportFilesComposite">
<arguments>
<argument name="importers" xsi:type="array">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,32 @@
*/
class UsedIn implements OptionSourceInterface
{
/**
* @var array
*/
private $options;

/**
* @param array $options
*/
public function __construct(array $options = [])
{
$this->options = $options;
}

/**
* @inheritdoc
*/
public function toOptionArray(): array
{
return $this->options;
return [
'cms_page' => [
'value' => 'cms_page',
'label' => 'Pages'
],
'catalog_category' => [
'value' => 'catalog_category',
'label' => 'Categories'
],
'cms_block' => [
'value' => 'cms_block',
'label' => 'Blocks'
],
'catalog_product' => [
'value' => 'catalog_product',
'label' => 'Products'
],
'not_used' => [
'value' => 'not_used',
'label' => 'Not used anywhere'
]
];
}
}
26 changes: 0 additions & 26 deletions app/code/Magento/MediaGalleryUi/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,4 @@
<argument name="collectionProcessor" xsi:type="object">Magento\MediaGalleryUi\Model\Api\SearchCriteria\CollectionProcessor</argument>
</arguments>
</type>
<type name="Magento\MediaGalleryUi\Ui\Component\Listing\Filters\Options\UsedIn">
<arguments>
<argument name="options" xsi:type="array">
<item name="cms_page" xsi:type="array">
<item name="value" xsi:type="string">cms_page</item>
<item name="label" xsi:type="string" translate="true">Pages</item>
</item>
<item name="catalog_category" xsi:type="array">
<item name="value" xsi:type="string">catalog_category</item>
<item name="label" xsi:type="string" translate="true">Categories</item>
</item>
<item name="cms_block" xsi:type="array">
<item name="value" xsi:type="string">cms_block</item>
<item name="label" xsi:type="string" translate="true">Blocks</item>
</item>
<item name="catalog_product" xsi:type="array">
<item name="value" xsi:type="string">catalog_product</item>
<item name="label" xsi:type="string" translate="true">Products</item>
</item>
<item name="not_used" xsi:type="array">
<item name="value" xsi:type="string">not_used</item>
<item name="label" xsi:type="string" translate="true">Not used anywhere</item>
</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit 4e891cc

Please sign in to comment.