Skip to content

Commit

Permalink
PaymentProcessorType - Use standard delete function which calls hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Dec 4, 2021
1 parent aeb3174 commit 39dfda3
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions CRM/Financial/BAO/PaymentProcessorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
class CRM_Financial_BAO_PaymentProcessorType extends CRM_Financial_DAO_PaymentProcessorType {
class CRM_Financial_BAO_PaymentProcessorType extends CRM_Financial_DAO_PaymentProcessorType implements \Civi\Test\HookInterface {

/**
* Static holder for the default payment processor.
Expand Down Expand Up @@ -153,29 +153,40 @@ public static function create(&$params) {
* Delete payment processor.
*
* @param int $paymentProcessorTypeId
* ID of the processor to be deleted.
*
* @deprecated
* @return bool|NULL
*/
public static function del($paymentProcessorTypeId) {
$query = "
try {
static::deleteRecord(['id' => $paymentProcessorTypeId]);
// This message is bad on so many levels
CRM_Core_Session::setStatus(ts('Selected Payment Processor type has been deleted.<br/>'), '', 'success');
return TRUE;
}
catch (CRM_Core_Exception $e) {
CRM_Core_Session::setStatus($e->getMessage(), ts('Deletion Error'), 'error');
return NULL;
}
}

/**
* Callback for hook_civicrm_pre().
* @param \Civi\Core\Event\PreEvent $event
* @throws CRM_Core_Exception
*/
public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
if ($event->action === 'delete') {
$query = "
SELECT pp.id processor_id
FROM civicrm_payment_processor pp, civicrm_payment_processor_type ppt
WHERE pp.payment_processor_type_id = ppt.id AND ppt.id = %1";

$params = [1 => [$paymentProcessorTypeId, 'Integer']];
$dao = CRM_Core_DAO::executeQuery($query, $params);

if ($dao->fetch()) {
CRM_Core_Session::setStatus(ts('There is a Payment Processor associated with selected Payment Processor type, hence it can not be deleted.'), ts('Deletion Error'), 'error');
return NULL;
}
$params = [1 => [$event->id, 'Integer']];
$dao = CRM_Core_DAO::executeQuery($query, $params);

$paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
$paymentProcessorType->id = $paymentProcessorTypeId;
if ($paymentProcessorType->delete()) {
CRM_Core_Session::setStatus(ts('Selected Payment Processor type has been deleted.<br/>'), '', 'success');
return TRUE;
if ($dao->fetch()) {
throw new CRM_Core_Exception(ts('There is a Payment Processor associated with selected Payment Processor type, hence it can not be deleted.'));
}
}
}

Expand Down

0 comments on commit 39dfda3

Please sign in to comment.