X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FGroupContact.php;h=20290e2c690150f6ed2472516c773d609a568e34;hb=6b83d5bdd0f2ca546924feae6aa42aeddb1d40cf;hp=3ac3b2b0eb1986ed3af59eff947021ce5a1b7813;hpb=412f2d1627d0a075f872064df40968b7adfcf51f;p=civicrm-core.git diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index 3ac3b2b0eb..20290e2c69 100644 --- a/CRM/Contact/BAO/GroupContact.php +++ b/CRM/Contact/BAO/GroupContact.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 5 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2018 | + | Copyright CiviCRM LLC (c) 2004-2019 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -28,7 +28,7 @@ /** * * @package CRM - * @copyright CiviCRM LLC (c) 2004-2018 + * @copyright CiviCRM LLC (c) 2004-2019 */ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { @@ -51,17 +51,27 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { * * @return CRM_Contact_BAO_Group */ - public static function add(&$params) { + public static function add($params) { + $hook = empty($params['id']) ? 'create' : 'edit'; + CRM_Utils_Hook::pre($hook, 'GroupContact', CRM_Utils_Array::value('id', $params), $params); - $dataExists = self::dataExists($params); - if (!$dataExists) { + if (!self::dataExists($params)) { return NULL; } $groupContact = new CRM_Contact_BAO_GroupContact(); $groupContact->copyValues($params); - CRM_Contact_BAO_SubscriptionHistory::create($params); $groupContact->save(); + + // Lookup existing info for the sake of subscription history + if (!empty($params['id'])) { + $groupContact->find(TRUE); + $params = $groupContact->toArray(); + } + CRM_Contact_BAO_SubscriptionHistory::create($params); + + CRM_Utils_Hook::post($hook, 'GroupContact', $groupContact->id, $groupContact); + return $groupContact; } @@ -74,12 +84,7 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { * @return bool */ public static function dataExists(&$params) { - // return if no data present - if ($params['group_id'] == 0) { - return FALSE; - } - - return TRUE; + return (!empty($params['id']) || (!empty($params['group_id']) && !empty($params['contact_id']))); } /**