CRM-18497 add first very basic test to job.merge
[civicrm-core.git] / api / v3 / Job.php
index 306f6de0aaebe05adece766572f2692359894fff..33605856c270e2b3c9ddcaa77deb4094b236d83c 100644 (file)
@@ -474,22 +474,25 @@ function civicrm_api3_job_process_respondent($params) {
  *
  * @return array
  *   API Result Array
+ * @throws \CiviCRM_API3_Exception
  */
 function civicrm_api3_job_process_batch_merge($params) {
-  $rgid = CRM_Utils_Array::value('rgid', $params);
+  $rule_group_id = CRM_Utils_Array::value('rgid', $params);
+  if (!$rule_group_id) {
+    $rule_group_id = civicrm_api3('RuleGroup', 'getvalue', array(
+      'contact_type' => 'Individual',
+      'used' => 'Unsupervised',
+      'return' => 'id',
+    ));
+  }
   $gid = CRM_Utils_Array::value('gid', $params);
 
   $mode = CRM_Utils_Array::value('mode', $params, 'safe');
   $autoFlip = CRM_Utils_Array::value('auto_flip', $params, TRUE);
 
-  $result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, $mode, $autoFlip);
+  $result = CRM_Dedupe_Merger::batchMerge($rule_group_id, $gid, $mode, $autoFlip);
 
-  if ($result['is_error'] == 0) {
-    return civicrm_api3_create_success();
-  }
-  else {
-    return civicrm_api3_create_error($result['messages']);
-  }
+  return civicrm_api3_create_success($result, $params);
 }
 
 /**
@@ -499,7 +502,7 @@ function civicrm_api3_job_process_batch_merge($params) {
  */
 function _civicrm_api3_job_process_batch_merge_spec(&$params) {
   $params['rgid'] = array(
-    'title' => 'rule group id',
+    'title' => 'Dedupe rule group id, defaults to Contact Unsupervised rule',
     'type' => CRM_Utils_Type::T_INT,
   );
   $params['gid'] = array(