This repository has been archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix AsynchronousOperations multistore issue by passing store_id from …
…in amqp application_headers property
- Loading branch information
1 parent
15100ac
commit fd6cf5e
Showing
4 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
app/code/Magento/Amqp/Plugin/Framework/MessageQueue/EnvelopeFactoryPlugin.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,74 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Amqp\Plugin\Framework\MessageQueue; | ||
|
||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Framework\MessageQueue\EnvelopeFactory; | ||
use PhpAmqpLib\Wire\AMQPTable; | ||
|
||
/** | ||
* Plugin to set 'store_id' to the new custom header 'store_id' in amqp | ||
* 'application_headers'. | ||
*/ | ||
class EnvelopeFactoryPlugin | ||
{ | ||
/** | ||
* @var \Magento\Store\Model\StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager | ||
*/ | ||
public function __construct( | ||
StoreManagerInterface $storeManager | ||
) { | ||
$this->storeManager = $storeManager; | ||
} | ||
|
||
/** | ||
* Pass current 'store_id' to the new custom header 'store_id' in amqp | ||
* 'application_headers' Magento\AsynchronousOperations\Model\MassConsumer | ||
* will use store_id to setCurrentStore and will execute messages for | ||
* correct store instead of default. | ||
* | ||
* @return array | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function beforeCreate(EnvelopeFactory $subject, array $data = []) | ||
{ | ||
if (!isset($data['publisher_flag'])) { | ||
return null; | ||
} else { | ||
unset($data['publisher_flag']); | ||
} | ||
try { | ||
$storeId = $this->storeManager->getStore()->getId(); | ||
|
||
if (isset($storeId)) { | ||
if (isset($data['properties'])) { | ||
$properties = $data['properties']; | ||
if (isset($properties['application_headers'])) { | ||
$headers = $properties['application_headers']; | ||
if ($headers instanceof AMQPTable) { | ||
$headers->set('store_id', $storeId); | ||
$data['properties']['application_headers'] = $headers; | ||
} | ||
} else { | ||
$data['properties']['application_headers'] = new AMQPTable(['store_id' => $storeId]); | ||
} | ||
} | ||
} | ||
} catch (\Exception $e) { | ||
return null; | ||
} | ||
|
||
return [$data]; | ||
} | ||
} |
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
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
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