From 17b3b987fc3de962a8cc43ee94f1b88169e5c0a9 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 6 Mar 2015 20:29:24 -0800 Subject: [PATCH] CRM-16063 - MailingComponent.create API - Fix management of is_default --- CRM/Mailing/BAO/Component.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/CRM/Mailing/BAO/Component.php b/CRM/Mailing/BAO/Component.php index 853dc3454a..3da5da0dbc 100644 --- a/CRM/Mailing/BAO/Component.php +++ b/CRM/Mailing/BAO/Component.php @@ -92,7 +92,11 @@ class CRM_Mailing_BAO_Component extends CRM_Mailing_DAO_Component { 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->id = $id; + if ($id) { + $component->id = $id; + $component->find(TRUE); + } + $component->copyValues($params); if (empty($id) && empty($params['body_text'])) { $component->body_text = CRM_Utils_String::htmlToText(CRM_Utils_Array::value('body_html', $params)); @@ -100,11 +104,19 @@ class CRM_Mailing_BAO_Component extends CRM_Mailing_DAO_Component { if ($component->is_default) { if (!empty($id)) { - CRM_Core_DAO::executeQuery("UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type ='{$component->component_type}' AND id <> $id"); + $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1 AND id <> %2'; + $sqlParams = array( + 1 => array($component->component_type, 'String'), + 2 => array($id, 'Positive'), + ); } else { - CRM_Core_DAO::executeQuery("UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type ='{$component->component_type}'"); + $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1'; + $sqlParams = array( + 1 => array($component->component_type, 'String'), + ); } + CRM_Core_DAO::executeQuery($sql, $sqlParams); } $component->save(); -- 2.25.1