7
7
8
8
namespace Magento \MediaContentSynchronization \Model ;
9
9
10
+ use Magento \Framework \App \ResourceConnection ;
10
11
use Magento \MediaContentApi \Api \Data \ContentIdentityInterfaceFactory ;
11
12
use Magento \MediaContentApi \Api \UpdateContentAssetLinksInterface ;
12
13
use Magento \MediaContentApi \Model \GetEntityContentsInterface ;
@@ -17,12 +18,24 @@ class SynchronizeIdentities implements SynchronizeIdentitiesInterface
17
18
private const ENTITY_TYPE = 'entityType ' ;
18
19
private const ENTITY_ID = 'entityId ' ;
19
20
private const FIELD = 'field ' ;
21
+
20
22
private const MEDIA_CONTENT_TYPE = 'entity_type ' ;
21
23
private const MEDIA_CONTENT_ENTITY_ID = 'entity_id ' ;
22
24
private const MEDIA_CONTENT_FIELD = 'field ' ;
25
+
23
26
private const FIELD_CMS_PAGE = 'cms_page ' ;
24
27
private const FIELD_CMS_BLOCK = 'cms_block ' ;
25
28
29
+ private const ID_CMS_PAGE = 'page_id ' ;
30
+ private const ID_CMS_BLOCK = 'block_id ' ;
31
+
32
+ private const COLUMN_CMS_CONTENT = 'content ' ;
33
+
34
+ /**
35
+ * @var ResourceConnection
36
+ */
37
+ private $ resourceConnection ;
38
+
26
39
/**
27
40
* @var ContentIdentityInterfaceFactory
28
41
*/
@@ -39,26 +52,21 @@ class SynchronizeIdentities implements SynchronizeIdentitiesInterface
39
52
private $ getEntityContents ;
40
53
41
54
/**
42
- * @var array
43
- */
44
- private $ fields ;
45
-
46
- /**
55
+ * @param ResourceConnection $resourceConnection
47
56
* @param ContentIdentityInterfaceFactory $contentIdentityFactory
48
57
* @param UpdateContentAssetLinksInterface $updateContentAssetLinks
49
58
* @param GetEntityContentsInterface $getEntityContents
50
- * @param array $fields
51
59
*/
52
60
public function __construct (
61
+ ResourceConnection $ resourceConnection ,
53
62
ContentIdentityInterfaceFactory $ contentIdentityFactory ,
54
63
UpdateContentAssetLinksInterface $ updateContentAssetLinks ,
55
- GetEntityContentsInterface $ getEntityContents ,
56
- array $ fields = []
64
+ GetEntityContentsInterface $ getEntityContents
57
65
) {
66
+ $ this ->resourceConnection = $ resourceConnection ;
58
67
$ this ->contentIdentityFactory = $ contentIdentityFactory ;
59
68
$ this ->updateContentAssetLinks = $ updateContentAssetLinks ;
60
69
$ this ->getEntityContents = $ getEntityContents ;
61
- $ this ->fields = $ fields ;
62
70
}
63
71
64
72
/**
@@ -78,7 +86,7 @@ public function execute(array $mediaContentIdentities): void
78
86
if ($ identity [self ::MEDIA_CONTENT_TYPE ] === self ::FIELD_CMS_PAGE
79
87
|| $ identity [self ::MEDIA_CONTENT_TYPE ] === self ::FIELD_CMS_BLOCK
80
88
) {
81
- $ content = ( string ) $ identity [self ::MEDIA_CONTENT_FIELD ] ;
89
+ $ content = $ this -> getCmsMediaContent ( $ identity [ self :: MEDIA_CONTENT_TYPE ], $ identity [self ::MEDIA_CONTENT_ENTITY_ID ]) ;
82
90
} else {
83
91
$ content = implode (PHP_EOL , $ this ->getEntityContents ->execute ($ contentIdentity ));
84
92
}
@@ -89,4 +97,25 @@ public function execute(array $mediaContentIdentities): void
89
97
);
90
98
}
91
99
}
100
+
101
+ /**
102
+ * Get cms media content from database
103
+ *
104
+ * @param string $tableName
105
+ * @param string $cmsId
106
+ * @return string
107
+ */
108
+ private function getCmsMediaContent (string $ tableName , string $ cmsId ): string
109
+ {
110
+ $ connection = $ this ->resourceConnection ->getConnection ();
111
+ $ tableName = $ this ->resourceConnection ->getTableName ($ tableName );
112
+ $ idField = $ tableName == self ::FIELD_CMS_BLOCK ? $ idField = self ::ID_CMS_BLOCK : self ::ID_CMS_PAGE ;
113
+
114
+ $ select = $ connection ->select ()
115
+ ->from ($ tableName , self ::COLUMN_CMS_CONTENT )
116
+ ->where ($ idField . '= ? ' , $ cmsId );
117
+ $ data = $ connection ->fetchOne ($ select );
118
+
119
+ return (string )$ data ;
120
+ }
92
121
}
0 commit comments