From 3ff238ae7ff2c1e44450a5b98f8e8bcdea456f83 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Sat, 6 Aug 2016 20:32:34 +1200 Subject: [PATCH] CRM-19836 Enable activity create from replies to CiviMail. This relies on a parameter being added to the api call: civicrm_api3('Job', 'fetch_bounces', array('is_create_activities' => TRUE)); --- CRM/Utils/Mail/EmailProcessor.php | 20 +++++++++----------- api/v3/Job.php | 22 +++++++++++++++------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CRM/Utils/Mail/EmailProcessor.php b/CRM/Utils/Mail/EmailProcessor.php index 2e8c14a991..3acb4a68fb 100644 --- a/CRM/Utils/Mail/EmailProcessor.php +++ b/CRM/Utils/Mail/EmailProcessor.php @@ -44,22 +44,18 @@ class CRM_Utils_Mail_EmailProcessor { /** * Process the default mailbox (ie. that is used by civiMail for the bounce) * - * @return bool - * Always returns true (for the api). at a later stage we should - * fix this to return true on success / false on failure etc. + * @param bool $is_create_activities + * Should activities be created */ - public static function processBounces() { + public static function processBounces($is_create_activities) { $dao = new CRM_Core_DAO_MailSettings(); $dao->domain_id = CRM_Core_Config::domainID(); $dao->is_default = TRUE; $dao->find(); while ($dao->fetch()) { - self::_process(TRUE, $dao); + self::_process(TRUE, $dao, $is_create_activities); } - - // always returns true, i.e. never fails :) - return TRUE; } /** @@ -102,7 +98,7 @@ class CRM_Utils_Mail_EmailProcessor { $found = FALSE; while ($dao->fetch()) { $found = TRUE; - self::_process(FALSE, $dao); + self::_process(FALSE, $dao, $is_create_activities); } if (!$found) { CRM_Core_Error::fatal(ts('No mailboxes have been configured for Email to Activity Processing')); @@ -128,10 +124,12 @@ class CRM_Utils_Mail_EmailProcessor { /** * @param $civiMail * @param CRM_Core_DAO $dao + * @param bool $is_create_activities + * Create activities. * * @throws Exception */ - public static function _process($civiMail, $dao) { + public static function _process($civiMail, $dao, $is_create_activities) { // 0 = activities; 1 = bounce; $usedfor = $dao->is_default; @@ -234,7 +232,7 @@ class CRM_Utils_Mail_EmailProcessor { } // preseve backward compatibility - if ($usedfor == 0 || !$civiMail) { + if ($usedfor == 0 || $is_create_activities) { // if its the activities that needs to be processed .. try { $mailParams = CRM_Utils_Mail_Incoming::parseMailingObject($mail); diff --git a/api/v3/Job.php b/api/v3/Job.php index 89f4fb0d3b..8cd1b2af27 100644 --- a/api/v3/Job.php +++ b/api/v3/Job.php @@ -358,15 +358,23 @@ function civicrm_api3_job_fetch_bounces($params) { if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); } - if (!CRM_Utils_Mail_EmailProcessor::processBounces()) { - $lock->release(); - return civicrm_api3_create_error('Process Bounces failed'); - } + CRM_Utils_Mail_EmailProcessor::processBounces($params['is_create_activities']); $lock->release(); - // FIXME: processBounces doesn't return true/false on success/failure - $values = array(); - return civicrm_api3_create_success($values, $params, 'Job', 'fetch_bounces'); + return civicrm_api3_create_success(1, $params, 'Job', 'fetch_bounces'); +} + +/** + * Metadata for bounce function. + * + * @param array $params + */ +function _civicrm_api3_job_fetch_bounces_spec(&$params) { + $params['is_create_activities'] = array( + 'api.default' => 0, + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'title' => ts('Create activities for replies?'), + ); } /** -- 2.25.1