From: eileen Date: Thu, 25 Jul 2013 03:25:28 +0000 (+1200) Subject: CRM-13072 standardise tag api to fix errors revealed by upgraded tests X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d989d349d8c84344fe4ca3237838c9272a67808f;p=civicrm-core.git CRM-13072 standardise tag api to fix errors revealed by upgraded tests --- diff --git a/CRM/Core/BAO/Tag.php b/CRM/Core/BAO/Tag.php index 17a802f1a5..6249909fae 100644 --- a/CRM/Core/BAO/Tag.php +++ b/CRM/Core/BAO/Tag.php @@ -297,13 +297,14 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { * pairs * * @param array $params (reference) an assoc array of name/value pairs - * @param array $ids (reference) the array that holds all the db ids + * @param array $ids (optional) the array that holds all the db ids - we are moving away from this in bao + * signatures * * @return object CRM_Core_DAO_Tag object on success, otherwise null * @access public * @static */ - static function add(&$params, &$ids) { + static function add(&$params, $ids = array()) { if (!self::dataExists($params)) { return NULL; } @@ -317,15 +318,9 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { } $tag->copyValues($params); - $tag->id = CRM_Utils_Array::value('tag', $ids); - - $edit = ($tag->id) ? TRUE : FALSE; - if ($edit) { - CRM_Utils_Hook::pre('edit', 'Tag', $tag->id, $tag); - } - else { - CRM_Utils_Hook::pre('create', 'Tag', NULL, $tag); - } + $tag->id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('tag', $ids)); + $hook = empty($params['id']) ? 'create' : 'edit'; + CRM_Utils_Hook::pre($hook, 'Tag', $tag->id, $params); // save creator id and time if (!$tag->id) { @@ -335,13 +330,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { } $tag->save(); - - if ($edit) { - CRM_Utils_Hook::post('edit', 'Tag', $tag->id, $tag); - } - else { - CRM_Utils_Hook::post('create', 'Tag', NULL, $tag); - } + CRM_Utils_Hook::post($hook, 'Tag', $tag->id, $tag); // if we modify parent tag, then we need to update all children if ($tag->parent_id === 'null') { diff --git a/api/v3/Tag.php b/api/v3/Tag.php index 2d4e01da67..d8129e2703 100644 --- a/api/v3/Tag.php +++ b/api/v3/Tag.php @@ -1,5 +1,4 @@ CRM_Utils_Array::value('tag', $params)); - if (CRM_Utils_Array::value('tag', $params)) { - $ids['tag'] = $params['tag']; - } - if (CRM_Utils_Array::value('id', $params)) { - $ids['tag'] = $params['id']; - } - $tagBAO = CRM_Core_BAO_Tag::add($params, $ids); - - $values = array(); - _civicrm_api3_object_to_array($tagBAO, $values[$tagBAO->id]); - return civicrm_api3_create_success($values, $params, 'tag', 'create', $tagBAO); - } + return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); +} /** * Specify Meta data for create. Note that this data is retrievable via the getfields function