* @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.
* 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.'));
+ }
}
}