From: Coleman Watts Date: Fri, 3 Dec 2021 04:22:49 +0000 (-0500) Subject: PaymentProcessor - Use standard delete function which calls hooks X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=927ce3f0ea7bd12eeb7a4850e528ad2eea63d903;p=civicrm-core.git PaymentProcessor - Use standard delete function which calls hooks --- diff --git a/CRM/Financial/BAO/PaymentProcessor.php b/CRM/Financial/BAO/PaymentProcessor.php index 7c94cad4f6..d27b502fb3 100644 --- a/CRM/Financial/BAO/PaymentProcessor.php +++ b/CRM/Financial/BAO/PaymentProcessor.php @@ -18,7 +18,7 @@ /** * This class contains payment processor related functions. */ -class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProcessor { +class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProcessor implements \Civi\Test\HookInterface { /** * Static holder for the default payment processor * @var object @@ -184,27 +184,29 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces * Delete payment processor. * * @param int $paymentProcessorID - * - * @return null + * @deprecated */ public static function del($paymentProcessorID) { if (!$paymentProcessorID) { throw new CRM_Core_Exception(ts('Invalid value passed to delete function.')); } + static::deleteRecord(['id' => $paymentProcessorID]); + } - $dao = new CRM_Financial_DAO_PaymentProcessor(); - $dao->id = $paymentProcessorID; - if (!$dao->find(TRUE)) { - return NULL; - } - - $testDAO = new CRM_Financial_DAO_PaymentProcessor(); - $testDAO->name = $dao->name; - $testDAO->is_test = 1; - $testDAO->delete(); + /** + * Callback for hook_civicrm_post(). + * @param \Civi\Core\Event\PostEvent $event + */ + public static function self_hook_civicrm_post(\Civi\Core\Event\PostEvent $event) { + if ($event->action === 'delete') { + // When a paymentProcessor is deleted, delete the associated test processor + $testDAO = new CRM_Financial_DAO_PaymentProcessor(); + $testDAO->name = $event->object->name; + $testDAO->is_test = 1; + $testDAO->delete(); - $dao->delete(); - Civi\Payment\System::singleton()->flushProcessors(); + Civi\Payment\System::singleton()->flushProcessors(); + } } /**