3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This api exposes CiviCRM dedupe functionality.
15 * @package CiviCRM_APIv3
19 * Get rows for any cached attempted merges on the passed criteria.
21 * @param array $params
24 * @throws \API_Exception
26 function civicrm_api3_dedupe_get($params) {
27 $sql = CRM_Utils_SQL_Select
::fragment();
28 $sql->where(['merge_data_restriction' => "cachekey LIKE 'merge_%'"]);
30 $options = _civicrm_api3_get_options_from_params($params, TRUE, 'PrevNextCache', 'get');
31 $result = _civicrm_api3_basic_get('CRM_Core_BAO_PrevNextCache', $params, FALSE, 'PrevNextCache', $sql);
33 if ($options['is_count']) {
34 return civicrm_api3_create_success($result, $params, 'PrevNextCache', 'get');
36 foreach ($result as $index => $values) {
37 if (isset($values['data']) && !empty($values['data'])) {
38 $result[$index]['data'] = CRM_Core_DAO
::unSerializeField($values['data'], CRM_Core_DAO
::SERIALIZE_PHP
);
41 return civicrm_api3_create_success($result, $params, 'PrevNextCache');
45 * Get rows for getting dedupe cache records.
47 * @param array $params
49 function _civicrm_api3_dedupe_get_spec(&$params) {
50 $params = CRM_Core_DAO_PrevNextCache
::fields();
51 $params['id']['api.aliases'] = ['dedupe_id'];
55 * Delete rows for any cached attempted merges on the passed criteria.
57 * @param array $params
61 * @throws \API_Exception
62 * @throws \Civi\API\Exception\UnauthorizedException
64 function civicrm_api3_dedupe_delete($params) {
65 return _civicrm_api3_basic_delete('CRM_Core_BAO_PrevNextCache', $params);
69 * Get the statistics for any cached attempted merges on the passed criteria.
71 * @param array $params
74 * @throws \API_Exception
75 * @throws \Civi\API\Exception\UnauthorizedException
77 function civicrm_api3_dedupe_create($params) {
78 return _civicrm_api3_basic_create('CRM_Core_BAO_PrevNextCache', $params, 'PrevNextCache');
82 * Get the statistics for any cached attempted merges on the passed criteria.
84 * @param array $params
87 * @throws \CiviCRM_API3_Exception
89 function civicrm_api3_dedupe_getstatistics($params) {
90 $stats = CRM_Dedupe_Merger
::getMergeStats(CRM_Dedupe_Merger
::getMergeCacheKeyString(
91 $params['rule_group_id'],
92 CRM_Utils_Array
::value('group_id', $params),
93 CRM_Utils_Array
::value('criteria', $params, []),
94 !empty($params['check_permissions']),
95 CRM_Utils_Array
::value('search_limit', $params, 0)
97 return civicrm_api3_create_success($stats);
101 * Adjust Metadata for Create action.
103 * The metadata is used for setting defaults, documentation & validation.
105 * @param array $params
106 * Array of parameters determined by getfields.
108 function _civicrm_api3_dedupe_getstatistics_spec(&$params) {
109 $params['rule_group_id'] = [
110 'title' => ts('Rule Group ID'),
111 'api.required' => TRUE,
112 'type' => CRM_Utils_Type
::T_INT
,
114 $params['group_id'] = [
115 'title' => ts('Group ID'),
116 'api.required' => FALSE,
117 'type' => CRM_Utils_Type
::T_INT
,
119 $params['criteria'] = [
120 'title' => ts('Criteria'),
121 'description' => ts('Dedupe search criteria, as parsable by v3 Contact.get api'),
123 $spec['search_limit'] = [
124 'title' => ts('Number of contacts to look for matches for.'),
125 'type' => CRM_Utils_Type
::T_INT
,
126 'api.default' => (int) Civi
::settings()->get('dedupe_default_limit'),
132 * Get the duplicate contacts for the supplied parameters.
134 * @param array $params
137 * @throws \CiviCRM_API3_Exception
138 * @throws \API_Exception
139 * @throws \CRM_Core_Exception
141 function civicrm_api3_dedupe_getduplicates($params) {
142 $options = _civicrm_api3_get_options_from_params($params);
143 $dupePairs = CRM_Dedupe_Merger
::getDuplicatePairs($params['rule_group_id'], NULL, TRUE, $options['limit'], FALSE, TRUE, $params['criteria'], CRM_Utils_Array
::value('check_permissions', $params), CRM_Utils_Array
::value('search_limit', $params, 0), CRM_Utils_Array
::value('is_force_new_search', $params));
144 return civicrm_api3_create_success($dupePairs);
148 * Adjust Metadata for getduplicates action..
150 * The metadata is used for setting defaults, documentation & validation.
152 * @param array $params
153 * Array of parameters determined by getfields.
155 function _civicrm_api3_dedupe_getduplicates_spec(&$params) {
156 $params['rule_group_id'] = [
157 'title' => ts('Rule Group ID'),
158 'api.required' => TRUE,
159 'type' => CRM_Utils_Type
::T_INT
,
161 $params['criteria'] = [
162 'title' => ts('Criteria'),
163 'description' => ts("Dedupe search criteria, as parsable by v3 Contact.get api, keyed by Contact. Eg.['Contact' => ['id' => ['BETWEEN' => [1, 2000]], 'group' => 34]"),
166 $spec['search_limit'] = [
167 'title' => ts('Number of contacts to look for matches for.'),
168 'type' => CRM_Utils_Type
::T_INT
,
169 'api.default' => (int) Civi
::settings()->get('dedupe_default_limit'),
171 $spec['is_force_new_search'] = [
172 'title' => ts('Force a new search, refreshing any cached search'),
173 'type' => CRM_Utils_Type
::T_BOOLEAN
,