File tree Expand file tree Collapse file tree 12 files changed +70
-51
lines changed Expand file tree Collapse file tree 12 files changed +70
-51
lines changed Original file line number Diff line number Diff line change 7
7
8
8
namespace Magento \MediaContent \Model ;
9
9
10
+ use Magento \Framework \Exception \InvalidArgumentException ;
11
+ use Magento \Framework \Exception \LocalizedException ;
12
+ use Magento \MediaContentApi \Api \GetAssetIdByContentFieldInterface as GetAssetIdByContentFieldApiInterface ;
10
13
use Magento \MediaContentApi \Model \GetAssetIdByContentFieldInterface ;
11
14
12
15
/**
13
16
* Class responsible to return Asset ids by content field
14
17
*/
15
- class GetAssetIdByContentFieldComposite implements GetAssetIdByContentFieldInterface
18
+ class GetAssetIdByContentFieldComposite implements GetAssetIdByContentFieldApiInterface
16
19
{
17
20
/**
18
21
* @var GetAssetIdByContentFieldInterface[]
@@ -32,10 +35,13 @@ public function __construct($getAssetIdByContentFieldArray = [])
32
35
/**
33
36
* @inheritDoc
34
37
*/
35
- public function execute (string $ value ): array
38
+ public function execute (string $ field , string $ value ): array
36
39
{
40
+ if (!array_key_exists ($ field , $ this ->getAssetIdByContentFieldArray )) {
41
+ throw new InvalidArgumentException (__ ('The field argument is invalid. ' ));
42
+ }
37
43
$ ids = [];
38
- foreach ($ this ->getAssetIdByContentFieldArray as $ getAssetIdByContentField ) {
44
+ foreach ($ this ->getAssetIdByContentFieldArray [ $ field ] as $ getAssetIdByContentField ) {
39
45
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
40
46
$ ids = array_merge ($ ids , $ getAssetIdByContentField ->execute ($ value ));
41
47
}
Original file line number Diff line number Diff line change 16
16
<preference for =" Magento\MediaContentApi\Api\Data\ContentIdentityInterface" type =" Magento\MediaContent\Model\ContentIdentity" />
17
17
<preference for =" Magento\MediaContentApi\Api\Data\ContentAssetLinkInterface" type =" Magento\MediaContent\Model\ContentAssetLink" />
18
18
<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
20
<type name =" Magento\MediaGalleryApi\Api\DeleteAssetsByPathsInterface" >
20
21
<plugin name =" remove_media_content_after_asset_is_removed_by_path" type =" Magento\MediaContent\Plugin\MediaGalleryAssetDeleteByPath" />
21
22
</type >
43
44
<argument name =" data" xsi : type =" object" >Magento\MediaContent\Model\Content\Config\Data</argument >
44
45
</arguments >
45
46
</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" />
48
47
</config >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 7
7
8
8
namespace Magento \MediaContentApi \Model ;
9
9
10
+ use Magento \Framework \Exception \LocalizedException ;
11
+ use Magento \Framework \Exception \NoSuchEntityException ;
12
+
10
13
/**
11
14
* Interface used to return Asset id by content field.
12
15
*/
@@ -17,6 +20,8 @@ interface GetAssetIdByContentFieldInterface
17
20
*
18
21
* @param string $value
19
22
* @return int[]
23
+ * @throws LocalizedException
24
+ * @throws NoSuchEntityException
20
25
*/
21
26
public function execute (string $ value ): array ;
22
27
}
Original file line number Diff line number Diff line change @@ -57,8 +57,6 @@ public function __construct(
57
57
58
58
/**
59
59
* @inheritDoc
60
- * @throws LocalizedException
61
- * @throws \Magento\Framework\Exception\NoSuchEntityException
62
60
*/
63
61
public function execute (string $ value ): array
64
62
{
@@ -76,11 +74,7 @@ public function execute(string $value): array
76
74
$ categoryIds
77
75
);
78
76
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 );
84
78
}
85
79
86
80
/**
Original file line number Diff line number Diff line change @@ -68,7 +68,6 @@ public function __construct(
68
68
69
69
/**
70
70
* @inheritDoc
71
- * @throws \Magento\Framework\Exception\LocalizedException
72
71
*/
73
72
public function execute (string $ value ): array
74
73
{
@@ -91,11 +90,7 @@ public function execute(string $value): array
91
90
$ this ->getValueFromMap ($ value )
92
91
);
93
92
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 );
99
94
}
100
95
101
96
/**
Original file line number Diff line number Diff line change @@ -49,8 +49,6 @@ public function __construct(
49
49
50
50
/**
51
51
* @inheritDoc
52
- * @throws LocalizedException
53
- * @throws \Magento\Framework\Exception\NoSuchEntityException
54
52
*/
55
53
public function execute (string $ value ): array
56
54
{
@@ -70,10 +68,6 @@ public function execute(string $value): array
70
68
$ store ->getWebsiteId ()
71
69
);
72
70
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 );
78
72
}
79
73
}
Original file line number Diff line number Diff line change 4
4
"require" : {
5
5
"php" : " ~7.3.0||~7.4.0" ,
6
6
"magento/module-media-content-api" : " *" ,
7
- "magento/module-media-content" : " *" ,
8
7
"magento/module-catalog" : " *" ,
9
8
"magento/module-eav" : " *" ,
10
9
"magento/module-store" : " *" ,
Original file line number Diff line number Diff line change 62
62
<argument name =" entityType" xsi : type =" string" >catalog_category</argument >
63
63
</arguments >
64
64
</virtualType >
65
- <virtualType name =" Magento\MediaContent\Model\GetAssetIdByContentStatusComposite " >
65
+ <type name =" Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface " >
66
66
<arguments >
67
67
<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 >
70
72
</argument >
71
73
</arguments >
72
- </virtualType >
73
- <virtualType name =" Magento\MediaContent\Model\GetAssetIdByContentStoreComposite " >
74
+ </type >
75
+ <type name =" Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface " >
74
76
<arguments >
75
77
<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 >
78
82
</argument >
79
83
</arguments >
80
- </virtualType >
84
+ </type >
81
85
</config >
Original file line number Diff line number Diff line change 8
8
namespace Magento \MediaContentCms \Model ;
9
9
10
10
use Magento \Framework \App \ResourceConnection ;
11
- use Magento \Framework \Exception \LocalizedException ;
12
11
use Magento \MediaContentApi \Model \GetAssetIdByContentFieldInterface ;
13
- use Magento \Store \Api \StoreRepositoryInterface ;
14
12
15
13
/**
16
14
* Class responsible to return Asset id by content field
@@ -44,7 +42,6 @@ class GetAssetIdByContentField implements GetAssetIdByContentFieldInterface
44
42
*/
45
43
private $ idColumn ;
46
44
47
-
48
45
/**
49
46
* GetAssetIdByContentField constructor.
50
47
*
@@ -88,10 +85,6 @@ public function execute(string $value): array
88
85
$ value
89
86
);
90
87
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 );
96
89
}
97
90
}
You can’t perform that action at this time.
0 commit comments