From 6f56dc346afa9d14842fd5ed3296f3a7d26bfa36 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Thu, 27 Aug 2015 18:21:29 +0530 Subject: [PATCH] CRM-17069 fix for master ---------------------------------------- * CRM-17069: Search for Contribution with campaign causes fatal error https://issues.civicrm.org/jira/browse/CRM-17069 --- CRM/Activity/BAO/Query.php | 16 ++++------- CRM/Campaign/BAO/Query.php | 53 ------------------------------------ CRM/Contribute/BAO/Query.php | 14 ++-------- CRM/Event/BAO/Query.php | 13 ++------- CRM/Mailing/BAO/Query.php | 12 ++++---- CRM/Member/BAO/Query.php | 16 ++++------- CRM/Pledge/BAO/Query.php | 14 ++-------- 7 files changed, 26 insertions(+), 112 deletions(-) diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php index 147dd69d4e..046afd02bc 100644 --- a/CRM/Activity/BAO/Query.php +++ b/CRM/Activity/BAO/Query.php @@ -197,6 +197,8 @@ class CRM_Activity_BAO_Query { case 'activity_engagement_level': case 'activity_subject': case 'activity_id': + case 'activity_campaign_id': + $qillName = $name; if (in_array($name, array('activity_engagement_level', 'activity_id'))) { $name = $qillName = str_replace('activity_', '', $name); @@ -205,6 +207,10 @@ class CRM_Activity_BAO_Query { $name = str_replace('activity_', '', $name); $qillName = str_replace('_id', '', $qillName); } + if ($name == 'activity_campaign_id') { + $name = 'campaign_id'; + } + $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.$name", $op, $value, $dataType); @@ -300,16 +306,6 @@ class CRM_Activity_BAO_Query { $query->_tables['civicrm_activity_tag'] = $query->_whereTables['civicrm_activity_tag'] = 1; break; - case 'activity_campaign_id': - $campParams = array( - 'op' => $op, - 'campaign' => $value, - 'grouping' => $grouping, - 'tableName' => 'civicrm_activity', - ); - CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query); - break; - case 'activity_result': if (is_array($value)) { $safe = NULL; diff --git a/CRM/Campaign/BAO/Query.php b/CRM/Campaign/BAO/Query.php index f38273cfb8..1066794f66 100755 --- a/CRM/Campaign/BAO/Query.php +++ b/CRM/Campaign/BAO/Query.php @@ -568,57 +568,4 @@ INNER JOIN civicrm_custom_group grp on fld.custom_group_id = grp.id return $voterClause; } - /** - * Build the campaign clause for component serach. - * - */ - public static function componentSearchClause(&$params, &$query) { - $op = CRM_Utils_Array::value('op', $params, '='); - $campaign = CRM_Utils_Array::value('campaign', $params); - $tableName = CRM_Utils_Array::value('tableName', $params); - $grouping = CRM_Utils_Array::value('grouping', $params); - if (CRM_Utils_System::isNull($campaign) || empty($tableName)) { - return; - } - - // fixme - what is the purpose of this code? $campaign should be - // an integer, not an array - if (is_array($campaign)) { - foreach (array( - 'current_campaign', - 'past_campaign', - ) as $ignore) { - $index = array_search($ignore, $campaign); - if ($index !== FALSE) { - unset($campaign[$index]); - } - } - } - - $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); - - $campaignIds = $campaignTitles = array(); - if (is_array($campaign)) { - foreach ($campaign as $campId) { - $campaignIds[$campId] = $campId; - $campaignTitles[$campId] = $allCampaigns[$campId]; - } - } - else { - $campaignIds = $campaign; - if (array_key_exists($campaignIds, $allCampaigns)) { - $campaignTitles[$campaignIds] = $allCampaigns[$campaignIds]; - } - } - $query->_qill[$grouping][] = ts('Campaigns %1', - array(1 => $op) - ) . ' ' . implode(' ' . ts('or') . ' ', $campaignTitles); - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("{$tableName}.campaign_id", - $op, - $campaignIds, - 'Integer' - ); - $query->_tables[$tableName] = $query->_whereTables[$tableName] = 1; - } - } diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 7e82e7a80a..8836a34c6b 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -360,6 +360,7 @@ class CRM_Contribute_BAO_Query { case 'contribution_contact_id': case (strpos($name, '_amount') !== FALSE): case (strpos($name, '_date') !== FALSE && $name != 'contribution_fulfilled_date'): + case 'contribution_campaign_id': $qillName = $name; $pseudoExtraParam = NULL; // @todo including names using a switch statement & then using an 'if' to filter them out is ... odd! @@ -372,11 +373,12 @@ class CRM_Contribute_BAO_Query { 'contribution_check_number', 'contribution_payment_instrument_id', 'contribution_contact_id', + 'contribution_campaign_id', ) ) ) { $name = str_replace('contribution_', '', $name); - if (!in_array($name, array('source', 'id', 'contact_id'))) { + if (!in_array($name, array('source', 'id', 'contact_id', 'campaign_id'))) { $qillName = str_replace('contribution_', '', $qillName); } } @@ -517,16 +519,6 @@ class CRM_Contribute_BAO_Query { $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1; return; - case 'contribution_campaign_id': - $campParams = array( - 'op' => $op, - 'campaign' => $value, - 'grouping' => $grouping, - 'tableName' => 'civicrm_contribution', - ); - CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query); - return; - case 'contribution_batch_id': $batches = CRM_Contribute_PseudoConstant::batch(); $query->_where[$grouping][] = " civicrm_entity_batch.batch_id $op $value"; diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index b9d18e1381..1f5dc93c51 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -346,6 +346,8 @@ class CRM_Event_BAO_Query { case 'participant_is_pay_later': case 'participant_fee_amount': case 'participant_fee_level': + case 'participant_campaign_id': + $qillName = $name; if (in_array($name, array( 'participant_status_id', @@ -356,6 +358,7 @@ class CRM_Event_BAO_Query { 'participant_fee_amount', 'participant_fee_level', 'participant_is_pay_later', + 'participant_campaign_id', ))) { $name = str_replace('participant_', '', $name); if ($name == 'is_pay_later') { @@ -411,16 +414,6 @@ class CRM_Event_BAO_Query { list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Event', $name, $value, $op); $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value)); return; - - case 'participant_campaign_id': - $campParams = array( - 'op' => $op, - 'campaign' => $value, - 'grouping' => $grouping, - 'tableName' => 'civicrm_participant', - ); - CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query); - return; } } diff --git a/CRM/Mailing/BAO/Query.php b/CRM/Mailing/BAO/Query.php index 13fed90d9b..983a690f3f 100644 --- a/CRM/Mailing/BAO/Query.php +++ b/CRM/Mailing/BAO/Query.php @@ -384,13 +384,11 @@ class CRM_Mailing_BAO_Query { return; case 'mailing_campaign_id': - $campParams = array( - 'op' => $op, - 'campaign' => $value, - 'grouping' => $grouping, - 'tableName' => 'civicrm_mailing', - ); - CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query); + $name = 'campaign_id'; + CRM_Contact_BAO_Query::buildClause("civicrm_mailing.$name", $op, $value, 'Integer'); + list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Mailing_DAO_Mailing', $name, $value, $op); + $query->_qill[$grouping][] = ts('Campaign %1 %2', array(1 => $op, 2 => $value)); + $query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1; $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1; return; } diff --git a/CRM/Member/BAO/Query.php b/CRM/Member/BAO/Query.php index 0ff5dd5283..524302bde8 100644 --- a/CRM/Member/BAO/Query.php +++ b/CRM/Member/BAO/Query.php @@ -209,6 +209,8 @@ class CRM_Member_BAO_Query { case 'membership_type': case 'membership_type_id': case 'member_id': + case 'member_campaign_id': + if (strpos($name, 'status') !== FALSE) { $name = 'status_id'; $qillName = 'Membership Status(s)'; @@ -217,6 +219,10 @@ class CRM_Member_BAO_Query { $name = 'id'; $qillName = 'Membership ID'; } + elseif ($name == 'member_campaign_id') { + $name = 'campaign_id'; + $qillName = 'Campaign'; + } else { $name = 'membership_type_id'; $qillName = 'Membership Type(s)'; @@ -290,16 +296,6 @@ class CRM_Member_BAO_Query { } $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1; return; - - case 'member_campaign_id': - $campParams = array( - 'op' => $op, - 'campaign' => $value, - 'grouping' => $grouping, - 'tableName' => 'civicrm_membership', - ); - CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query); - return; } } diff --git a/CRM/Pledge/BAO/Query.php b/CRM/Pledge/BAO/Query.php index e4b176c9fb..6d5f4f2c37 100644 --- a/CRM/Pledge/BAO/Query.php +++ b/CRM/Pledge/BAO/Query.php @@ -355,21 +355,13 @@ class CRM_Pledge_BAO_Query { $query->_tables['civicrm_pledge'] = $query->_whereTables['civicrm_pledge'] = 1; return; - case 'pledge_campaign_id': - $campParams = array( - 'op' => $op, - 'campaign' => $value, - 'grouping' => $grouping, - 'tableName' => 'civicrm_pledge', - ); - CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query); - return; - case 'pledge_contact_id': + case 'pledge_campaign_id': $name = str_replace('pledge_', '', $name); $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_pledge.$name", $op, $value, 'Integer'); list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Pledge_DAO_Pledge', $name, $value, $op); - $query->_qill[$grouping][] = ts('Contact ID %1 %2', array(1 => $op, 2 => $value)); + $label = ($name == 'campaign_id') ? 'Campaign' : 'Contact ID'; + $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $label, 2 => $op, 3 => $value)); $query->_tables['civicrm_pledge'] = $query->_whereTables['civicrm_pledge'] = 1; return; } -- 2.25.1