3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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'] = unserialize($values['data']);
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 CRM_Utils_Array
::value('check_permissions', $params, [])
112 return civicrm_api3_create_success($stats);
116 * Adjust Metadata for Create action.
118 * The metadata is used for setting defaults, documentation & validation.
120 * @param array $params
121 * Array of parameters determined by getfields.
123 function _civicrm_api3_dedupe_getstatistics_spec(&$params) {
124 $params['rule_group_id'] = [
125 'title' => ts('Rule Group ID'),
126 'api.required' => TRUE,
127 'type' => CRM_Utils_Type
::T_INT
,
129 $params['group_id'] = [
130 'title' => ts('Group ID'),
131 'api.required' => FALSE,
132 'type' => CRM_Utils_Type
::T_INT
,
134 $params['criteria'] = [
135 'title' => ts('Criteria'),
136 'description' => ts('Dedupe search criteria, as parsable by v3 Contact.get api'),