From: Donald A. Lobo Date: Fri, 26 Apr 2013 18:08:06 +0000 (-0700) Subject: CRM-12430 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9510d1b1833e14854574903f4c0bfdd5bdc0076f;p=civicrm-core.git CRM-12430 ---------------------------------------- * CRM-12430: CRM_Mailing_BAO_Mailing:create changes all mailing settings back to default http://issues.civicrm.org/jira/browse/CRM-12430 --- diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index b3b406ea3c..74d59edb7c 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -1479,60 +1479,70 @@ ORDER BY civicrm_email.is_bulkmail DESC * @static */ public static function create(&$params, $ids = array()) { - // Retrieve domain email and name for default sender - $domain = civicrm_api('Domain', 'getsingle', array( - 'version' => 3, - 'current_domain' => 1, - 'sequential' => 1, - )); - if (isset($domain['from_email'])) { - $domain_email = $domain['from_email']; - $domain_name = $domain['from_name']; - } - else { - $domain_email = 'info@EXAMPLE.ORG'; - $domain_name = 'EXAMPLE.ORG'; - } - if (!isset($params['created_id'])) { - $session =& CRM_Core_Session::singleton(); - $params['created_id'] = $session->get('userID'); - } - $defaults = array( - // load the default config settings for each - // eg reply_id, unsubscribe_id need to use - // correct template IDs here - 'override_verp' => TRUE, - 'forward_replies' => FALSE, - 'open_tracking' => TRUE, - 'url_tracking' => TRUE, - 'visibility' => 'User and User Admin Only', - 'replyto_email' => $domain_email, - 'header_id' => CRM_Mailing_PseudoConstant::defaultComponent('header_id', ''), - 'footer_id' => CRM_Mailing_PseudoConstant::defaultComponent('footer_id', ''), - 'from_email' => $domain_email, - 'from_name' => $domain_name, - 'msg_template_id' => NULL, - 'contact_id' => $params['created_id'], - 'created_id' => $params['created_id'], - 'approver_id' => $params['created_id'], - 'auto_responder' => 0, - 'created_date' => date('YmdHis'), - 'scheduled_date' => date('YmdHis'), - 'approval_date' => date('YmdHis'), - ); - // Get the default from email address, if not provided. - if (empty($defaults['from_email'])) { - $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); - foreach ($defaultAddress as $id => $value) { - if (preg_match('/"(.*)" <(.*)>/', $value, $match)) { - $defaults['from_email'] = $match[2]; - $defaults['from_name'] = $match[1]; + // CRM-12430 + // Do the below only for an insert + // for an update, we should not set the defaults + if (!isset($ids['id']) && !isset($ids['mailing_id'])) { + // Retrieve domain email and name for default sender + $domain = civicrm_api( + 'Domain', + 'getsingle', + array( + 'version' => 3, + 'current_domain' => 1, + 'sequential' => 1, + ) + ); + if (isset($domain['from_email'])) { + $domain_email = $domain['from_email']; + $domain_name = $domain['from_name']; + } + else { + $domain_email = 'info@EXAMPLE.ORG'; + $domain_name = 'EXAMPLE.ORG'; + } + if (!isset($params['created_id'])) { + $session =& CRM_Core_Session::singleton(); + $params['created_id'] = $session->get('userID'); + } + $defaults = array( + // load the default config settings for each + // eg reply_id, unsubscribe_id need to use + // correct template IDs here + 'override_verp' => TRUE, + 'forward_replies' => FALSE, + 'open_tracking' => TRUE, + 'url_tracking' => TRUE, + 'visibility' => 'User and User Admin Only', + 'replyto_email' => $domain_email, + 'header_id' => CRM_Mailing_PseudoConstant::defaultComponent('header_id', ''), + 'footer_id' => CRM_Mailing_PseudoConstant::defaultComponent('footer_id', ''), + 'from_email' => $domain_email, + 'from_name' => $domain_name, + 'msg_template_id' => NULL, + 'contact_id' => $params['created_id'], + 'created_id' => $params['created_id'], + 'approver_id' => $params['created_id'], + 'auto_responder' => 0, + 'created_date' => date('YmdHis'), + 'scheduled_date' => date('YmdHis'), + 'approval_date' => date('YmdHis'), + ); + + // Get the default from email address, if not provided. + if (empty($defaults['from_email'])) { + $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); + foreach ($defaultAddress as $id => $value) { + if (preg_match('/"(.*)" <(.*)>/', $value, $match)) { + $defaults['from_email'] = $match[2]; + $defaults['from_name'] = $match[1]; + } } } - } - $params = array_merge($defaults, $params); + $params = array_merge($defaults, $params); + } /** * Could check and warn for the following cases: @@ -1559,7 +1569,7 @@ ORDER BY civicrm_email.is_bulkmail DESC foreach (array('include', 'exclude', 'base') as $type) { if (isset($params[$entity]) && CRM_Utils_Array::value($type, $params[$entity]) && - is_array($params[$entity][$type])) { + is_array($params[$entity][$type])) { foreach ($params[$entity][$type] as $entityId) { $mg->reset(); $mg->mailing_id = $mailing->id; @@ -1744,7 +1754,7 @@ ORDER BY civicrm_email.is_bulkmail DESC $row['id'] = $mailing->group_id; $row['name'] = $mailing->group_title; $row['link'] = CRM_Utils_System::url('civicrm/group/search', - "reset=1&force=1&context=smog&gid={$row['id']}" + "reset=1&force=1&context=smog&gid={$row['id']}" ); } else { @@ -1752,7 +1762,7 @@ ORDER BY civicrm_email.is_bulkmail DESC $row['name'] = $mailing->mailing_name; $row['mailing'] = TRUE; $row['link'] = CRM_Utils_System::url('civicrm/mailing/report', - "mid={$row['id']}" + "mid={$row['id']}" ); } @@ -1891,7 +1901,7 @@ ORDER BY civicrm_email.is_bulkmail DESC ); foreach (array( - 'scheduled_date', 'start_date', 'end_date') as $key) { + 'scheduled_date', 'start_date', 'end_date') as $key) { $row[$key] = CRM_Utils_Date::customFormat($row[$key]); } $report['jobs'][] = $row;