From 6604fd581436ceb34dd3183af48e426c81fe911d Mon Sep 17 00:00:00 2001 From: Fabian Hurnaus Date: Mon, 18 Nov 2024 12:08:49 +0100 Subject: [PATCH 1/3] Make VaultMigration compatible with disabled/removed Magento PayPal module **Issue** The installation/upgrade of the Adyen Payment plugin fails with the following error: ``` Column not found: 1054 Unknown column 'method_code' in 'where clause', query was: SELECT `paypal_billing_agreement`.* FROM `paypal_billing_agreement` WHERE (method_code = 'adyen_oneclick') AND (status = 'active') ``` **Cause** The Adyen Payment module re-creates the table during migration by adding the agreement_data field (via db_schema.xml). However, when attempting to migrate the billing agreements to the vault, the process fails to query the table using the `method_code` and `status` because these fields do not exist in the table. **Solution** Ensure VaultMigration does not fail if the `paypal_billing_agreement` table is missing or required fields are missing. --- Setup/Patch/Data/VaultMigration.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Setup/Patch/Data/VaultMigration.php b/Setup/Patch/Data/VaultMigration.php index baa6688085..1978db6d78 100644 --- a/Setup/Patch/Data/VaultMigration.php +++ b/Setup/Patch/Data/VaultMigration.php @@ -56,6 +56,17 @@ public function apply(): void private function migrateBillingAgreementsToVault(ModuleDataSetupInterface $setup): void { + if (!$setup->tableExists('paypal_billing_agreement')) { + $this->adyenLogger->addAdyenInfoLog('Table paypal_billing_agreement does not exist, skipping migration'); + return; + } + + $columns = $setup->getConnection()->describeTable('paypal_billing_agreement'); + if (!isset($columns['method_code']) || !isset($columns['status'])) { + $this->adyenLogger->addAdyenInfoLog('Columns method_code and status do not exist, skipping migration'); + return; + } + $paypalTable = $setup->getTable('paypal_billing_agreement'); $connection = $setup->getConnection(); From e59cbbc8ed2bdad344505a005e455331da91940a Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Tue, 25 Feb 2025 13:16:40 +0100 Subject: [PATCH 2/3] Use getTableName() method to obtain the full table name containing table prefix --- Setup/Patch/Data/VaultMigration.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Setup/Patch/Data/VaultMigration.php b/Setup/Patch/Data/VaultMigration.php index 1978db6d78..3436993ce3 100644 --- a/Setup/Patch/Data/VaultMigration.php +++ b/Setup/Patch/Data/VaultMigration.php @@ -61,7 +61,9 @@ private function migrateBillingAgreementsToVault(ModuleDataSetupInterface $setup return; } - $columns = $setup->getConnection()->describeTable('paypal_billing_agreement'); + $paypalTableName = $setup->getConnection()->getTableName('paypal_billing_agreement'); + $columns = $setup->getConnection()->describeTable($paypalTableName); + if (!isset($columns['method_code']) || !isset($columns['status'])) { $this->adyenLogger->addAdyenInfoLog('Columns method_code and status do not exist, skipping migration'); return; From 4d2531f2f6c549222aca5910fdc83393381c719d Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Tue, 25 Feb 2025 13:22:49 +0100 Subject: [PATCH 3/3] Revert "Use getTableName() method to obtain the full table name containing table prefix" This reverts commit e59cbbc8ed2bdad344505a005e455331da91940a. --- Setup/Patch/Data/VaultMigration.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Setup/Patch/Data/VaultMigration.php b/Setup/Patch/Data/VaultMigration.php index 3436993ce3..1978db6d78 100644 --- a/Setup/Patch/Data/VaultMigration.php +++ b/Setup/Patch/Data/VaultMigration.php @@ -61,9 +61,7 @@ private function migrateBillingAgreementsToVault(ModuleDataSetupInterface $setup return; } - $paypalTableName = $setup->getConnection()->getTableName('paypal_billing_agreement'); - $columns = $setup->getConnection()->describeTable($paypalTableName); - + $columns = $setup->getConnection()->describeTable('paypal_billing_agreement'); if (!isset($columns['method_code']) || !isset($columns['status'])) { $this->adyenLogger->addAdyenInfoLog('Columns method_code and status do not exist, skipping migration'); return;