Skip to content

Commit b99f911

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-2504' into Tier4-PR-Delivery-12-1-23
2 parents 541edba + 583a235 commit b99f911

File tree

15 files changed

+392
-339
lines changed

15 files changed

+392
-339
lines changed

app/code/Magento/Catalog/Cron/SynchronizeWebsiteAttributes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Magento\Catalog\Model\ResourceModel\Attribute\WebsiteAttributesSynchronizer;
1010

1111
/**
12-
* Class SynchronizeWebsiteAttributes
13-
* @package Magento\Catalog\Cron
12+
* @deprecated
13+
* @see \Magento\Catalog\Model\Attribute\Backend\WebsiteSpecific\ValueSynchronizer
1414
*/
1515
class SynchronizeWebsiteAttributes
1616
{
@@ -20,7 +20,6 @@ class SynchronizeWebsiteAttributes
2020
private $synchronizer;
2121

2222
/**
23-
* SynchronizeWebsiteAttributes constructor.
2423
* @param WebsiteAttributesSynchronizer $synchronizer
2524
*/
2625
public function __construct(WebsiteAttributesSynchronizer $synchronizer)
@@ -30,6 +29,7 @@ public function __construct(WebsiteAttributesSynchronizer $synchronizer)
3029

3130
/**
3231
* Synchronizes website attribute values if needed
32+
*
3333
* @return void
3434
*/
3535
public function execute()
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* ADOBE CONFIDENTIAL
4+
*
5+
* Copyright 2023 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Catalog\Model\Attribute\Backend\WebsiteSpecific;
20+
21+
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
22+
use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory;
23+
use Magento\Framework\Bulk\BulkManagementInterface;
24+
use Magento\Framework\DataObject\IdentityGeneratorInterface;
25+
use Magento\Framework\Exception\LocalizedException;
26+
use Magento\Framework\Serialize\SerializerInterface;
27+
28+
class Scheduler
29+
{
30+
private const TOPIC_NAME = 'catalog_website_attribute_value_sync';
31+
32+
/**
33+
* @param BulkManagementInterface $bulkManagement
34+
* @param IdentityGeneratorInterface $identityGenerator
35+
* @param OperationInterfaceFactory $operationFactory
36+
* @param SerializerInterface $serializer
37+
*/
38+
public function __construct(
39+
private BulkManagementInterface $bulkManagement,
40+
private IdentityGeneratorInterface $identityGenerator,
41+
private OperationInterfaceFactory $operationFactory,
42+
private SerializerInterface $serializer
43+
) {
44+
}
45+
46+
/**
47+
* Schedule website specific values synchronization.
48+
*
49+
* @param int $storeId
50+
* @return void
51+
* @throws LocalizedException
52+
*/
53+
public function execute(int $storeId): void
54+
{
55+
$bulkUuid = $this->identityGenerator->generateId();
56+
$operation = $this->operationFactory->create(
57+
[
58+
'data' => [
59+
'bulk_uuid' => $bulkUuid,
60+
'topic_name' => self::TOPIC_NAME,
61+
'serialized_data' => $this->serializer->serialize(['store_id' => $storeId]),
62+
'status' => OperationInterface::STATUS_TYPE_OPEN,
63+
]
64+
]
65+
);
66+
$bulkDescription = __('Synchronize website specific attributes values');
67+
$result = $this->bulkManagement->scheduleBulk($bulkUuid, [$operation], $bulkDescription);
68+
if (!$result) {
69+
throw new LocalizedException(__('Something went wrong while scheduling operations.'));
70+
}
71+
}
72+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* ADOBE CONFIDENTIAL
4+
*
5+
* Copyright 2023 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Catalog\Model\Attribute\Backend\WebsiteSpecific;
20+
21+
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
22+
use Magento\Catalog\Model\ResourceModel\Attribute\WebsiteAttributesSynchronizer;
23+
use Magento\Framework\DB\Adapter\ConnectionException;
24+
use Magento\Framework\DB\Adapter\DeadlockException;
25+
use Magento\Framework\DB\Adapter\LockWaitException;
26+
use Magento\Framework\EntityManager\EntityManager;
27+
use Magento\Framework\Exception\LocalizedException;
28+
use Magento\Framework\Serialize\SerializerInterface;
29+
use Psr\Log\LoggerInterface;
30+
31+
class ValueSynchronizer
32+
{
33+
/**
34+
* @param EntityManager $entityManager
35+
* @param SerializerInterface $serializer
36+
* @param LoggerInterface $logger
37+
* @param WebsiteAttributesSynchronizer $websiteAttributesSynchronizer
38+
*/
39+
public function __construct(
40+
private EntityManager $entityManager,
41+
private SerializerInterface $serializer,
42+
private LoggerInterface $logger,
43+
private WebsiteAttributesSynchronizer $websiteAttributesSynchronizer
44+
) {
45+
}
46+
47+
/**
48+
* Process website specific values synchronization.
49+
*
50+
* @param OperationInterface $operation
51+
* @return void
52+
*/
53+
public function process(OperationInterface $operation): void
54+
{
55+
try {
56+
$serializedData = $operation->getSerializedData();
57+
$data = $this->serializer->unserialize($serializedData);
58+
$this->websiteAttributesSynchronizer->synchronizeStoreValues($data['store_id']);
59+
$operation->setStatus(OperationInterface::STATUS_TYPE_COMPLETE);
60+
$operation->setResultMessage(null);
61+
} catch (LockWaitException|DeadlockException|ConnectionException $e) {
62+
$operation->setStatus(OperationInterface::STATUS_TYPE_RETRIABLY_FAILED);
63+
$operation->setErrorCode($e->getCode());
64+
$operation->setResultMessage($e->getMessage());
65+
} catch (LocalizedException $e) {
66+
$operation->setStatus(OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED);
67+
$operation->setErrorCode($e->getCode());
68+
$operation->setResultMessage($e->getMessage());
69+
} catch (\Throwable $e) {
70+
$this->logger->critical($e);
71+
$operation->setStatus(OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED);
72+
$operation->setErrorCode($e->getCode());
73+
$operation->setResultMessage(
74+
__('Sorry, something went wrong during update synchronization. Please see log for details.')
75+
);
76+
}
77+
$this->entityManager->save($operation);
78+
}
79+
}

0 commit comments

Comments
 (0)