From 7a5db44faa367831517e818b19ee1d34c2bad4ae Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 28 Mar 2018 14:56:31 +1300 Subject: [PATCH] Tidy up on_hold handling in holdEmail function. Follow up on https://github.com/civicrm/civicrm-core/pull/11807 --- CRM/Core/BAO/Email.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/CRM/Core/BAO/Email.php b/CRM/Core/BAO/Email.php index e1370ca433..0718811723 100644 --- a/CRM/Core/BAO/Email.php +++ b/CRM/Core/BAO/Email.php @@ -237,13 +237,20 @@ ORDER BY e.is_primary DESC, email_id ASC "; * Email object. */ public static function holdEmail(&$email) { - if (!($email->on_hold === 'null' || $email->on_hold === NULL)) { - $email->on_hold = intval($email->on_hold); + if ($email->id && $email->on_hold === NULL) { + // email is being updated but no change to on_hold. + return; } + if ($email->on_hold === 'null' || $email->on_hold === NULL) { + // legacy handling, deprecated. + $email->on_hold = 0; + } + $email->on_hold = (int) $email->on_hold; + //check for update mode if ($email->id) { $params = array(1 => array($email->id, 'Integer')); - if ($email->on_hold && $email->on_hold != 'null') { + if ($email->on_hold) { $sql = " SELECT id FROM civicrm_email @@ -255,7 +262,8 @@ AND hold_date IS NULL $email->reset_date = 'null'; } } - elseif ($email->on_hold == 'null') { + elseif ($email->on_hold === 0) { + // we do this lookup to see if reset_date should be changed. $sql = " SELECT id FROM civicrm_email @@ -272,7 +280,7 @@ AND reset_date IS NULL } } else { - if (($email->on_hold != 'null') && $email->on_hold) { + if ($email->on_hold) { $email->hold_date = date('YmdHis'); } } -- 2.25.1