diff --git a/app/code/Magento/Vault/Setup/UpgradeData.php b/app/code/Magento/Vault/Setup/UpgradeData.php index 757b5f4d3167c..6bea6720f6199 100644 --- a/app/code/Magento/Vault/Setup/UpgradeData.php +++ b/app/code/Magento/Vault/Setup/UpgradeData.php @@ -30,12 +30,11 @@ class UpgradeData implements UpgradeDataInterface public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); - $connection = $this->getConnection(); // data update for Vault module < 2.0.1 if (version_compare($context->getVersion(), '2.0.1', '<')) { // update sets credit card as default token type - $connection->update($setup->getTable(InstallSchema::PAYMENT_TOKEN_TABLE), [ + $setup->getConnection()->update($setup->getTable(InstallSchema::PAYMENT_TOKEN_TABLE), [ PaymentTokenInterface::TYPE => CreditCardTokenFactory::TOKEN_TYPE_CREDIT_CARD ], PaymentTokenInterface::TYPE . ' = ""'); } @@ -43,12 +42,13 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface // data update for Vault module < 2.0.2 if (version_compare($context->getVersion(), '2.0.2', '<')) { // update converts additional info with token metadata to single dimensional array - $select = $connection->select() + $salesConnection = $setup->getConnection('sales'); + $select = $salesConnection->select() ->from($setup->getTable('sales_order_payment'), 'entity_id') ->columns(['additional_information']) ->where('additional_information LIKE ?', '%token_metadata%'); - $items = $connection->fetchAll($select); + $items = $salesConnection->fetchAll($select); foreach ($items as $item) { $additionalInfo = unserialize($item['additional_information']); $additionalInfo[PaymentTokenInterface::CUSTOMER_ID] = @@ -57,7 +57,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $additionalInfo['token_metadata'][PaymentTokenInterface::PUBLIC_HASH]; unset($additionalInfo['token_metadata']); - $connection->update( + $salesConnection->update( $setup->getTable('sales_order_payment'), ['additional_information' => serialize($additionalInfo)], ['entity_id = ?' => $item['entity_id']] @@ -68,22 +68,4 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $setup->endSetup(); } - /** - * Tries to get connection for scalable sales DB, otherwise returns default connection - * @return AdapterInterface - */ - private function getConnection() - { - if ($this->connection === null) { - /** @var ResourceConnection $conn */ - $conn = ObjectManager::getInstance()->get(ResourceConnection::class); - try { - $this->connection = $conn->getConnectionByName('sales'); - } catch (\DomainException $e) { - $this->connection = $conn->getConnection(); - } - } - - return $this->connection; - } }