From 02a8bb7458958c86e10573652b53fa23650282f6 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 5 Jun 2023 17:37:59 +0200 Subject: [PATCH] add upgrade method This method adds the `generic` payment instrument with a default value to all existing profiles to avoid "Payment method could not be matched to existing payment" errors. --- CRM/Twingle/Upgrader.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CRM/Twingle/Upgrader.php b/CRM/Twingle/Upgrader.php index 9b3af0c..ad85189 100644 --- a/CRM/Twingle/Upgrader.php +++ b/CRM/Twingle/Upgrader.php @@ -84,4 +84,29 @@ public function upgrade_5140() { return TRUE; } + + /** + * Add the "generic" payment instrument with default values to all profiles + * to avoid "Payment method could not be matched to existing payment + * instrument." error. + * + * @return TRUE on success + * @throws Exception + */ + public function upgrade_5150() { + $this->ctx->log->info('Add "generic" payment instrument to all profiles.'); + + $profiles = CRM_Twingle_Profile::getProfiles(); + if ($profiles) { + foreach ($profiles as $profile) { + if (!$profile->getAttribute('pi_generic', False)) { + $profile->setAttribute('pi_generic', 1); + $profile->setAttribute('pi_generic_status', 1); + $profile->saveProfile(); + } + } + } + + return TRUE; + } }