Skip to content

Commit 5f82525

Browse files
author
Gabriel Galvao da Gama
committed
Updated names
1 parent 545f886 commit 5f82525

File tree

11 files changed

+97
-102
lines changed

11 files changed

+97
-102
lines changed

app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<preference for="Magento\MediaContentApi\Api\Data\ContentIdentityInterface" type="Magento\MediaContent\Model\ContentIdentity"/>
1717
<preference for="Magento\MediaContentApi\Api\Data\ContentAssetLinkInterface" type="Magento\MediaContent\Model\ContentAssetLink"/>
1818
<preference for="Magento\MediaContentApi\Model\SearchPatternConfigInterface" type="Magento\MediaContent\Model\Content\SearchPatternConfig"/>
19-
<preference for="Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface" type="Magento\MediaContent\Model\GetAssetIdByContentFieldComposite"/>
19+
<preference for="Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface" type="Magento\MediaContentApi\Model\Composite\GetAssetIdsByContentField"/>
2020
<type name="Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface">
2121
<plugin name="remove_media_content_after_asset_is_removed_by_path" type="Magento\MediaContent\Plugin\MediaGalleryAssetDeleteByPath" />
2222
</type>

app/code/Magento/MediaContentApi/Api/GetAssetIdByContentFieldInterface.php renamed to app/code/Magento/MediaContentApi/Api/GetAssetIdsByContentFieldInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
use Magento\Framework\Exception\InvalidArgumentException;
1111

