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)); } if ($component->is_default) { if (!empty($id)) { $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1 AND id <> %2'; $sqlParams = [ 1 => [$component->component_type, 'String'], 2 => [$id, 'Positive'], ]; } else { $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1'; $sqlParams = [ 1 => [$component->component_type, 'String'], ]; } CRM_Core_DAO::executeQuery($sql, $sqlParams); } $component->save(); return $component; } }