public static function relTables() {
static $relTables;
+ // Setting these merely prevents enotices - but it may be more appropriate not to add the user table below
+ // if the url can't be retrieved. A more standardised way to retrieve them is.
+ // CRM_Core_Config::singleton()->userSystem->getUserRecordUrl() - however that function takes a contact_id &
+ // we may need a different function when it is not known.
+ $title = $userRecordUrl = '';
+
$config = CRM_Core_Config::singleton();
if ($config->userSystem->is_drupal) {
$userRecordUrl = CRM_Utils_System::url('user/%ufid');
*
* @return array
* API Result Array
+ * @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),
+ $dupePairs = array(
+ array(
+ 'srcID' => CRM_Utils_Array::value('main_id', $params),
'dstID' => CRM_Utils_Array::value('other_id', $params),
- ));
- $result = CRM_Dedupe_Merger::merge($dupePairs, array(), $mode, $autoFlip);
+ ),
+ );
- if ($result['is_error'] == 0) {
- return civicrm_api3_create_success();
- }
- else {
- return civicrm_api3_create_error($result['messages']);
+ if (($result = CRM_Dedupe_Merger::merge($dupePairs, array(), $mode, $autoFlip)) != FALSE) {
+ return civicrm_api3_create_success($result, $params);
}
+ throw new CiviCRM_API3_Exception('Merge failed');
+}
+
+/**
+ * Adjust metadata for contact_proximity api function.
+ *
+ * @param array $params
+ */
+function _civicrm_api3_contact_merge_spec(&$params) {
+ $params['main_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,
+ );
+ $params['other_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,
+ );
}
/**
$this->assertContains($household['id'], array_keys($result['values']));
}
+ /**
+ * Test merging 2 contacts.
+ */
+ public function testMerge() {
+ $otherContact = $this->callAPISuccess('contact', 'create', $this->_params);
+ $mainContact = $this->callAPISuccess('contact', 'create', $this->_params);
+ $this->callAPISuccess('contact', 'merge', array('main_id' => $mainContact['id'], 'other_id' => $otherContact['id']));
+ $contacts = $this->callAPISuccess('contact', 'get', $this->_params);
+ $this->assertEquals($otherContact['id'], $contacts['id']);
+
+ }
+
}