From: Eileen McNaughton Date: Sun, 27 Apr 2014 21:11:36 +0000 (-0700) Subject: test fix - alter MailingComponent BAO to handle updating correctly & be more standardised X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2d75534c794f1225dbdf082dac03b5afeec4e4bd;p=civicrm-core.git test fix - alter MailingComponent BAO to handle updating correctly & be more standardised --- diff --git a/CRM/Mailing/BAO/Component.php b/CRM/Mailing/BAO/Component.php index a1364b9f10..2c23cdf5d5 100644 --- a/CRM/Mailing/BAO/Component.php +++ b/CRM/Mailing/BAO/Component.php @@ -89,33 +89,20 @@ class CRM_Mailing_BAO_Component extends CRM_Mailing_DAO_Component { * @access public * @static */ - static function add(&$params, &$ids = array()) { - // action is taken depending upon the mode + static function add(&$params, $ids = array()) { + $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); $component = new CRM_Mailing_DAO_Component(); - $component->name = $params['name']; - $component->component_type = CRM_Utils_Array::value('component_type', $params); - $component->subject = CRM_Utils_Array::value('subject', $params); - if (CRM_Utils_Array::value('body_text', $params)) { - $component->body_text = CRM_Utils_Array::value('body_text', $params); - } - else { + $component->id = $id; + $component->copyValues($params); + if (empty($id) && empty($params['body_text'])) { $component->body_text = CRM_Utils_String::htmlToText(CRM_Utils_Array::value('body_html', $params)); } - $component->body_html = CRM_Utils_Array::value('body_html', $params); - $component->is_active = CRM_Utils_Array::value('is_active', $params, FALSE); - $component->is_default = CRM_Utils_Array::value('is_default', $params, FALSE); if ($component->is_default) { - $query = "UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type ='{$component->component_type}'"; - CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); + CRM_Core_DAO::executeQuery("UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type ='{$component->component_type}' AND id <> $id"); } - $component->id = CRM_Utils_Array::value('id', $ids); - $component->save(); - - CRM_Core_Session::setStatus(ts('The mailing component \'%1\' has been saved.', - array(1 => $component->name) - ), ts('Saved'), 'success'); + return $component; } } diff --git a/CRM/Mailing/Form/Component.php b/CRM/Mailing/Form/Component.php index 7704167b58..f6ca5a05cc 100644 --- a/CRM/Mailing/Form/Component.php +++ b/CRM/Mailing/Form/Component.php @@ -137,13 +137,16 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); - $ids = array(); - if ($this->_action & CRM_Core_Action::UPDATE) { - $ids['id'] = $this->_id; + $params['id'] = $this->_id; } - CRM_Mailing_BAO_Component::add($params, $ids); + $component = CRM_Mailing_BAO_Component::add($params); + CRM_Core_Session::setStatus(ts('The mailing component \'%1\' has been saved.', array( + 1 => $component->name + ) + ), ts('Saved'), 'success'); + } //end of function