@@ -30,25 +30,25 @@ class UpgradeData implements UpgradeDataInterface
30
30
public function upgrade (ModuleDataSetupInterface $ setup , ModuleContextInterface $ context )
31
31
{
32
32
$ setup ->startSetup ();
33
- $ connection = $ this ->getConnection ();
34
33
35
34
// data update for Vault module < 2.0.1
36
35
if (version_compare ($ context ->getVersion (), '2.0.1 ' , '< ' )) {
37
36
// update sets credit card as default token type
38
- $ connection ->update ($ setup ->getTable (InstallSchema::PAYMENT_TOKEN_TABLE ), [
37
+ $ setup -> getConnection () ->update ($ setup ->getTable (InstallSchema::PAYMENT_TOKEN_TABLE ), [
39
38
PaymentTokenInterface::TYPE => CreditCardTokenFactory::TOKEN_TYPE_CREDIT_CARD
40
39
], PaymentTokenInterface::TYPE . ' = "" ' );
41
40
}
42
41
43
42
// data update for Vault module < 2.0.2
44
43
if (version_compare ($ context ->getVersion (), '2.0.2 ' , '< ' )) {
45
44
// update converts additional info with token metadata to single dimensional array
46
- $ select = $ connection ->select ()
45
+ $ salesConnection = $ setup ->getConnection ('sales ' );
46
+ $ select = $ salesConnection ->select ()
47
47
->from ($ setup ->getTable ('sales_order_payment ' ), 'entity_id ' )
48
48
->columns (['additional_information ' ])
49
49
->where ('additional_information LIKE ? ' , '%token_metadata% ' );
50
50
51
- $ items = $ connection ->fetchAll ($ select );
51
+ $ items = $ salesConnection ->fetchAll ($ select );
52
52
foreach ($ items as $ item ) {
53
53
$ additionalInfo = unserialize ($ item ['additional_information ' ]);
54
54
$ additionalInfo [PaymentTokenInterface::CUSTOMER_ID ] =
@@ -57,7 +57,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
57
57
$ additionalInfo ['token_metadata ' ][PaymentTokenInterface::PUBLIC_HASH ];
58
58
unset($ additionalInfo ['token_metadata ' ]);
59
59
60
- $ connection ->update (
60
+ $ salesConnection ->update (
61
61
$ setup ->getTable ('sales_order_payment ' ),
62
62
['additional_information ' => serialize ($ additionalInfo )],
63
63
['entity_id = ? ' => $ item ['entity_id ' ]]
@@ -68,22 +68,4 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
68
68
$ setup ->endSetup ();
69
69
}
70
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
- }
89
71
}
0 commit comments