Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit ab2f000

Browse files
committed
fix catching exceptions
1 parent 81ecd90 commit ab2f000

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

app/code/Magento/AmqpStore/Plugin/AsynchronousOperations/MassConsumerEnvelopeCallback.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,17 @@ public function __construct(
5151
}
5252

5353
/**
54+
* Check if amqpProperties['application_headers'] have 'store_id' and use it to setCurrentStore
55+
* Restore currentStore of consumer process after execution.
56+
*
5457
* @param SubjectMassConsumerEnvelopeCallback $subject
58+
* @param callable $proceed
5559
* @param EnvelopeInterface $message
5660
* @return array|null
61+
* @throws NoSuchEntityException
5762
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5863
*/
59-
public function beforeExecute(SubjectMassConsumerEnvelopeCallback $subject, EnvelopeInterface $message)
64+
public function aroundExecute(SubjectMassConsumerEnvelopeCallback $subject, callable $proceed, EnvelopeInterface $message)
6065
{
6166
$amqpProperties = $message->getProperties();
6267
if (isset($amqpProperties['application_headers'])) {
@@ -72,13 +77,17 @@ public function beforeExecute(SubjectMassConsumerEnvelopeCallback $subject, Enve
7277
$this->logger->error(
7378
sprintf("Can't set currentStoreId during processing queue. Error %s.", $e->getMessage())
7479
);
75-
return null;
80+
throw new NoSuchEntityException(__($e->getMessage()));
7681
}
7782
if (isset($storeId) && $storeId !== $currentStoreId) {
7883
$this->storeManager->setCurrentStore($storeId);
7984
}
8085
}
8186
}
82-
return [$message];
87+
$result = $proceed($message);
88+
if (isset($storeId, $currentStoreId) && $storeId !== $currentStoreId) {
89+
$this->storeManager->setCurrentStore($currentStoreId);//restore previous current store
90+
}
91+
return $result;
8392
}
8493
}

app/code/Magento/AmqpStore/Plugin/Framework/Amqp/Bulk/Exchange.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,22 @@ public function __construct(
5555
* @param $topic
5656
* @param EnvelopeInterface[] $envelopes
5757
* @return array|null
58+
* @throws NoSuchEntityException
59+
* @throws AMQPInvalidArgumentException
5860
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5961
*/
6062
public function beforeEnqueue(SubjectExchange $subject, $topic, array $envelopes)
6163
{
6264
try {
6365
$storeId = $this->storeManager->getStore()->getId();
66+
$code = $this->storeManager->getStore()->getCode();
67+
$t=1;
6468
} catch (NoSuchEntityException $e) {
69+
$r=1;
6570
$this->logger->error(
6671
sprintf("Can't get current storeId and inject to amqp message. Error %s.", $e->getMessage())
6772
);
68-
return null;
73+
throw new NoSuchEntityException(__($e->getMessage()));
6974
}
7075

7176
$updatedEnvelopes = [];
@@ -83,7 +88,7 @@ public function beforeEnqueue(SubjectExchange $subject, $topic, array $envelopes
8388
$this->logger->error(
8489
sprintf("Can't set storeId to amqp message. Error %s.", $ea->getMessage())
8590
);
86-
return null;
91+
throw new AMQPInvalidArgumentException($ea->getMessage());
8792
}
8893
$properties['application_headers'] = $headers;
8994
}

0 commit comments

Comments
 (0)