From: Tim Otten Date: Sat, 5 Sep 2015 19:23:13 +0000 (-0700) Subject: CRM-16373 - Mailer settings - Remove reliance on CRM_Core_BAO_ConfigSetting::create X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=dc00ac6d27486ca332116a99f013417896588a42;p=civicrm-core.git CRM-16373 - Mailer settings - Remove reliance on CRM_Core_BAO_ConfigSetting::create --- diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 27e00ee321..6c134c8b22 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -2847,8 +2847,9 @@ WHERE civicrm_mailing_job.id = %1 // CRM-8460 $gotCronLock = FALSE; - if (property_exists($config, 'mailerJobsMax') && $config->mailerJobsMax && $config->mailerJobsMax > 0) { - $lockArray = range(1, $config->mailerJobsMax); + $mailerJobsMax = Civi::settings()->get('mailerJobsMax'); + if (is_numeric($mailerJobsMax) && $mailerJobsMax > 0) { + $lockArray = range(1, $mailerJobsMax); shuffle($lockArray); // check if we are using global locks @@ -2875,7 +2876,7 @@ WHERE civicrm_mailing_job.id = %1 // load bootstrap to call hooks // Split up the parent jobs into multiple child jobs - $mailerJobSize = (property_exists($config, 'mailerJobSize')) ? $config->mailerJobSize : NULL; + $mailerJobSize = Civi::settings()->get('mailerJobSize'); CRM_Mailing_BAO_MailingJob::runJobs_pre($mailerJobSize, $mode); CRM_Mailing_BAO_MailingJob::runJobs(NULL, $mode); CRM_Mailing_BAO_MailingJob::runJobs_post($mode); diff --git a/CRM/Mailing/BAO/MailingJob.php b/CRM/Mailing/BAO/MailingJob.php index 6b51a925aa..5ccb3a94b2 100644 --- a/CRM/Mailing/BAO/MailingJob.php +++ b/CRM/Mailing/BAO/MailingJob.php @@ -565,16 +565,14 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) // have been delivered in prior jobs $isDelivered = TRUE; - // make sure that there's no more than $config->mailerBatchLimit mails processed in a run + // make sure that there's no more than $mailerBatchLimit mails processed in a run + $mailerBatchLimit = Civi::settings()->get('mailerBatchLimit'); while ($eq->fetch()) { // if ( ( $mailsProcessed % 100 ) == 0 ) { // CRM_Utils_System::xMemory( "$mailsProcessed: " ); // } - if ( - $config->mailerBatchLimit > 0 && - self::$mailsProcessed >= $config->mailerBatchLimit - ) { + if ($mailerBatchLimit > 0 && self::$mailsProcessed >= $mailerBatchLimit) { if (!empty($fields)) { $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments); } @@ -798,8 +796,9 @@ VALUES (%1, %2, %3, %4, %5, %6, %7) } // If we have enabled the Throttle option, this is the time to enforce it. - if (isset($config->mailThrottleTime) && $config->mailThrottleTime > 0) { - usleep((int ) $config->mailThrottleTime); + $mailThrottleTime = Civi::settings()->get('mailThrottleTime'); + if (!empty($mailThrottleTime)) { + usleep((int ) $mailThrottleTime); } } diff --git a/CRM/Mailing/Page/Browse.php b/CRM/Mailing/Page/Browse.php index e377f1e129..a50bbaea47 100644 --- a/CRM/Mailing/Page/Browse.php +++ b/CRM/Mailing/Page/Browse.php @@ -124,8 +124,8 @@ class CRM_Mailing_Page_Browse extends CRM_Core_Page { // since we want only first function argument $newArgs = $newArgs[0]; if (isset($_GET['runJobs']) || CRM_Utils_Array::value('2', $newArgs) == 'queue') { - $config = CRM_Core_Config::singleton(); - CRM_Mailing_BAO_MailingJob::runJobs_pre($config->mailerJobSize); + $mailerJobSize = Civi::settings()->get('mailerJobSize'); + CRM_Mailing_BAO_MailingJob::runJobs_pre($mailerJobSize); CRM_Mailing_BAO_MailingJob::runJobs(); CRM_Mailing_BAO_MailingJob::runJobs_post(); } diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index 19d4c7b7f4..8dd5578752 100755 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -632,7 +632,7 @@ function civicrm_api3_mailing_send_test($params) { $isComplete = FALSE; $config = CRM_Core_Config::singleton(); - $mailerJobSize = (property_exists($config, 'mailerJobSize')) ? $config->mailerJobSize : NULL; + $mailerJobSize = Civi::settings()->get('mailerJobSize'); while (!$isComplete) { // Q: In CRM_Mailing_BAO_Mailing::processQueue(), the three runJobs*() // functions are all called. Why does Mailing.send_test only call one? diff --git a/tests/phpunit/api/v3/JobProcessMailingTest.php b/tests/phpunit/api/v3/JobProcessMailingTest.php index d518a1ec24..6a914d08cd 100644 --- a/tests/phpunit/api/v3/JobProcessMailingTest.php +++ b/tests/phpunit/api/v3/JobProcessMailingTest.php @@ -99,7 +99,7 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { public function testBasic() { $this->createContactsInGroup(10, $this->_groupID); - $this->setSettings(array( + Civi::settings()->add(array( 'mailerBatchLimit' => 2, )); $this->callAPISuccess('mailing', 'create', $this->_params); @@ -238,7 +238,7 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { $settings = array_merge($this->defaultSettings, $settings); $this->createContactsInGroup($settings['recipients'], $this->_groupID); - $this->setSettings(CRM_Utils_Array::subset($settings, array( + Civi::settings()->add(CRM_Utils_Array::subset($settings, array( 'mailerBatchLimit', 'mailerJobsMax', 'mailThrottleTime', @@ -303,19 +303,6 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase { return $recipients; } - /** - * @param array $params - * - mailerBatchLimit - * - mailerJobSize - * - mailerJobsMax - * - mailThrottleTime - */ - protected function setSettings($params) { - // FIXME: These settings are not available via Setting API. - // When they become available, use that instead. - CRM_Core_BAO_ConfigSetting::create($params); - } - protected function cleanupMailingTest() { $this->quickCleanup(array( 'civicrm_mailing',