From 4032f8f4f2ac3d6c47bdf976889994f3d4395c01 Mon Sep 17 00:00:00 2001 From: Jaap Jansma Date: Thu, 12 May 2016 20:23:29 +0200 Subject: [PATCH] CRM-18159 fixed styles issues and moved buildAcl to CRM_ACL_BAO_ACL --- CRM/ACL/BAO/ACL.php | 34 ++++++++++++++++++++++++++ CRM/Mailing/BAO/Mailing.php | 42 ++++---------------------------- CRM/Mailing/BAO/MailingJob.php | 44 ++++------------------------------ 3 files changed, 43 insertions(+), 77 deletions(-) diff --git a/CRM/ACL/BAO/ACL.php b/CRM/ACL/BAO/ACL.php index 54962f9cfa..1033986c5f 100644 --- a/CRM/ACL/BAO/ACL.php +++ b/CRM/ACL/BAO/ACL.php @@ -722,6 +722,40 @@ 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) { + $tables = array(); + $whereTables = array(); + $whereClause = CRM_ACL_BAO_ACL::whereClause(CRM_Core_Permission::VIEW, $tables, $whereTables, $contactId); + 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 diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index fdf003228b..9059d3a299 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -908,40 +908,6 @@ ORDER BY i.contact_id, i.{$tempColumn} } } - /** - * Build a join and where part for a query - * - * @param $contact_id - * @return array - the first key is join part of the query and the second key is the where part of the query - */ - public function buildAcl($contact_id) { - $tables = array(); - $whereTables = array(); - $whereClause = CRM_ACL_BAO_ACL::whereClause(CRM_Core_Permission::VIEW, $tables, $whereTables, $contact_id); - 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 - ); - } - /** * Generate an event queue for a test job. * @@ -952,8 +918,8 @@ ORDER BY i.contact_id, i.{$tempColumn} */ public function getTestRecipients($testParams) { $session = CRM_Core_Session::singleton(); - $sender_id = $session->get('userID'); - list($acl_join, $acl_where) = $this->buildAcl($sender_id); + $senderId = $session->get('userID'); + list($aclJoin, $aclWhere) = CRM_ACL_BAO_ACL::buildAcl($senderId); if (array_key_exists($testParams['test_group'], CRM_Core_PseudoConstant::group())) { $contacts = civicrm_api('contact', 'get', array( @@ -973,14 +939,14 @@ SELECT civicrm_email.id AS email_id, civicrm_email.is_bulkmail as is_bulkmail FROM civicrm_email INNER JOIN civicrm_contact contact_a ON civicrm_email.contact_id = contact_a.id -{$acl_join} +{$aclJoin} 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_email.on_hold = 0 AND contact_a.is_opt_out = 0 -{$acl_where} +{$aclWhere} 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 20fa926f0e..c8e3d289fd 100644 --- a/CRM/Mailing/BAO/MailingJob.php +++ b/CRM/Mailing/BAO/MailingJob.php @@ -477,40 +477,6 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) } } - /** - * Build a join and where part for a query - * - * @param $contact_id - * @return array - the first key is join part of the query and the second key is the where part of the query - */ - public function buildAcl($contact_id) { - $tables = array(); - $whereTables = array(); - $whereClause = CRM_ACL_BAO_ACL::whereClause(CRM_Core_Permission::VIEW, $tables, $whereTables, $contact_id); - 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 - ); - } - /** * Send the mailing. * @@ -533,7 +499,7 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) $edTable = CRM_Mailing_Event_BAO_Delivered::getTableName(); $ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName(); - list($acl_join, $acl_where) = $this->buildAcl($mailing->created_id); + list($aclJoin, $aclWhere) = CRM_ACL_BAO_ACL::buildAcl($mailing->created_id); $query = " SELECT $eqTable.id, $emailTable.email as email, @@ -549,12 +515,12 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) ON $eqTable.id = $edTable.event_queue_id LEFT JOIN $ebTable ON $eqTable.id = $ebTable.event_queue_id - $acl_join + $aclJoin WHERE $eqTable.job_id = " . $this->id . " AND $edTable.id IS null AND $ebTable.id IS null AND contact_a.is_opt_out = 0 - $acl_where"; + $aclWhere"; if ($mailing->sms_provider_id) { $query = " @@ -572,13 +538,13 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) ON $eqTable.id = $edTable.event_queue_id LEFT JOIN $ebTable ON $eqTable.id = $ebTable.event_queue_id - $acl_join + $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 ) - $acl_where}"; + $aclWhere}"; } $eq->query($query); -- 2.25.1