From 0fb7d0a187a9eedcb68aeefd2e7ae0708f9dde24 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 9 Mar 2016 02:09:03 +0000 Subject: [PATCH] Ensure that we are only running the Mailings query when we have found mailings --- CRM/Mailing/BAO/Mailing.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 99f05dcafa..2b855337d8 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -2455,15 +2455,17 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id = m.id $mailingIDs[] = $dao->id; } //CRM-18181 Get all mailings that use the mailings found earlier as receipients - $mailings = implode(',', $mailingIDs); - $mailingQuery = " - SELECT DISTINCT ( m.id ) as id - FROM civicrm_mailing m - LEFT JOIN civicrm_mailing_group g ON g.mailing_id = m.id - WHERE g.entity_table like 'civicrm_mailing%' AND g.entity_id IN ($mailings)"; - $mailingDao = CRM_Core_DAO::executeQuery($mailingQuery); - while ($mailingDao->fetch()) { - $mailingIDs[] = $mailingDao->id; + if (!empty($mailingIDs)) { + $mailings = implode(',', $mailingIDs); + $mailingQuery = " + SELECT DISTINCT ( m.id ) as id + FROM civicrm_mailing m + LEFT JOIN civicrm_mailing_group g ON g.mailing_id = m.id + WHERE g.entity_table like 'civicrm_mailing%' AND g.entity_id IN ($mailings)"; + $mailingDao = CRM_Core_DAO::executeQuery($mailingQuery); + while ($mailingDao->fetch()) { + $mailingIDs[] = $mailingDao->id; + } } } -- 2.25.1