From a0120b6aed7934f641dcae87f303b88c93ebeb2a Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Wed, 25 Jan 2023 17:30:50 +1100 Subject: [PATCH] CIVIEWAY-246 Refactor legacy upgrade functions into Upgrader class --- CRM/eWAYRecurring/Upgrader.php | 35 ++++++++++++++ eWAYRecurring.php | 87 ---------------------------------- 2 files changed, 35 insertions(+), 87 deletions(-) diff --git a/CRM/eWAYRecurring/Upgrader.php b/CRM/eWAYRecurring/Upgrader.php index 41de2c1..1d3e01d 100644 --- a/CRM/eWAYRecurring/Upgrader.php +++ b/CRM/eWAYRecurring/Upgrader.php @@ -6,6 +6,41 @@ * Collection of upgrade steps. */ class CRM_eWAYRecurring_Upgrader extends CRM_Extension_Upgrader_Base { + public function upgrade_6() { + $setting_url = CRM_Utils_System::url('civicrm/admin/paymentProcessor', ['reset' => 1]); + $this->ctx->log->info(E::ts('Version 2.x of the eWay Payment Processor extension uses the new eWay Rapid API. Please go to the Payment Processor page and update the eWay API credentials with the new API Key and API Password. For more details see the upgrade notes.', [ + 1 => 'https://github.com/agileware/au.com.agileware.ewayrecurring/blob/master/UPGRADE.md', + 2 => $setting_url, + ])); + + $this->ctx->log->info('Update Payment Processor labels for Rapid API'); + CRM_Core_DAO::executeQuery("UPDATE civicrm_payment_processor_type SET user_name_label = 'API Key', password_label = 'API Password' WHERE name = 'eWay_Recurring'"); + + $this->ctx->log->info('Create eWAY Contribution Transactions store.'); + $query = <<ctx->log->info('Add email receipt field to eWAY Contribution Transactions store.'); + CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_eway_contribution_transactions` ADD `is_email_receipt` TINYINT(1) DEFAULT 1"); + return TRUE; + } + public function upgrade_20201() { $this->ctx->log->info('Applying 2.2.1 update; Fix billing mode for payment processor.'); CRM_Core_DAO::executeQuery("UPDATE civicrm_payment_processor_type SET billing_mode = 4 WHERE name = 'eWay_Recurring'"); diff --git a/eWAYRecurring.php b/eWAYRecurring.php index 110662d..4a57cc5 100644 --- a/eWAYRecurring.php +++ b/eWAYRecurring.php @@ -49,93 +49,6 @@ function ewayrecurring_civicrm_enable() { * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade */ -function ewayrecurring_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { - $schemaVersion = intval(CRM_Core_BAO_Extension::getSchemaVersion('au.com.agileware.ewayrecurring')); - $upgrades = []; - - if ($op == 'check') { - if ($schemaVersion < 6) { - $setting_url = CRM_Utils_System::url('civicrm/admin/paymentProcessor', ['reset' => 1]); - CRM_Core_Session::setStatus(ts('Version 2.x of the eWay Payment Processor extension uses the new eWay Rapid API. Please go to the Payment Processor page and update the eWay API credentials with the new API Key and API Password. For more details see the upgrade notes.', [ - 1 => 'https://github.com/agileware/au.com.agileware.ewayrecurring/blob/master/UPGRADE.md', - 2 => $setting_url, - ]), ts('eWay Payment Processor Update')); - } - if ($schemaVersion < 7) { - CRM_Core_Session::setStatus(ts('Please edit and save (without any changes) your existing eWay payment processor after updating.'), ts('eWay Payment Processor Update')); - } - return [$schemaVersion < 20201]; - } - elseif ($op == 'enqueue') { - if (NULL == $queue) { - return CRM_Core_Error::fatal('au.com.agileware.ewayrecurring: No Queue supplied for upgrade'); - } - if ($schemaVersion < 5) { - $queue->createItem( - new CRM_Queue_Task('_ewayrecurring_upgrade_schema_version', [ - 5, - ], - 'Update schema version' - ) - ); - } - if ($schemaVersion < 6) { - $queue->createItem( - new CRM_Queue_Task('_ewayrecurring_upgrade_schema', [ - 6, - "UPDATE civicrm_payment_processor_type SET user_name_label = 'API Key', password_label = 'API Password' WHERE name = 'eWay_Recurring'", - ], - 'Perform Rapid API related changes' - ) - ); - - // add the table if not exist - $queue->createItem( - new CRM_Queue_Task('_ewayrecurring_upgrade_schema', [ - 6, - "CREATE TABLE IF NOT EXISTS `civicrm_eway_contribution_transactions`( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Unique EwayContributionTransactions ID', - `contribution_id` INT UNSIGNED COMMENT 'FK to Contact', - `payment_processor_id` INT UNSIGNED COMMENT 'FK to PaymentProcessor', - `access_code` TEXT, - `failed_message` TEXT DEFAULT NULL, - `status` INT UNSIGNED DEFAULT 0, - `tries` INT UNSIGNED DEFAULT 0, - PRIMARY KEY(`id`), - CONSTRAINT FK_civicrm_eway_contribution_transactions_contribution_id FOREIGN KEY(`contribution_id`) REFERENCES `civicrm_contribution`(`id`) ON DELETE CASCADE, - CONSTRAINT FK_civicrm_eway_contribution_transactions_payment_processor_id FOREIGN KEY(`payment_processor_id`) REFERENCES `civicrm_payment_processor`(`id`) ON DELETE CASCADE -);", - ], - 'Create the table if not exist.' - ) - ); - } - if ($schemaVersion < 7) { - // CIVIEWAY-76 remember the send email option - $queue->createItem( - new CRM_Queue_Task('_ewayrecurring_upgrade_schema', [ - 7, - "ALTER TABLE `civicrm_eway_contribution_transactions` ADD `is_email_receipt` TINYINT(1) DEFAULT 1", - ], - 'Save the send email option.' - ) - ); - } - - if ($schemaVersion < 20200) { - $queue->createItem( - new CRM_Queue_Task('_ewayrecurring_upgrade_schema', [ - 20200, - "UPDATE civicrm_payment_processor SET billing_mode = 4 WHERE payment_processor_type_id = (SELECT id FROM civicrm_payment_processor_type WHERE name = 'eWay_Recurring')", - ], - 'Updating existing processors.' - ) - ); - } - } - // @TODO Refactor the upgrader function to use the upgrader class - // return _ewayrecurring_civix_civicrm_upgrade($op, $queue); -} /** * Implements hook_civicrm_managed().