3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This api exposes CiviCRM dedupe functionality.
31 * @package CiviCRM_APIv3
35 * Get rows for any cached attempted merges on the passed criteria.
37 * @param array $params
40 * @throws \API_Exception
42 function civicrm_api3_dedupe_get($params) {
43 $sql = CRM_Utils_SQL_Select
::fragment();
44 $sql->where(['merge_data_restriction' => "cachekey LIKE 'merge_%'"]);
46 $options = _civicrm_api3_get_options_from_params($params, TRUE, 'PrevNextCache', 'get');
47 $result = _civicrm_api3_basic_get('CRM_Core_BAO_PrevNextCache', $params, FALSE, 'PrevNextCache', $sql);
49 if ($options['is_count']) {
50 return civicrm_api3_create_success($result, $params, 'PrevNextCache', 'get');
52 foreach ($result as $index => $values) {
53 if (isset($values['data']) && !empty($values['data'])) {
54 $result[$index]['data'] = CRM_Core_DAO
::unSerializeField($values['data'], CRM_Core_DAO
::SERIALIZE_PHP
);
57 return civicrm_api3_create_success($result, $params, 'PrevNextCache');
61 * Get rows for getting dedupe cache records.
63 * @param array $params
65 function _civicrm_api3_dedupe_get_spec(&$params) {
66 $params = CRM_Core_DAO_PrevNextCache
::fields();
67 $params['id']['api.aliases'] = ['dedupe_id'];
71 * Delete rows for any cached attempted merges on the passed criteria.
73 * @param array $params
77 * @throws \API_Exception
78 * @throws \Civi\API\Exception\UnauthorizedException
80 function civicrm_api3_dedupe_delete($params) {
81 return _civicrm_api3_basic_delete('CRM_Core_BAO_PrevNextCache', $params);
85 * Get the statistics for any cached attempted merges on the passed criteria.
87 * @param array $params
90 * @throws \API_Exception
91 * @throws \Civi\API\Exception\UnauthorizedException
93 function civicrm_api3_dedupe_create($params) {
94 return _civicrm_api3_basic_create('CRM_Core_BAO_PrevNextCache', $params, 'PrevNextCache');
98 * Get the statistics for any cached attempted merges on the passed criteria.
100 * @param array $params
103 * @throws \CiviCRM_API3_Exception
105 function civicrm_api3_dedupe_getstatistics($params) {
106 $stats = CRM_Dedupe_Merger
::getMergeStats(CRM_Dedupe_Merger
::getMergeCacheKeyString(
107 $params['rule_group_id'],
108 CRM_Utils_Array
::value('group_id', $params),
109 CRM_Utils_Array
::value('criteria', $params, []),
110 !empty($params['check_permissions']),
111 CRM_Utils_Array
::value('search_limit', $params, 0)
113 return civicrm_api3_create_success($stats);
117 * Adjust Metadata for Create action.
119 * The metadata is used for setting defaults, documentation & validation.
121 * @param array $params
122 * Array of parameters determined by getfields.
124 function _civicrm_api3_dedupe_getstatistics_spec(&$params) {
125 $params['rule_group_id'] = [
126 'title' => ts('Rule Group ID'),
127 'api.required' => TRUE,
128 'type' => CRM_Utils_Type
::T_INT
,
130 $params['group_id'] = [
131 'title' => ts('Group ID'),
132 'api.required' => FALSE,
133 'type' => CRM_Utils_Type
::T_INT
,
135 $params['criteria'] = [
136 'title' => ts('Criteria'),
137 'description' => ts('Dedupe search criteria, as parsable by v3 Contact.get api'),
139 $spec['search_limit'] = [
140 'title' => ts('Number of contacts to look for matches for.'),
141 'type' => CRM_Utils_Type
::T_INT
,
142 'api.default' => (int) Civi
::settings()->get('dedupe_default_limit'),
148 * Get the duplicate contacts for the supplied parameters.
150 * @param array $params
153 * @throws \CiviCRM_API3_Exception
154 * @throws \API_Exception
155 * @throws \CRM_Core_Exception
157 function civicrm_api3_dedupe_getduplicates($params) {
158 $options = _civicrm_api3_get_options_from_params($params);
159 $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));
160 return civicrm_api3_create_success($dupePairs);
164 * Adjust Metadata for getduplicates action..
166 * The metadata is used for setting defaults, documentation & validation.
168 * @param array $params
169 * Array of parameters determined by getfields.
171 function _civicrm_api3_dedupe_getduplicates_spec(&$params) {
172 $params['rule_group_id'] = [
173 'title' => ts('Rule Group ID'),
174 'api.required' => TRUE,
175 'type' => CRM_Utils_Type
::T_INT
,
177 $params['criteria'] = [
178 'title' => ts('Criteria'),
179 'description' => ts("Dedupe search criteria, as parsable by v3 Contact.get api, keyed by Contact. Eg.['Contact' => ['id' => ['BETWEEN' => [1, 2000]], 'group' => 34]"),
182 $spec['search_limit'] = [
183 'title' => ts('Number of contacts to look for matches for.'),
184 'type' => CRM_Utils_Type
::T_INT
,
185 'api.default' => (int) Civi
::settings()->get('dedupe_default_limit'),
187 $spec['is_force_new_search'] = [
188 'title' => ts('Force a new search, refreshing any cached search'),
189 'type' => CRM_Utils_Type
::T_BOOLEAN
,