|
5 | 5 | */
|
6 | 6 | namespace Magento\Vault\Setup;
|
7 | 7 |
|
| 8 | +use Magento\Framework\App\ObjectManager; |
| 9 | +use Magento\Framework\App\ResourceConnection; |
| 10 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
8 | 11 | use Magento\Framework\Setup\ModuleContextInterface;
|
9 | 12 | use Magento\Framework\Setup\ModuleDataSetupInterface;
|
10 | 13 | use Magento\Framework\Setup\UpgradeDataInterface;
|
|
16 | 19 | */
|
17 | 20 | class UpgradeData implements UpgradeDataInterface
|
18 | 21 | {
|
| 22 | + /** |
| 23 | + * @var AdapterInterface |
| 24 | + */ |
| 25 | + private $connection; |
| 26 | + |
19 | 27 | /**
|
20 | 28 | * @inheritdoc
|
21 | 29 | */
|
22 | 30 | public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
|
23 | 31 | {
|
24 | 32 | $setup->startSetup();
|
25 |
| - $connection = $setup->getConnection(); |
| 33 | + $connection = $this->getConnection(); |
26 | 34 |
|
27 | 35 | // data update for Vault module < 2.0.1
|
28 | 36 | if (version_compare($context->getVersion(), '2.0.1', '<')) {
|
@@ -59,4 +67,23 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
|
59 | 67 |
|
60 | 68 | $setup->endSetup();
|
61 | 69 | }
|
| 70 | + |
| 71 | + /** |
| 72 | + * Tries to get connection for scalable sales DB, otherwise returns default connection |
| 73 | + * @return AdapterInterface |
| 74 | + */ |
| 75 | + private function getConnection() |
| 76 | + { |
| 77 | + if ($this->connection === null) { |
| 78 | + /** @var ResourceConnection $conn */ |
| 79 | + $conn = ObjectManager::getInstance()->get(ResourceConnection::class); |
| 80 | + try { |
| 81 | + $this->connection = $conn->getConnectionByName('sales'); |
| 82 | + } catch (\DomainException $e) { |
| 83 | + $this->connection = $conn->getConnection(); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + return $this->connection; |
| 88 | + } |
62 | 89 | }
|
0 commit comments