Skip to content

Commit 8955147

Browse files
author
Gabriel Galvao da Gama
committed
Implemented suggestions
1 parent e0a777b commit 8955147

File tree

12 files changed

+70
-51
lines changed

12 files changed

+70
-51
lines changed

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

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

88
namespace Magento\MediaContent\Model;
99

10+
use Magento\Framework\Exception\InvalidArgumentException;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface as GetAssetIdByContentFieldApiInterface;
1013
use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface;
1114

1215
/**
1316
* Class responsible to return Asset ids by content field
1417
*/
15-
class GetAssetIdByContentFieldComposite implements GetAssetIdByContentFieldInterface
18+
class GetAssetIdByContentFieldComposite implements GetAssetIdByContentFieldApiInterface
1619
{
1720
/**
1821
* @var GetAssetIdByContentFieldInterface[]
@@ -32,10 +35,13 @@ public function __construct($getAssetIdByContentFieldArray = [])
3235
/**
3336
* @inheritDoc
3437
*/
35-
public function execute(string $value): array
38+
public function execute(string $field, string $value): array
3639
{
40+
if (!array_key_exists($field, $this->getAssetIdByContentFieldArray)) {
41+
throw new InvalidArgumentException(__('The field argument is invalid.'));
42+
}
3743
$ids = [];
38-
foreach ($this->getAssetIdByContentFieldArray as $getAssetIdByContentField) {
44+
foreach ($this->getAssetIdByContentFieldArray[$field] as $getAssetIdByContentField) {
3945
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
4046
$ids = array_merge($ids, $getAssetIdByContentField->execute($value));
4147
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +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"/>
1920
<type name="Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface">
2021
<plugin name="remove_media_content_after_asset_is_removed_by_path" type="Magento\MediaContent\Plugin\MediaGalleryAssetDeleteByPath" />
2122
</type>
@@ -43,6 +44,4 @@
4344
<argument name="data" xsi:type="object">Magento\MediaContent\Model\Content\Config\Data</argument>
4445
</arguments>
4546
</type>
46-
<virtualType name="Magento\MediaContent\Model\GetAssetIdByContentStatusComposite" type="Magento\MediaContent\Model\GetAssetIdByContentFieldComposite"/>
47-
<virtualType name="Magento\MediaContent\Model\GetAssetIdByContentStoreComposite" type="Magento\MediaContent\Model\GetAssetIdByContentFieldComposite"/>
4847
</config>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\Api;
9+
10+
use Magento\Framework\Exception\InvalidArgumentException;
11+
12+
/**
13+
* @api
14+
* Interface used to return Asset id by content field.
15+
*/
16+
interface GetAssetIdByContentFieldInterface
17+
{
18+
/**
19+
* This function returns asset ids by content field
20+
*
21+
* @param string $field
22+
* @param string $value
23+
* @throws InvalidArgumentException
24+
* @return int[]
25+
*/
26+
public function execute(string $field, string $value): array;
27+
}

app/code/Magento/MediaContentApi/Model/GetAssetIdByContentFieldInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace Magento\MediaContentApi\Model;
99

10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
1013
/**
1114
* Interface used to return Asset id by content field.
1215
*/
@@ -17,6 +20,8 @@ interface GetAssetIdByContentFieldInterface
1720
*
1821
* @param string $value
1922
* @return int[]
23+
* @throws LocalizedException
24+
* @throws NoSuchEntityException
2025
*/
2126
public function execute(string $value): array;
2227
}

app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public function __construct(
5757

5858
/**
5959
* @inheritDoc
60-
* @throws LocalizedException
61-
* @throws \Magento\Framework\Exception\NoSuchEntityException
6260
*/
6361
public function execute(string $value): array
6462
{
@@ -76,11 +74,7 @@ public function execute(string $value): array
7674
$categoryIds
7775
);
7876

79-
$result = $this->connection->getConnection()->fetchAll($sql);
80-
81-
return array_map(function ($item) {
82-
return $item['asset_id'];
83-
}, $result);
77+
return $this->connection->getConnection()->fetchCol($sql);
8478
}
8579

8680
/**

app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function __construct(
6868

6969
/**
7070
* @inheritDoc
71-
* @throws \Magento\Framework\Exception\LocalizedException
7271
*/
7372
public function execute(string $value): array
7473
{
@@ -91,11 +90,7 @@ public function execute(string $value): array
9190
$this->getValueFromMap($value)
9291
);
9392

94-
$result = $this->connection->getConnection()->fetchAll($sql);
95-
96-
return array_map(function ($item) {
97-
return $item['asset_id'];
98-
}, $result);
93+
return $this->connection->getConnection()->fetchCol($sql);
9994
}
10095

10196
/**

app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public function __construct(
4949

5050
/**
5151
* @inheritDoc
52-
* @throws LocalizedException
53-
* @throws \Magento\Framework\Exception\NoSuchEntityException
5452
*/
5553
public function execute(string $value): array
5654
{
@@ -70,10 +68,6 @@ public function execute(string $value): array
7068
$store->getWebsiteId()
7169
);
7270

73-
$result = $this->connection->getConnection()->fetchAll($sql);
74-
75-
return array_map(function ($item) {
76-
return $item['asset_id'];
77-
}, $result);
71+
return $this->connection->getConnection()->fetchCol($sql);
7872
}
7973
}

