From cc3c3fcc5b4eaf320d1a21fd4b940ac6cb79a8a4 Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Thu, 28 Mar 2013 15:41:44 -0400 Subject: [PATCH] validate Mailer Settings admin form --- CRM/Admin/Form/Setting/Mail.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CRM/Admin/Form/Setting/Mail.php b/CRM/Admin/Form/Setting/Mail.php index 6440da05c9..40f7aa0c30 100644 --- a/CRM/Admin/Form/Setting/Mail.php +++ b/CRM/Admin/Form/Setting/Mail.php @@ -57,8 +57,31 @@ class CRM_Admin_Form_Setting_Mail extends CRM_Admin_Form_Setting { // redirect to Administer Section After hitting either Save or Cancel button. $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1')); + + $this->addFormRule(array('CRM_Admin_Form_Setting_Mail', 'formRule')); + $this->addRule('mailerBatchLimit', ts('Must be an integer'), 'integer'); + $this->addRule('mailThrottleTime', ts('Must be an integer'), 'integer'); + $this->addRule('mailerJobSize', ts('Must be an integer'), 'integer'); + $this->addRule('mailerJobsMax', ts('Must be an integer'), 'integer'); parent::buildQuickForm($check); } + + static function formRule($fields) { + $errors = array(); + + if (CRM_Utils_Array::value('mailerJobSize', $fields) < 1000 + && CRM_Utils_Array::value('mailerJobSize', $fields) > 0) { + $errors['mailerJobSize'] = ts('The job size must be at least 1000 or set to 0 (unlimited).'); + } + elseif (CRM_Utils_Array::value('mailerJobSize', $fields) < + CRM_Utils_Array::value('mailerBatchLimit', $fields) + && CRM_Utils_Array::value('mailerBatchLimit', $fields) > 0 + && CRM_Utils_Array::value('mailerJobSize', $fields) > 0) { + $errors['mailerJobSize'] = ts('A job size smaller than the batch limit will negate the effect of the batch limit.'); + } + + return empty($errors) ? TRUE : $errors; + } } -- 2.25.1