From c905ba989e3470ee65271ea59c26ba066900c7da Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 23 Jul 2013 22:48:44 +1200 Subject: [PATCH] And the correct way to refactor a form layer extension on the BAO (when you can be sure it's only called from one place --- CRM/Member/BAO/Membership.php | 16 +--------------- CRM/Member/Form/Membership.php | 6 ++++-- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 5657efef70..549f70b4f7 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1180,21 +1180,7 @@ AND civicrm_membership.is_test = %2"; static function statusAvailabilty($contactId) { $membership = new CRM_Member_DAO_MembershipStatus(); $membership->whereAdd('is_active=1'); - $count = $membership->count(); - - if (!$count) { - // Redirect the form in case of error - // @todo this redirect in the BAO layer is really bad & should be moved to the form layer - // however since we have no idea how (if) this is triggered we can't safely move / remove it - // note I think this is the error triggered when there are no active memberships - // & you attempt to add one - $errorParams = array( - 'message_title' => ts('Invalid Action'), - 'legacy_redirect_path' => 'civicrm/contact/view', - 'legacy_redirect_query' => "reset=1&force=1&cid={$contactId}&selectedChild=member", - ); - throw new CiviCRM_Exception(ts('There are no configured membership statuses, You cannot add this membership.'), 0, $errorParams); - } + return $membership->count(); } /** diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index b8d6d6480c..6eb400e0cd 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -197,8 +197,10 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { } if ($this->_action & CRM_Core_Action::ADD) { - //check whether any active membership statuses are available - redirects back to contact summary if not - CRM_Member_BAO_Membership::statusAvailabilty($this->_contactID); + if (!CRM_Member_BAO_Membership::statusAvailabilty($this->_contactID)) { + // all possible statuses are disabled - redirect back to contact form + CRM_Core_Error::statusBounce(ts('There are no configured membership statuses. You cannot add this membership until your membership statuses are correctly configured')); + } if ($this->_contactID) { //check whether contact has a current membership so we can alert user that they may want to do a renewal instead -- 2.25.1