From 76ddbc8e15714cba82899247bccaa93924212ad9 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 4 May 2016 11:57:12 +1200 Subject: [PATCH] CRM-18497 add first very basic test to job.merge The test doesn't check any functionality, just the fact it runs without error. More to come --- CRM/Dedupe/Merger.php | 2 +- api/v3/Job.php | 21 +++--- api/v3/RuleGroup.php | 83 +++++++++++++++++++++ tests/phpunit/CiviTest/CiviUnitTestCase.php | 1 - tests/phpunit/api/v3/JobTest.php | 9 ++- 5 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 api/v3/RuleGroup.php diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 3558ccd612..e1f1bd7343 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -586,7 +586,7 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m * A 'safe' value skips the merge if there are any un-resolved conflicts. * Does a force merge otherwise. * @param bool $autoFlip to let api decide which contact to retain and which to delete. - * Wether to let api decide which contact to retain and which to delete. + * Whether to let api decide which contact to retain and which to delete. * @param int $batchLimit number of merges to carry out in one batch. * @param int $isSelected if records with is_selected column needs to be processed. * diff --git a/api/v3/Job.php b/api/v3/Job.php index 306f6de0aa..33605856c2 100644 --- a/api/v3/Job.php +++ b/api/v3/Job.php @@ -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( diff --git a/api/v3/RuleGroup.php b/api/v3/RuleGroup.php new file mode 100644 index 0000000000..bbd4ff05bb --- /dev/null +++ b/api/v3/RuleGroup.php @@ -0,0 +1,83 @@ + 'Semi-formal explanation of runtime job parameters', 'is_active' => 1, ); - $result = $this->callAPIFailure('job', 'create', $params); + $this->callAPIFailure('job', 'create', $params); } /** @@ -296,6 +296,13 @@ class api_v3_JobTest extends CiviUnitTestCase { $this->contactDelete($orgID); } + /** + * Test the batch merge function. + */ + public function testBatchMerge() { + $this->callAPISuccess('Job', 'process_batch_merge', array()); + } + /** * @param $op * @param string $objectName -- 2.25.1