Skip to content

Commit 2917c4b

Browse files
committed
magento/adobe-stock-integration#1724: Support batches processing for synchronization queue messages - added media content sychronizer and save contents to database
1 parent bbb99e5 commit 2917c4b

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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\MediaContentSynchronization\Model;
9+
10+
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory;
11+
use Magento\MediaContentApi\Api\UpdateContentAssetLinksInterface;
12+
use Magento\MediaContentApi\Model\GetEntityContentsInterface;
13+
use Magento\MediaContentSynchronizationApi\Api\SynchronizeIdentitiesInterface;
14+
15+
class SynchronizeIdentities implements SynchronizeIdentitiesInterface
16+
{
17+
private const ENTITY_TYPE = 'entityType';
18+
private const ENTITY_ID = 'entityId';
19+
private const FIELD = 'field';
20+
private const MEDIA_CONTENT_TYPE = 'entity_type';
21+
private const MEDIA_CONTENT_ENTITY_ID = 'entity_id';
22+
private const MEDIA_CONTENT_FIELD = 'field';
23+
private const FIELD_CMS_PAGE = 'cms_page';
24+
private const FIELD_CMS_BLOCK = 'cms_block';
25+
26+
/**
27+
* @var ContentIdentityInterfaceFactory
28+
*/
29+
private $contentIdentityFactory;
30+
31+
/**
32+
* @var UpdateContentAssetLinksInterface
33+
*/
34+
private $updateContentAssetLinks;
35+
36+
/**
37+
* @var GetEntityContentsInterface
38+
*/
39+
private $getEntityContents;
40+
41+
/**
42+
* @var array
43+
*/
44+
private $fields;
45+
46+
/**
47+
* @param ContentIdentityInterfaceFactory $contentIdentityFactory
48+
* @param UpdateContentAssetLinksInterface $updateContentAssetLinks
49+
* @param GetEntityContentsInterface $getEntityContents
50+
* @param array $fields
51+
*/
52+
public function __construct(
53+
ContentIdentityInterfaceFactory $contentIdentityFactory,
54+
UpdateContentAssetLinksInterface $updateContentAssetLinks,
55+
GetEntityContentsInterface $getEntityContents,
56+
array $fields = []
57+
) {
58+
$this->contentIdentityFactory = $contentIdentityFactory;
59+
$this->updateContentAssetLinks = $updateContentAssetLinks;
60+
$this->getEntityContents = $getEntityContents;
61+
$this->fields = $fields;
62+
}
63+
64+
/**
65+
* @inheritDoc
66+
*/
67+
public function execute(array $mediaContentIdentities): void
68+
{
69+
foreach ($mediaContentIdentities as $identity) {
70+
$contentIdentity = $this->contentIdentityFactory->create(
71+
[
72+
self::ENTITY_TYPE => $identity[self::MEDIA_CONTENT_TYPE],
73+
self::ENTITY_ID => $identity[self::MEDIA_CONTENT_ENTITY_ID],
74+
self::FIELD => $identity[self::MEDIA_CONTENT_FIELD]
75+
]
76+
);
77+
78+
if ($identity[self::MEDIA_CONTENT_TYPE] === self::FIELD_CMS_PAGE
79+
|| $identity[self::MEDIA_CONTENT_TYPE] === self::FIELD_CMS_BLOCK
80+
) {
81+
$content = (string) $identity[self::MEDIA_CONTENT_FIELD];
82+
} else {
83+
$content = implode(PHP_EOL, $this->getEntityContents->execute($contentIdentity));
84+
}
85+
86+
$this->updateContentAssetLinks->execute(
87+
$contentIdentity,
88+
$content
89+
);
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)