app/code/Magento/MediaContentCatalog/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"require": {
55
"php": "~7.3.0||~7.4.0",
66
"magento/module-media-content-api": "*",
7-
"magento/module-media-content": "*",
87
"magento/module-catalog": "*",
98
"magento/module-eav": "*",
109
"magento/module-store": "*",

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,24 @@
6262
<argument name="entityType" xsi:type="string">catalog_category</argument>
6363
</arguments>
6464
</virtualType>
65-
<virtualType name="Magento\MediaContent\Model\GetAssetIdByContentStatusComposite">
65+
<type name="Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface">
6666
<arguments>
6767
<argument name="getAssetIdByContentFieldArray" xsi:type="array">
68-
<item name="getAssetIdByProductStatus" xsi:type="object">Magento\MediaContentCatalog\Model\GetAssetIdByProductStatus</item>
69-
<item name="getAssetIdByCategoryStatus" xsi:type="object">Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStatus</item>
68+
<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>
71+
</item>
7072
</argument>
7173
</arguments>
72-
</virtualType>
73-
<virtualType name="Magento\MediaContent\Model\GetAssetIdByContentStoreComposite">
74+
</type>
75+
<type name="Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface">
7476
<arguments>
7577
<argument name="getAssetIdByContentFieldArray" xsi:type="array">
76-
<item name="getAssetIdByProductStore" xsi:type="object">Magento\MediaContentCatalog\Model\GetAssetIdByProductStore</item>
77-
<item name="getAssetIdByCategoryStore" xsi:type="object">Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStore</item>
78+
<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>
81+
</item>
7882
</argument>
7983
</arguments>
80-
</virtualType>
84+
</type>
8185
</config>

app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
namespace Magento\MediaContentCms\Model;
99

1010
use Magento\Framework\App\ResourceConnection;
11-
use Magento\Framework\Exception\LocalizedException;
1211
use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface;
13-
use Magento\Store\Api\StoreRepositoryInterface;
1412

1513
/**
1614
* Class responsible to return Asset id by content field
@@ -44,7 +42,6 @@ class GetAssetIdByContentField implements GetAssetIdByContentFieldInterface
4442
*/
4543
private $idColumn;
4644

47-
4845
/**
4946
* GetAssetIdByContentField constructor.
5047
*
@@ -88,10 +85,6 @@ public function execute(string $value): array
8885
$value
8986
);
9087

91-
$result = $this->connection->getConnection()->fetchAll($sql);
92-
93-
return array_map(function ($item) {
94-
return $item['asset_id'];
95-
}, $result);
88+
return $this->connection->getConnection()->fetchCol($sql);
9689
}
9790
}

0 commit comments

Comments
 (0)