1212
/**
13-
* @api
1413
* Interface used to return Asset id by content field.
1514
*/
16-
interface GetAssetIdByContentFieldInterface
15+
interface GetAssetIdsByContentFieldInterface
1716
{
1817
/**
1918
* This function returns asset ids by content field
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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\MediaContentApi\Model\Composite;
9+
10+
use Magento\Framework\Exception\InvalidArgumentException;
11+
use Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface as GetAssetIdsByContentFieldApiInterface;
12+
use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface;
13+
14+
/**
15+
* Class responsible to return Asset ids by content field
16+
*/
17+
class GetAssetIdsByContentField implements GetAssetIdsByContentFieldApiInterface
18+
{
19+
/**
20+
* @var GetAssetIdsByContentFieldInterface[]
21+
*/
22+
private $fieldHandlers;
23+
24+
/**
25+
* GetAssetIdsByContentField constructor.
26+
*
27+
* @param array $fieldHandlers
28+
*/
29+
public function __construct($fieldHandlers = [])
30+
{
31+
$this->fieldHandlers = $fieldHandlers;
32+
}
33+
34+
/**
35+
* @inheritDoc
36+
*/
37+
public function execute(string $field, string $value): array
38+
{
39+
if (!array_key_exists($field, $this->fieldHandlers)) {
40+
throw new InvalidArgumentException(__('The field argument is invalid.'));
41+
}
42+
$ids = [];
43+
/** @var GetAssetIdsByContentFieldInterface $fieldHandlers */
44+
foreach ($this->fieldHandlers[$field] as $fieldHandlers) {
45+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
46+
$ids = array_merge($ids, $fieldHandlers->execute($value));
47+
}
48+
return array_unique($ids);
49+
}
50+
}

app/code/Magento/MediaContentApi/Model/GetAssetIdByContentFieldInterface.php renamed to app/code/Magento/MediaContentApi/Model/GetAssetIdsByContentFieldInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Interface used to return Asset id by content field.
1515
*/
16-
interface GetAssetIdByContentFieldInterface
16+
interface GetAssetIdsByContentFieldInterface
1717
{
1818
/**
1919
* This function returns asset ids by content field

app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php renamed to app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\MediaContentCatalog\Model;
8+
namespace Magento\MediaContentCatalog\Model\ResourceModel;
99

1010
use Magento\Catalog\Api\CategoryManagementInterface;
1111
use Magento\Framework\App\ResourceConnection;
1212
use Magento\Framework\Exception\LocalizedException;
13-
use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface;
13+
use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface;
1414
use Magento\Store\Api\GroupRepositoryInterface;
1515
use Magento\Store\Api\StoreRepositoryInterface;
1616

1717
/**
1818
* Class responsible to return Asset id by category store
1919
*/
20-
class GetAssetIdByCategoryStore implements GetAssetIdByContentFieldInterface
20+
class GetAssetIdsByCategoryStore implements GetAssetIdsByContentFieldInterface
2121
{
2222
private const TABLE_CONTENT_ASSET = 'media_content_asset';
2323
private const TABLE_CATALOG_CATEGORY = 'catalog_category_entity';
@@ -39,7 +39,7 @@ class GetAssetIdByCategoryStore implements GetAssetIdByContentFieldInterface
3939
private $storeGroupRepository;
4040

4141
/**
42-
* GetAssetIdByProductStore constructor.
42+
* GetAssetIdsByCategoryStore constructor.
4343
*
4444
* @param ResourceConnection $resource
4545
* @param StoreRepositoryInterface $storeRepository
@@ -88,7 +88,7 @@ private function getCategoryIdsByRootCategory(int $rootCategoryId): array
8888
$result = $this->getCategoryIdsAndPath();
8989

9090
$result = array_filter($result, function ($item) use ($rootCategoryId) {
91-
$pathArray = explode("/", $item['path']);
91+
$pathArray = explode('/', $item['path']);
9292
$isInPath = false;
9393
foreach ($pathArray as $id) {
9494
if ($id == $rootCategoryId) {

app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php renamed to app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByEavContentField.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\MediaContentCatalog\Model;
8+
namespace Magento\MediaContentCatalog\Model\ResourceModel;
99

1010
use Magento\Eav\Model\Config;
1111
use Magento\Framework\App\ResourceConnection;
12-
use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface;
12+
use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface;
1313

1414
/**
1515
* Class responsible to return Asset id by eav content field
1616
*/
17-
class GetAssetIdByEavContentField implements GetAssetIdByContentFieldInterface
17+
class GetAssetIdsByEavContentField implements GetAssetIdsByContentFieldInterface
1818
{
1919
private const TABLE_CONTENT_ASSET = 'media_content_asset';
2020

@@ -44,7 +44,7 @@ class GetAssetIdByEavContentField implements GetAssetIdByContentFieldInterface
4444
private $valueMap;
4545

4646
/**
47-
* GetAssetIdByEavContentStatus constructor.
47+
* GetAssetIdsByEavContentField constructor.
4848
*
4949
* @param ResourceConnection $resource
5050
* @param Config $config
@@ -71,7 +71,7 @@ public function __construct(
7171
*/
7272
public function execute(string $value): array
7373
{
74-
$statusAttribute = $this->config->getAttribute($this->entityType, $this->attributeCode);
74+
$attribute = $this->config->getAttribute($this->entityType, $this->attributeCode);
7575

7676
$sql = $this->connection->getConnection()->select()->from(
7777
['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)],
@@ -80,10 +80,10 @@ public function execute(string $value): array
8080
'entity_type = ?',
8181
$this->entityType
8282
)->joinInner(
83-
['entity_eav_type' => $statusAttribute->getBackendTable()],
84-
'asset_content_table.entity_id = entity_eav_type.' . $statusAttribute->getEntityIdField() .
83+
['entity_eav_type' => $attribute->getBackendTable()],
84+
'asset_content_table.entity_id = entity_eav_type.' . $attribute->getEntityIdField() .
8585
' AND entity_eav_type.attribute_id = ' .
86-
$statusAttribute->getAttributeId(),
86+
$attribute->getAttributeId(),
8787
[]
8888
)->where(
8989
'entity_eav_type.value = ?',
@@ -101,9 +101,6 @@ public function execute(string $value): array
101101
*/
102102
private function getValueFromMap(string $value): string
103103
{
104-
if (count($this->valueMap) > 0 && array_key_exists($value, $this->valueMap)) {
105-
return $this->valueMap[$value];
106-
}
107-
return $value;
104+
return $this->valueMap[$value] ?? $value;
108105
}
109106
}

app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php renamed to app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByProductStore.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\MediaContentCatalog\Model;
8+
namespace Magento\MediaContentCatalog\Model\ResourceModel;
99

1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Framework\Exception\LocalizedException;
12-
use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface;
12+
use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface;
1313
use Magento\Store\Api\StoreRepositoryInterface;
1414

1515
/**
1616
* Class responsible to return Asset ids by product store
1717
*/
18-
class GetAssetIdByProductStore implements GetAssetIdByContentFieldInterface
18+
class GetAssetIdsByProductStore implements GetAssetIdsByContentFieldInterface
1919
{
2020
private const TABLE_CONTENT_ASSET = 'media_content_asset';
2121
private const ENTITY_TYPE = 'catalog_product';
@@ -34,7 +34,7 @@ class GetAssetIdByProductStore implements GetAssetIdByContentFieldInterface
3434
private $storeRepository;
3535

3636
/**
37-
* GetAssetIdByProductStore constructor.
37+
* GetAssetIdsByProductStore constructor.
3838
*
3939
* @param ResourceConnection $resource
4040
* @param StoreRepositoryInterface $storeRepository

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</argument>
4747
</arguments>
4848
</type>
49-
<virtualType name="Magento\MediaContentCatalog\Model\GetAssetIdByProductStatus" type="Magento\MediaContentCatalog\Model\GetAssetIdByEavContentField">
49+
<virtualType name="Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByProductStatus" type="Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByEavContentField">
5050
<arguments>
5151
<argument name="attributeCode" xsi:type="string">status</argument>
5252
<argument name="entityType" xsi:type="string">catalog_product</argument>
@@ -56,28 +56,28 @@
5656
</argument>
5757
</arguments>
5858
</virtualType>
59-
<virtualType name="Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStatus" type="Magento\MediaContentCatalog\Model\GetAssetIdByEavContentField">
59+
<virtualType name="Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByCategoryStatus" type="Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByEavContentField">
6060
<arguments>
6161
<argument name="attributeCode" xsi:type="string">is_active</argument>
6262
<argument name="entityType" xsi:type="string">catalog_category</argument>
6363
</arguments>
6464
</virtualType>
65-
<type name="Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface">
65+
<type name="Magento\MediaContentApi\Model\Composite\GetAssetIdsByContentField">
6666
<arguments>
67-
<argument name="getAssetIdByContentFieldArray" xsi:type="array">
67+
<argument name="fieldHandlers" xsi:type="array">
6868
<item name="content_status" xsi:type="array">
69-
<item name="getAssetIdByProductStatus" xsi:type="object">Magento\MediaContentCatalog\Model\GetAssetIdByProductStatus</item>
70-
<item name="getAssetIdByCategoryStatus" xsi:type="object">Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStatus</item>
69+
<item name="getAssetIdsByProductStatus" xsi:type="object">Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByProductStatus</item>
70+
<item name="getAssetIdsByCategoryStatus" xsi:type="object">Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByCategoryStatus</item>
7171
</item>
7272
</argument>
7373
</arguments>
7474
</type>
75-
<type name="Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface">
75+
<type name="Magento\MediaContentApi\Model\Composite\GetAssetIdsByContentField">
7676
<arguments>
77-
<argument name="getAssetIdByContentFieldArray" xsi:type="array">
77+
<argument name="fieldHandlers" xsi:type="array">
7878
<item name="store_id" xsi:type="array">
79-
<item name="getAssetIdByProductStore" xsi:type="object">Magento\MediaContentCatalog\Model\GetAssetIdByProductStore</item>
80-
<item name="getAssetIdByCategoryStore" xsi:type="object">Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStore</item>
79+
<item name="getAssetIdsByProductStore" xsi:type="object">Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByProductStore</item>
80+
<item name="getAssetIdsByCategoryStore" xsi:type="object">Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByCategoryStore</item>
8181
</item>
8282
</argument>
8383
</arguments>

app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php renamed to app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentField.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\MediaContentCms\Model;
8+
namespace Magento\MediaContentCms\Model\ResourceModel;
99

1010
use Magento\Framework\App\ResourceConnection;
11-
use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface;
11+
use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface;
1212

1313
/**
1414
* Class responsible to return Asset id by content field
1515
*/
16-
class GetAssetIdByContentField implements GetAssetIdByContentFieldInterface
16+
class GetAssetIdsByContentField implements GetAssetIdsByContentFieldInterface
1717
{
1818
private const TABLE_CONTENT_ASSET = 'media_content_asset';
1919

@@ -43,7 +43,7 @@ class GetAssetIdByContentField implements GetAssetIdByContentFieldInterface
4343
private $idColumn;
4444

4545
/**
46-
* GetAssetIdByContentField constructor.
46+
* GetAssetIdsByContentField constructor.
4747
*
4848
* @param ResourceConnection $resource
4949
* @param string $entityType

0 commit comments

Comments
 (0)