From 199761b463772f27aa424d7c9d9866a65f4089c3 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Tue, 27 Sep 2016 18:37:06 +0530 Subject: [PATCH] Revert CRM-18159 fix [4.7.8 REGRESSION] --- CRM/ACL/BAO/ACL.php | 44 ++-------------------------------- CRM/Mailing/BAO/Mailing.php | 18 +++++--------- CRM/Mailing/BAO/MailingJob.php | 20 ++++++---------- 3 files changed, 15 insertions(+), 67 deletions(-) diff --git a/CRM/ACL/BAO/ACL.php b/CRM/ACL/BAO/ACL.php index 205cb0b9ca..54962f9cfa 100644 --- a/CRM/ACL/BAO/ACL.php +++ b/CRM/ACL/BAO/ACL.php @@ -722,55 +722,15 @@ SELECT count( a.id ) return ($count) ? TRUE : FALSE; } - /** - * Build a join and where part for a query - * - * @param int $contactId - * @return array - the first key is join part of the query and the second key is the where part of the query - */ - public static function buildAcl($contactId) { - // If there is no $contactId passed return empty ACL join and where clause - if (empty($contactId)) { - return array('', ''); - } - - $tables = array(); - $whereTables = array(); - $whereClause = CRM_ACL_BAO_ACL::whereClause(CRM_Core_Permission::VIEW, $tables, $whereTables, $contactId, TRUE); - if (strlen($whereClause)) { - $whereClause = " AND (" . $whereClause . ")"; - } - - $join = ""; - foreach ($whereTables as $name => $value) { - if (!$value) { - continue; - } - if ($value != 1) { - // if there is already a join statement in value, use value itself - if (strpos($value, 'JOIN')) { - $join .= " $value "; - } - continue; - } - } - - return array( - $join, - $whereClause, - ); - } - /** * @param $type * @param $tables * @param $whereTables * @param int $contactID - * @param bool $strictReturn If there is no where clause build for ACL * * @return null|string */ - public static function whereClause($type, &$tables, &$whereTables, $contactID = NULL, $strictReturn = FALSE) { + public static function whereClause($type, &$tables, &$whereTables, $contactID = NULL) { $acls = CRM_ACL_BAO_Cache::build($contactID); $whereClause = NULL; @@ -880,7 +840,7 @@ SELECT g.* // call the hook to get additional whereClauses CRM_Utils_Hook::aclWhereClause($type, $tables, $whereTables, $contactID, $whereClause); - if (empty($whereClause) && !$strictReturn) { + if (empty($whereClause)) { $whereClause = ' ( 0 ) '; } diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 10d2ab7ee1..ea5d2e947a 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -921,11 +921,7 @@ ORDER BY i.contact_id, i.{$tempColumn} * @return void */ public function getTestRecipients($testParams) { - $session = CRM_Core_Session::singleton(); - $senderId = $session->get('userID'); - list($aclJoin, $aclWhere) = CRM_ACL_BAO_ACL::buildAcl($senderId); - - if (!empty($testParams['test_group']) && array_key_exists($testParams['test_group'], CRM_Core_PseudoConstant::group())) { + if (array_key_exists($testParams['test_group'], CRM_Core_PseudoConstant::group())) { $contacts = civicrm_api('contact', 'get', array( 'version' => 3, 'group' => $testParams['test_group'], @@ -942,15 +938,13 @@ SELECT civicrm_email.id AS email_id, civicrm_email.is_primary as is_primary, civicrm_email.is_bulkmail as is_bulkmail FROM civicrm_email -INNER JOIN civicrm_contact contact_a ON civicrm_email.contact_id = contact_a.id -{$aclJoin} +INNER JOIN civicrm_contact ON civicrm_email.contact_id = civicrm_contact.id WHERE (civicrm_email.is_bulkmail = 1 OR civicrm_email.is_primary = 1) -AND contact_a.id = {$groupContact} -AND contact_a.do_not_email = 0 -AND contact_a.is_deceased <> 1 +AND civicrm_contact.id = {$groupContact} +AND civicrm_contact.do_not_email = 0 +AND civicrm_contact.is_deceased <> 1 AND civicrm_email.on_hold = 0 -AND contact_a.is_opt_out = 0 -{$aclWhere} +AND civicrm_contact.is_opt_out = 0 GROUP BY civicrm_email.id ORDER BY civicrm_email.is_bulkmail DESC "; diff --git a/CRM/Mailing/BAO/MailingJob.php b/CRM/Mailing/BAO/MailingJob.php index c6e8b18c83..14ecb417ab 100644 --- a/CRM/Mailing/BAO/MailingJob.php +++ b/CRM/Mailing/BAO/MailingJob.php @@ -505,8 +505,6 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) $edTable = CRM_Mailing_Event_BAO_Delivered::getTableName(); $ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName(); - list($aclJoin, $aclWhere) = CRM_ACL_BAO_ACL::buildAcl($mailing->created_id); - $query = " SELECT $eqTable.id, $emailTable.email as email, $eqTable.contact_id, @@ -515,18 +513,16 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) FROM $eqTable INNER JOIN $emailTable ON $eqTable.email_id = $emailTable.id - INNER JOIN $contactTable contact_a - ON contact_a.id = $emailTable.contact_id + INNER JOIN $contactTable + ON $contactTable.id = $emailTable.contact_id LEFT JOIN $edTable ON $eqTable.id = $edTable.event_queue_id LEFT JOIN $ebTable ON $eqTable.id = $ebTable.event_queue_id - $aclJoin WHERE $eqTable.job_id = " . $this->id . " AND $edTable.id IS null AND $ebTable.id IS null - AND contact_a.is_opt_out = 0 - $aclWhere"; + AND $contactTable.is_opt_out = 0"; if ($mailing->sms_provider_id) { $query = " @@ -538,19 +534,17 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) FROM $eqTable INNER JOIN $phoneTable ON $eqTable.phone_id = $phoneTable.id - INNER JOIN $contactTable contact_a - ON contact_a.id = $phoneTable.contact_id + INNER JOIN $contactTable + ON $contactTable.id = $phoneTable.contact_id LEFT JOIN $edTable ON $eqTable.id = $edTable.event_queue_id LEFT JOIN $ebTable ON $eqTable.id = $ebTable.event_queue_id - $aclJoin WHERE $eqTable.job_id = " . $this->id . " AND $edTable.id IS null AND $ebTable.id IS null - AND ( contact_a.is_opt_out = 0 - OR contact_a.do_not_sms = 0 ) - $aclWhere"; + AND ( $contactTable.is_opt_out = 0 + OR $contactTable.do_not_sms = 0 )"; } $eq->query($query); -- 2.25.1