Skip to content

Commit

Permalink
Merge pull request #607 from magento-mpi/MAGETWO-60898
Browse files Browse the repository at this point in the history
Fixed issue:
 - MAGETWO-60898: Table vault_payment_token doesn't exist
  • Loading branch information
Oleksii Korshenko authored Nov 17, 2016
2 parents 53ae7ab + 078c651 commit 056ffbe
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions app/code/Magento/Vault/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ 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 . ' = ""');
}

// 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] =
Expand All @@ -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']]
Expand All @@ -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;
}
}

0 comments on commit 056ffbe

Please sign in to comment.