From 0b960db116d0506a139738f5ce6196fd11fdb77f Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Fri, 2 Jul 2021 16:47:59 +0100 Subject: [PATCH] Fix invalid defaults for Mailing.update_email_resetdate API temp --- CRM/Mailing/Event/BAO/Delivered.php | 6 +++++- api/v3/Mailing.php | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CRM/Mailing/Event/BAO/Delivered.php b/CRM/Mailing/Event/BAO/Delivered.php index e236767c2e..f14176652b 100644 --- a/CRM/Mailing/Event/BAO/Delivered.php +++ b/CRM/Mailing/Event/BAO/Delivered.php @@ -263,7 +263,11 @@ class CRM_Mailing_Event_BAO_Delivered extends CRM_Mailing_Event_DAO_Delivered { * @param int $maxDays * Consider mailings that were completed not more than $maxDays ago. */ - public static function updateEmailResetDate($minDays = 3, $maxDays = 7) { + public static function updateEmailResetDate(int $minDays = 3, int $maxDays = 7) { + + if ($minDays < 0 || $maxDays < 0 || $maxDays <= $minDays) { + throw new \InvalidArgumentException("minDays and maxDays must be >=0 and maxDays > minDays"); + } $temporaryTable = CRM_Utils_SQL_TempTable::build() ->setCategory('mailingemail') diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index 653fdcd2b2..51a5679bba 100644 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -782,6 +782,18 @@ function civicrm_api3_mailing_stats($params) { return civicrm_api3_create_success($stats); } +function _civicrm_api3_mailing_update_email_resetdate_spec(&$spec) { + $spec['minDays']['title'] = 'Number of days to wait without a bounce to assume successful delivery (default 3)'; + $spec['minDays']['type'] = CRM_Utils_Type::T_INT; + $spec['minDays']['api.default'] = 3; + $spec['minDays']['api.required'] = 1; + + $spec['maxDays']['title'] = 'Analyze mailings since this many days ago (default 7)'; + $spec['maxDays']['type'] = CRM_Utils_Type::T_INT; + $spec['maxDays']['api.default'] = 7; + $spec['maxDays']['api.required'] = 1; +} + /** * Fix the reset dates on the email record based on when a mail was last delivered. * @@ -793,9 +805,6 @@ function civicrm_api3_mailing_stats($params) { * @return array */ function civicrm_api3_mailing_update_email_resetdate($params) { - CRM_Mailing_Event_BAO_Delivered::updateEmailResetDate( - CRM_Utils_Array::value('minDays', $params, 3), - CRM_Utils_Array::value('maxDays', $params, 3) - ); + CRM_Mailing_Event_BAO_Delivered::updateEmailResetDate((int) $params['minDays'], (int) $params['maxDays']); return civicrm_api3_create_success(); } -- 2.25.1