Eileen has uploaded a new change for review. https://gerrit.wikimedia.org/r/277448
Change subject: CRM-18134 move api merge activity contact function to the BAO ...................................................................... CRM-18134 move api merge activity contact function to the BAO These changes are merged to master already Change-Id: I0462e17792fc25b98546ae1a17b6b3470705f884 --- M CRM/Contact/Form/Merge.php M CRM/Dedupe/Merger.php M api/v3/Contact.php 3 files changed, 35 insertions(+), 37 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm/civicrm refs/changes/48/277448/1 diff --git a/CRM/Contact/Form/Merge.php b/CRM/Contact/Form/Merge.php index 4c7cf41..ec750bf 100644 --- a/CRM/Contact/Form/Merge.php +++ b/CRM/Contact/Form/Merge.php @@ -333,20 +333,6 @@ $message = '<ul><li>' . ts('%1 has been updated.', array(1 => $name)) . '</li><li>' . ts('Contact ID %1 has been deleted.', array(1 => $this->_oid)) . '</li></ul>'; CRM_Core_Session::setStatus($message, ts('Contacts Merged'), 'success'); - //create activity for merge - //To do: this should be refactored into BAO layer at some point. - $messageActivity = ts('Contact ID %1 has been merged and deleted.', array(1 => $this->_oid)); - $activityParams = array( - 'subject' => $messageActivity, - 'source_contact_id' => $session->get('userID'), - 'target_contact_id' => $this->_cid, - 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Contact Merged'), - 'status_id' => 'Completed', - 'priority_id' => 'Normal', - 'activity_date_time' => date('YmdHis'), - ); - civicrm_api3('activity', 'create', $activityParams); - $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_cid}"); if (!empty($formValues['_qf_Merge_submit'])) { $listParamsURL = "reset=1&action=update&rgid={$this->_rgid}"; diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 3310878..53a046b 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1538,12 +1538,6 @@ CRM_Core_BAO_CustomValueTable::setValues($viewOnlyCustomFields); } - // **** Delete other contact & update prev-next caching - $otherParams = array( - 'contact_id' => $otherId, - 'id' => $otherId, - 'version' => 3, - ); if (CRM_Core_Permission::check('merge duplicate contacts') && CRM_Core_Permission::check('delete contacts') ) { @@ -1553,15 +1547,13 @@ CRM_Core_DAO::executeQuery($query); } - civicrm_api('contact', 'delete', $otherParams); + civicrm_api3('contact', 'delete', array('id' => $otherId)); CRM_Core_BAO_PrevNextCache::deleteItem($otherId); } // FIXME: else part - /* else { */ - - /* CRM_Core_Session::setStatus( ts('Do not have sufficient permission to delete duplicate contact.') ); */ - - /* } */ + // else { + // CRM_Core_Session::setStatus( ts('Do not have sufficient permission to delete duplicate contact.') ); + // } // CRM-15681 merge sub_types if ($other_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['other_details'])) { @@ -1602,6 +1594,17 @@ CRM_Utils_Hook::post('merge', 'Contact', $mainId, CRM_Core_DAO::$_nullObject); + // Create activity for merge. + $messageActivity = ts('Contact ID %1 has been merged and deleted.', array(1 => $otherId)); + civicrm_api3('activity', 'create', array( + 'subject' => $messageActivity, + 'source_contact_id' => CRM_Core_Session::singleton()->getLoggedInContactID(), + 'target_contact_id' => $mainId, + 'activity_type_id' => 'Contact Merged', + 'status_id' => 'Completed', + 'priority_id' => 'Normal', + )); + return TRUE; } diff --git a/api/v3/Contact.php b/api/v3/Contact.php index 87d9a1c..ccdc5ed 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -1006,36 +1006,45 @@ * @throws CiviCRM_API3_Exception */ function civicrm_api3_contact_merge($params) { - $mode = CRM_Utils_Array::value('mode', $params, 'safe'); - $autoFlip = CRM_Utils_Array::value('auto_flip', $params, TRUE); - - $dupePairs = array(array( - 'srcID' => CRM_Utils_Array::value('main_id', $params), - 'dstID' => CRM_Utils_Array::value('other_id', $params), - )); - if (($result = CRM_Dedupe_Merger::merge($dupePairs, array(), $mode, $autoFlip)) != FALSE) { + if (($result = CRM_Dedupe_Merger::merge(array( + array( + 'srcID' => $params['to_remove_id'], + 'dstID' => $params['to_keep_id'], + ), + ), array(), $params['mode'], $params['auto_flip'])) != FALSE) { return civicrm_api3_create_success($result, $params); } throw new CiviCRM_API3_Exception('Merge failed'); } /** - * Adjust metadata for contact_proximity api function. + * Adjust metadata for contact_merge api function. * * @param array $params */ function _civicrm_api3_contact_merge_spec(&$params) { - $params['main_id'] = array( + $params['to_remove_id'] = array( 'title' => 'ID of the contact to merge & remove', 'description' => ts('Wow - these 2 params are the logical reverse of what I expect - but what to do?'), 'api.required' => 1, 'type' => CRM_Utils_Type::T_INT, + 'api.aliases' => array('main_id'), ); - $params['other_id'] = array( + $params['to_keep_id'] = array( 'title' => 'ID of the contact to keep', 'description' => ts('Wow - these 2 params are the logical reverse of what I expect - but what to do?'), 'api.required' => 1, 'type' => CRM_Utils_Type::T_INT, + 'api.aliases' => array('other_id'), + ); + $params['auto_flip'] = array( + 'title' => 'Swap destination and source to retain lowest id?', + 'api.default' => TRUE, + ); + $params['mode'] = array( + // @todo need more detail on what this means. + 'title' => 'Dedupe mode', + 'api.default' => 'safe', ); } -- To view, visit https://gerrit.wikimedia.org/r/277448 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0462e17792fc25b98546ae1a17b6b3470705f884 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm/civicrm Gerrit-Branch: master Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits