From 355b9405e792b01c37a20ca89a826b25413b7726 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 8 Sep 2020 08:40:54 +1000 Subject: [PATCH] [REF] Improve the human readable name of the eway upgrade step to be clearer about what it is doing and also fix issue with a hard fault if the eway single currency payment processor type has been already removed --- CRM/Upgrade/Incremental/php/FiveThirtyOne.php | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FiveThirtyOne.php b/CRM/Upgrade/Incremental/php/FiveThirtyOne.php index 8cecc02d43..50c35a60e8 100644 --- a/CRM/Upgrade/Incremental/php/FiveThirtyOne.php +++ b/CRM/Upgrade/Incremental/php/FiveThirtyOne.php @@ -72,34 +72,36 @@ class CRM_Upgrade_Incremental_php_FiveThirtyOne extends CRM_Upgrade_Incremental_ */ public function upgrade_5_31_alpha1($rev) { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); - $this->addTask('enableeWAYSingleCurrencyExtension', 'enableEwaySingleExtension'); + $this->addTask('Remove Eway Single Currency Payment Processor type if not used or install the new extension for it', 'enableEwaySingleExtension'); } public static function enableEwaySingleExtension(CRM_Queue_TaskContext $ctx) { $eWAYPaymentProcessorType = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_payment_processor_type WHERE class_name = 'Payment_eWAY'"); - $ewayPaymentProcessorCount = CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM civicrm_payment_processor WHERE payment_processor_type_id = %1", [1 => [$eWAYPaymentProcessorType, 'Positive']]); - if ($ewayPaymentProcessorCount) { - $insert = CRM_Utils_SQL_Insert::into('civicrm_extension')->row([ - 'type' => 'module', - 'full_name' => 'ewaysingle', - 'name' => 'eway Single currency extension', - 'label' => 'eway Single currency extension', - 'file' => 'ewaysingle', - 'schema_version' => NULL, - 'is_active' => 1, - ]); - CRM_Core_DAO::executeQuery($insert->usingReplace()->toSQL()); - $managedEntity = CRM_Utils_SQL_Insert::into('civicrm_managed')->row([ - 'name' => 'eWAY', - 'module' => 'ewaysingle', - 'entity_type' => 'PaymentProcessorType', - 'entity_id' => $eWAYPaymentProcessorType, - 'cleanup' => NULL, - ]); - CRM_Core_DAO::executeQuery($managedEntity->usingReplace()->toSQL()); - } - else { - CRM_Core_DAO::executeQuery("DELETE FROM civicrm_payment_processor_type WHERE id = %1", [1 => [$eWAYPaymentProcessorType, 'Positive']]); + if ($eWAYPaymentProcessorType) { + $ewayPaymentProcessorCount = CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM civicrm_payment_processor WHERE payment_processor_type_id = %1", [1 => [$eWAYPaymentProcessorType, 'Positive']]); + if ($ewayPaymentProcessorCount) { + $insert = CRM_Utils_SQL_Insert::into('civicrm_extension')->row([ + 'type' => 'module', + 'full_name' => 'ewaysingle', + 'name' => 'eway Single currency extension', + 'label' => 'eway Single currency extension', + 'file' => 'ewaysingle', + 'schema_version' => NULL, + 'is_active' => 1, + ]); + CRM_Core_DAO::executeQuery($insert->usingReplace()->toSQL()); + $managedEntity = CRM_Utils_SQL_Insert::into('civicrm_managed')->row([ + 'name' => 'eWAY', + 'module' => 'ewaysingle', + 'entity_type' => 'PaymentProcessorType', + 'entity_id' => $eWAYPaymentProcessorType, + 'cleanup' => NULL, + ]); + CRM_Core_DAO::executeQuery($managedEntity->usingReplace()->toSQL()); + } + else { + CRM_Core_DAO::executeQuery("DELETE FROM civicrm_payment_processor_type WHERE id = %1", [1 => [$eWAYPaymentProcessorType, 'Positive']]); + } } return TRUE; } -- 2.25.1