Skip to content

Commit

Permalink
fix code related to reviewer comments and possible static-code test i…
Browse files Browse the repository at this point in the history
…ssues
  • Loading branch information
anvasiliev committed May 28, 2019
1 parent 80732c8 commit 51ac4d8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
use PhpAmqpLib\Wire\AMQPTable;
use Magento\Framework\Amqp\Queue;
use Magento\Framework\MessageQueue\EnvelopeInterface;
use Magento\AsynchronousOperations\Model\MassConsumerEnvelopeCallback;
use Magento\AsynchronousOperations\Model\MassConsumerEnvelopeCallback as SubjectMassConsumerEnvelopeCallback;
use Psr\Log\LoggerInterface;

/**
* Plugin to get 'store_id' from the new custom header 'store_id' in amqp
* 'application_headers' properties and setCurrentStore by value 'store_id'.
*/
class MassConsumerEnvelopeCallbackPlugin
class MassConsumerEnvelopeCallback
{
/**
* @var \Magento\Store\Model\StoreManagerInterface
Expand Down Expand Up @@ -52,12 +52,12 @@ public function __construct(
}

/**
* @param MassConsumerEnvelopeCallback $subject
* @param SubjectMassConsumerEnvelopeCallback $subject
* @param EnvelopeInterface $message
* @return array|null
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeExecute(MassConsumerEnvelopeCallback $subject, EnvelopeInterface $message)
public function beforeExecute(SubjectMassConsumerEnvelopeCallback $subject, EnvelopeInterface $message)
{
$amqpProperties = $message->getProperties();
if (isset($amqpProperties['application_headers'])) {
Expand All @@ -76,7 +76,7 @@ public function beforeExecute(MassConsumerEnvelopeCallback $subject, EnvelopeInt
return null;
}
if (isset($storeId) && $storeId !== $currentStoreId) {
$this->storeManager->setCurrentStore($storeId);
$this->storeManager->setCurrentStore($storeId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
use Magento\Framework\MessageQueue\EnvelopeFactory;
use PhpAmqpLib\Exception\AMQPInvalidArgumentException;
use PhpAmqpLib\Wire\AMQPTable;
use Magento\Framework\Amqp\Bulk\Exchange;
use Magento\Framework\Amqp\Bulk\Exchange as SubjectExchange;
use Magento\Framework\MessageQueue\EnvelopeInterface;
use Psr\Log\LoggerInterface;

/**
* Plugin to set 'store_id' to the new custom header 'store_id' in amqp
* 'application_headers'.
*/
class ExchangePlugin
class Exchange
{
/**
* @var StoreManagerInterface
Expand Down Expand Up @@ -51,13 +51,13 @@ public function __construct(
}

/**
* @param Exchange $subject
* @param SubjectExchange $subject
* @param $topic
* @param EnvelopeInterface[] $envelopes
* @return array|null
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeEnqueue(Exchange $subject, $topic, array $envelopes)
public function beforeEnqueue(SubjectExchange $subject, $topic, array $envelopes)
{
try {
$storeId = $this->storeManager->getStore()->getId();
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/AmqpStore/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"magento/framework": "*",
"magento/framework-amqp": "*",
"magento/framework-message-queue": "*",
"magento/module-store": "*",
"php": "~7.1.3||~7.2.0"
},
"type": "magento2-module",
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/AmqpStore/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\Amqp\Bulk\Exchange">
<plugin name="amqpStoreIdFieldForAmqpBulkExchange" type="Magento\AmqpStore\Plugin\Framework\Amqp\Bulk\ExchangePlugin"/>
<plugin name="amqpStoreIdFieldForAmqpBulkExchange" type="Magento\AmqpStore\Plugin\Framework\Amqp\Bulk\Exchange"/>
</type>
<type name="Magento\AsynchronousOperations\Model\MassConsumerEnvelopeCallback">
<plugin name="amqpStoreIdFieldForAsynchronousOperationsMassConsumerEnvelopeCallback" type="Magento\AmqpStore\Plugin\AsynchronousOperations\MassConsumerEnvelopeCallbackPlugin"/>
<plugin name="amqpStoreIdFieldForAsynchronousOperationsMassConsumerEnvelopeCallback" type="Magento\AmqpStore\Plugin\AsynchronousOperations\MassConsumerEnvelopeCallback"/>
</type>
</config>
21 changes: 10 additions & 11 deletions app/code/Magento/AsynchronousOperations/Model/MassConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class MassConsumer implements ConsumerInterface
* @param ConsumerConfigurationInterface $configuration
* @param OperationProcessorFactory $operationProcessorFactory
* @param LoggerInterface $logger
* @param Registry $registry
* @param MassConsumerEnvelopeCallbackFactory $massConsumerEnvelopeCallback
* @param Registry $registry
*/
public function __construct(
CallbackInvokerInterface $invoker,
Expand All @@ -90,8 +90,8 @@ public function __construct(
ConsumerConfigurationInterface $configuration,
OperationProcessorFactory $operationProcessorFactory,
LoggerInterface $logger,
Registry $registry = null,
MassConsumerEnvelopeCallbackFactory $massConsumerEnvelopeCallback = null
MassConsumerEnvelopeCallbackFactory $massConsumerEnvelopeCallback,
Registry $registry = null
) {
$this->invoker = $invoker;
$this->resource = $resource;
Expand All @@ -101,10 +101,9 @@ public function __construct(
'configuration' => $configuration
]);
$this->logger = $logger;
$this->massConsumerEnvelopeCallback = $massConsumerEnvelopeCallback;
$this->registry = $registry ?? \Magento\Framework\App\ObjectManager::getInstance()
->get(Registry::class);
$this->massConsumerEnvelopeCallback = $massConsumerEnvelopeCallback ?? \Magento\Framework\App\ObjectManager::getInstance()
->get(MassConsumerEnvelopeCallbackFactory::class);
}

/**
Expand Down Expand Up @@ -135,12 +134,12 @@ private function getTransactionCallback(QueueInterface $queue)
{
$callbackInstance = $this->massConsumerEnvelopeCallback->create([
'resource' => $this->resource,
'messageController'=>$this->messageController,
'configuration'=>$this->configuration,
'operationProcessor'=>$this->operationProcessor,
'logger'=>$this->logger,
'registry'=>$this->registry,
'queue'=>$queue,
'messageController' => $this->messageController,
'configuration' => $this->configuration,
'operationProcessor' => $this->operationProcessor,
'logger' => $this->logger,
'registry' => $this->registry,
'queue' => $queue,
]);
return function (EnvelopeInterface $message) use ($callbackInstance) {
$callbackInstance->execute($message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,21 @@ class MassConsumerEnvelopeCallback
*/
private $operationProcessor;

/**
* @var Registry
*/
private $registry;

/**
* @param ResourceConnection $resource
* @param MessageController $messageController
* @param ConsumerConfigurationInterface $configuration
* @param OperationProcessorFactory $operationProcessorFactory
* @param LoggerInterface $logger
* @param QueueInterface $queue
* @param Registry|null $registry
*/
public function __construct(
ResourceConnection $resource,
MessageController $messageController,
ConsumerConfigurationInterface $configuration,
OperationProcessorFactory $operationProcessorFactory,
LoggerInterface $logger,
QueueInterface $queue,
Registry $registry = null
QueueInterface $queue
) {
$this->resource = $resource;
$this->messageController = $messageController;
Expand All @@ -86,8 +79,6 @@ public function __construct(
'configuration' => $configuration
]);
$this->logger = $logger;
$this->registry = $registry ?? \Magento\Framework\App\ObjectManager::getInstance()
->get(Registry::class);
$this->queue = $queue;
}

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"magento/module-admin-notification": "*",
"magento/module-advanced-pricing-import-export": "*",
"magento/module-amqp": "*",
"magento/module-amqp-store": "*",
"magento/module-analytics": "*",
"magento/module-asynchronous-operations": "*",
"magento/module-authorization": "*",
Expand Down

0 comments on commit 51ac4d8

Please sign in to comment.