Skip to content

Commit 16dc1fa

Browse files
committed
magento/adobe-stock-integration#1724: Support batches processing for synchronization queue messages - added method to sync and save media content to database
1 parent d98fcf3 commit 16dc1fa

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

app/code/Magento/MediaContentSynchronization/Model/SynchronizeIdentities.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\MediaContentSynchronization\Model;
99

10+
use Magento\Framework\App\ResourceConnection;
1011
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory;
1112
use Magento\MediaContentApi\Api\UpdateContentAssetLinksInterface;
1213
use Magento\MediaContentApi\Model\GetEntityContentsInterface;
@@ -17,12 +18,24 @@ class SynchronizeIdentities implements SynchronizeIdentitiesInterface
1718
private const ENTITY_TYPE = 'entityType';
1819
private const ENTITY_ID = 'entityId';
1920
private const FIELD = 'field';
21+
2022
private const MEDIA_CONTENT_TYPE = 'entity_type';
2123
private const MEDIA_CONTENT_ENTITY_ID = 'entity_id';
2224
private const MEDIA_CONTENT_FIELD = 'field';
25+
2326
private const FIELD_CMS_PAGE = 'cms_page';
2427
private const FIELD_CMS_BLOCK = 'cms_block';
2528

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+
2639
/**
2740
* @var ContentIdentityInterfaceFactory
2841
*/
@@ -39,26 +52,21 @@ class SynchronizeIdentities implements SynchronizeIdentitiesInterface
3952
private $getEntityContents;
4053

4154
/**
42-
* @var array
43-
*/
44-
private $fields;
45-
46-
/**
55+
* @param ResourceConnection $resourceConnection
4756
* @param ContentIdentityInterfaceFactory $contentIdentityFactory
4857
* @param UpdateContentAssetLinksInterface $updateContentAssetLinks
4958
* @param GetEntityContentsInterface $getEntityContents
50-
* @param array $fields
5159
*/
5260
public function __construct(
61+
ResourceConnection $resourceConnection,
5362
ContentIdentityInterfaceFactory $contentIdentityFactory,
5463
UpdateContentAssetLinksInterface $updateContentAssetLinks,
55-
GetEntityContentsInterface $getEntityContents,
56-
array $fields = []
64+
GetEntityContentsInterface $getEntityContents
5765
) {
66+
$this->resourceConnection = $resourceConnection;
5867
$this->contentIdentityFactory = $contentIdentityFactory;
5968
$this->updateContentAssetLinks = $updateContentAssetLinks;
6069
$this->getEntityContents = $getEntityContents;
61-
$this->fields = $fields;
6270
}
6371

6472
/**
@@ -78,7 +86,7 @@ public function execute(array $mediaContentIdentities): void
7886
if ($identity[self::MEDIA_CONTENT_TYPE] === self::FIELD_CMS_PAGE
7987
|| $identity[self::MEDIA_CONTENT_TYPE] === self::FIELD_CMS_BLOCK
8088
) {
81-
$content = (string) $identity[self::MEDIA_CONTENT_FIELD];
89+
$content = $this->getCmsMediaContent($identity[self::MEDIA_CONTENT_TYPE], $identity[self::MEDIA_CONTENT_ENTITY_ID]);
8290
} else {
8391
$content = implode(PHP_EOL, $this->getEntityContents->execute($contentIdentity));
8492
}
@@ -89,4 +97,25 @@ public function execute(array $mediaContentIdentities): void
8997
);
9098
}
9199
}
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+
}
92121
}

0 commit comments

Comments
 (0)