forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
magento/adobe-stock-integration#1724: Support batches processing for …
…synchronization queue messages - added media content sychronizer and save contents to database
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
app/code/Magento/MediaContentSynchronization/Model/SynchronizeIdentities.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MediaContentSynchronization\Model; | ||
|
||
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory; | ||
use Magento\MediaContentApi\Api\UpdateContentAssetLinksInterface; | ||
use Magento\MediaContentApi\Model\GetEntityContentsInterface; | ||
use Magento\MediaContentSynchronizationApi\Api\SynchronizeIdentitiesInterface; | ||
|
||
class SynchronizeIdentities implements SynchronizeIdentitiesInterface | ||
{ | ||
private const ENTITY_TYPE = 'entityType'; | ||
private const ENTITY_ID = 'entityId'; | ||
private const FIELD = 'field'; | ||
private const MEDIA_CONTENT_TYPE = 'entity_type'; | ||
private const MEDIA_CONTENT_ENTITY_ID = 'entity_id'; | ||
private const MEDIA_CONTENT_FIELD = 'field'; | ||
private const FIELD_CMS_PAGE = 'cms_page'; | ||
private const FIELD_CMS_BLOCK = 'cms_block'; | ||
|
||
/** | ||
* @var ContentIdentityInterfaceFactory | ||
*/ | ||
private $contentIdentityFactory; | ||
|
||
/** | ||
* @var UpdateContentAssetLinksInterface | ||
*/ | ||
private $updateContentAssetLinks; | ||
|
||
/** | ||
* @var GetEntityContentsInterface | ||
*/ | ||
private $getEntityContents; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $fields; | ||
|
||
/** | ||
* @param ContentIdentityInterfaceFactory $contentIdentityFactory | ||
* @param UpdateContentAssetLinksInterface $updateContentAssetLinks | ||
* @param GetEntityContentsInterface $getEntityContents | ||
* @param array $fields | ||
*/ | ||
public function __construct( | ||
ContentIdentityInterfaceFactory $contentIdentityFactory, | ||
UpdateContentAssetLinksInterface $updateContentAssetLinks, | ||
GetEntityContentsInterface $getEntityContents, | ||
array $fields = [] | ||
) { | ||
$this->contentIdentityFactory = $contentIdentityFactory; | ||
$this->updateContentAssetLinks = $updateContentAssetLinks; | ||
$this->getEntityContents = $getEntityContents; | ||
$this->fields = $fields; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function execute(array $mediaContentIdentities): void | ||
{ | ||
foreach ($mediaContentIdentities as $identity) { | ||
$contentIdentity = $this->contentIdentityFactory->create( | ||
[ | ||
self::ENTITY_TYPE => $identity[self::MEDIA_CONTENT_TYPE], | ||
self::ENTITY_ID => $identity[self::MEDIA_CONTENT_ENTITY_ID], | ||
self::FIELD => $identity[self::MEDIA_CONTENT_FIELD] | ||
] | ||
); | ||
|
||
if ($identity[self::MEDIA_CONTENT_TYPE] === self::FIELD_CMS_PAGE | ||
|| $identity[self::MEDIA_CONTENT_TYPE] === self::FIELD_CMS_BLOCK | ||
) { | ||
$content = (string) $identity[self::MEDIA_CONTENT_FIELD]; | ||
} else { | ||
$content = implode(PHP_EOL, $this->getEntityContents->execute($contentIdentity)); | ||
} | ||
|
||
$this->updateContentAssetLinks->execute( | ||
$contentIdentity, | ||
$content | ||
); | ||
} | ||
} | ||
} |