-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/core#982 add dedupe.getstatistics api #14298
Merged
+200
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 5 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2019 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM is distributed in the hope that it will be useful, but | | ||
| WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | ||
| See the GNU Affero General Public License for more details. | | ||
| | | ||
| You should have received a copy of the GNU Affero General Public | | ||
| License and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* This api exposes CiviCRM dedupe functionality. | ||
* | ||
* @package CiviCRM_APIv3 | ||
*/ | ||
|
||
/** | ||
* Get rows for any cached attempted merges on the passed criteria. | ||
* | ||
* @param array $params | ||
* | ||
* @return array | ||
* @throws \API_Exception | ||
*/ | ||
function civicrm_api3_dedupe_get($params) { | ||
$sql = CRM_Utils_SQL_Select::fragment(); | ||
$sql->where(['merge_data_restriction' => "cachekey LIKE 'merge_%'"]); | ||
|
||
if (isset($params['cachekey'])) { | ||
// This is so bad. We actually have a camel case field name in the DB. Don't do that. | ||
// Intercept the pain here. | ||
$params['cacheKey'] = $params['cachekey']; | ||
unset($params['cachekey']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh no. We should fix this!!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's bad isn't it! |
||
} | ||
|
||
$options = _civicrm_api3_get_options_from_params($params, TRUE, 'PrevNextCache', 'get'); | ||
$result = _civicrm_api3_basic_get('CRM_Core_BAO_PrevNextCache', $params, FALSE, 'PrevNextCache', $sql); | ||
|
||
if ($options['is_count']) { | ||
return civicrm_api3_create_success($result, $params, 'PrevNextCache', 'get'); | ||
} | ||
foreach ($result as $index => $values) { | ||
if (isset($values['data']) && !empty($values['data'])) { | ||
$result[$index]['data'] = unserialize($values['data']); | ||
} | ||
if (isset($values['cacheKey'])) { | ||
$result[$index]['cachekey'] = $result[$index]['cacheKey']; | ||
unset($result[$index]['cacheKey']); | ||
} | ||
} | ||
return civicrm_api3_create_success($result, $params, 'PrevNextCache'); | ||
} | ||
|
||
/** | ||
* Get rows for getting dedupe cache records. | ||
* | ||
* @param array $params | ||
*/ | ||
function _civicrm_api3_dedupe_get_spec(&$params) { | ||
$params = CRM_Core_DAO_PrevNextCache::fields(); | ||
$params['id']['api.aliases'] = ['dedupe_id']; | ||
} | ||
|
||
/** | ||
* Delete rows for any cached attempted merges on the passed criteria. | ||
* | ||
* @param array $params | ||
* | ||
* @return array | ||
* | ||
* @throws \API_Exception | ||
* @throws \Civi\API\Exception\UnauthorizedException | ||
*/ | ||
function civicrm_api3_dedupe_delete($params) { | ||
return _civicrm_api3_basic_delete('CRM_Core_BAO_PrevNextCache', $params); | ||
} | ||
|
||
/** | ||
* Get the statistics for any cached attempted merges on the passed criteria. | ||
* | ||
* @param array $params | ||
* | ||
* @return array | ||
* @throws \API_Exception | ||
* @throws \Civi\API\Exception\UnauthorizedException | ||
*/ | ||
function civicrm_api3_dedupe_create($params) { | ||
return _civicrm_api3_basic_create('CRM_Core_BAO_PrevNextCache', $params, 'PrevNextCache'); | ||
} | ||
|
||
/** | ||
* Get the statistics for any cached attempted merges on the passed criteria. | ||
* | ||
* @param array $params | ||
* | ||
* @return array | ||
* @throws \CiviCRM_API3_Exception | ||
*/ | ||
function civicrm_api3_dedupe_getstatistics($params) { | ||
$stats = CRM_Dedupe_Merger::getMergeStats(CRM_Dedupe_Merger::getMergeCacheKeyString( | ||
$params['rule_group_id'], | ||
CRM_Utils_Array::value('group_id', $params), | ||
CRM_Utils_Array::value('criteria', $params, []), | ||
CRM_Utils_Array::value('check_permissions', $params, []) | ||
)); | ||
return civicrm_api3_create_success($stats); | ||
} | ||
|
||
/** | ||
* Adjust Metadata for Create action. | ||
* | ||
* The metadata is used for setting defaults, documentation & validation. | ||
* | ||
* @param array $params | ||
* Array of parameters determined by getfields. | ||
*/ | ||
function _civicrm_api3_dedupe_getstatistics_spec(&$params) { | ||
$params['rule_group_id'] = [ | ||
'title' => ts('Rule Group ID'), | ||
'api.required' => TRUE, | ||
'type' => CRM_Utils_Type::T_INT, | ||
]; | ||
$params['group_id'] = [ | ||
'title' => ts('Group ID'), | ||
'api.required' => FALSE, | ||
'type' => CRM_Utils_Type::T_INT, | ||
]; | ||
$params['criteria'] = [ | ||
'title' => ts('Criteria'), | ||
'description' => ts('Dedupe search criteria, as parsable by v3 Contact.get api'), | ||
]; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was hit by tests so has cover