7
7
8
8
namespace Magento \MediaContent \Model ;
9
9
10
+ use Magento \Eav \Api \Data \AttributeInterface ;
11
+ use Magento \Eav \Model \Config ;
10
12
use Magento \Framework \App \ResourceConnection ;
11
13
use Magento \MediaContentApi \Model \GetAssetIdByContentStatusInterface ;
12
14
16
18
class GetAssetIdByEavContentStatus implements GetAssetIdByContentStatusInterface
17
19
{
18
20
private const TABLE_CONTENT_ASSET = 'media_content_asset ' ;
19
- private const TABLE_EAV_ATTRIBUTE = 'eav_attribute ' ;
20
21
21
22
/**
22
23
* @var ResourceConnection
23
24
*/
24
25
private $ connection ;
25
26
26
27
/**
27
- * @var string
28
+ * @var Config
28
29
*/
29
- private $ entityEavTypeTable ;
30
+ private $ config ;
30
31
31
32
/**
32
33
* @var string
@@ -38,58 +39,53 @@ class GetAssetIdByEavContentStatus implements GetAssetIdByContentStatusInterface
38
39
*/
39
40
private $ entityType ;
40
41
41
- /**
42
- * @var int
43
- */
44
- private $ entityTypeId ;
45
-
46
42
/**
47
43
* @var array
48
44
*/
49
45
private $ valueMap ;
50
46
51
47
/**
52
- * GetEavContentIdByStatus constructor.
48
+ * GetAssetIdByEavContentStatus constructor.
53
49
* @param ResourceConnection $resource
54
- * @param string $entityEavTypeTable
50
+ * @param Config $config
55
51
* @param string $attributeCode
56
52
* @param string $entityType
57
- * @param int $entityTypeId
58
53
* @param array $valueMap
59
54
*/
60
55
public function __construct (
61
56
ResourceConnection $ resource ,
62
- string $ entityEavTypeTable ,
57
+ Config $ config ,
63
58
string $ attributeCode ,
64
59
string $ entityType ,
65
- int $ entityTypeId ,
66
60
array $ valueMap = []
67
61
) {
68
62
$ this ->connection = $ resource ;
69
- $ this ->entityEavTypeTable = $ entityEavTypeTable ;
63
+ $ this ->config = $ config ;
70
64
$ this ->attributeCode = $ attributeCode ;
71
65
$ this ->entityType = $ entityType ;
72
- $ this ->entityTypeId = $ entityTypeId ;
73
66
$ this ->valueMap = $ valueMap ;
74
67
}
75
68
76
69
/**
77
70
* @param string $value
78
71
* @return array
72
+ * @throws \Magento\Framework\Exception\LocalizedException
79
73
*/
80
74
public function execute (string $ value ): array
81
75
{
82
- $ statusAttributeId = $ this ->getAttributeId ();
76
+ $ statusAttribute = $ this ->config ->getAttribute ($ this ->entityType , $ this ->attributeCode );
77
+
83
78
$ sql = $ this ->connection ->getConnection ()->select ()->from (
84
79
['asset_content_table ' => $ this ->connection ->getTableName (self ::TABLE_CONTENT_ASSET )],
85
80
['asset_id ' ]
86
81
)->where (
87
82
'entity_type = ? ' ,
88
83
$ this ->entityType
89
84
)->joinInner (
90
- ['entity_eav_type ' => $ this ->connection ->getTableName ($ this ->entityEavTypeTable )],
91
- 'asset_content_table.entity_id = entity_eav_type.entity_id AND entity_eav_type.attribute_id = ' .
92
- $ statusAttributeId ,
85
+ ['entity_eav_type ' => $ statusAttribute ->getBackendTable ()],
86
+ 'asset_content_table.entity_id = entity_eav_type. ' . $ statusAttribute ->getEntityIdField () .
87
+ ' AND entity_eav_type.attribute_id = ' .
88
+ $ statusAttribute ->getAttributeId (),
93
89
[]
94
90
)->where (
95
91
'entity_eav_type.value = ? ' ,
@@ -103,25 +99,6 @@ public function execute(string $value): array
103
99
}, $ result );
104
100
}
105
101
106
- /**
107
- * @return string
108
- */
109
- private function getAttributeId (): string
110
- {
111
- $ sql = $ this ->connection ->getConnection ()->select ()->from (
112
- ['eav ' => $ this ->connection ->getTableName (self ::TABLE_EAV_ATTRIBUTE )],
113
- ['attribute_id ' ]
114
- )->where (
115
- 'entity_type_id = ? ' ,
116
- $ this ->entityTypeId
117
- )->where (
118
- 'attribute_code = ? ' ,
119
- $ this ->attributeCode
120
- );
121
-
122
- return $ this ->connection ->getConnection ()->fetchOne ($ sql );
123
- }
124
-
125
102
/**
126
103
* @param string $value
127
104
* @return string
0 commit comments