Skip to content
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

enforce required fields on Contact.duplicatecheck #22741

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion api/v3/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1602,10 +1602,16 @@ function _civicrm_api3_contact_getlist_output($result, $request) {
* @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_contact_duplicatecheck($params) {
if (!isset($params['match']) || !is_array($params['match'])) {
throw new \CiviCRM_API3_Exception('Duplicate check must include criteria to check against (missing or invalid $params[\'match\']).');
}
if (!isset($params['match']['contact_type']) || !is_string($params['match']['contact_type'])) {
throw new \CiviCRM_API3_Exception('Duplicate check must include a contact type. (missing or invalid $params[\'match\'][\'contact_type\'])');
}
$dupes = CRM_Contact_BAO_Contact::getDuplicateContacts(
$params['match'],
$params['match']['contact_type'],
$params['rule_type'],
$params['rule_type'] ?? '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would $params['rule_type'] ?: 'Unsupervised' be more correct?

Also - there IS a default for the field

  $params['rule_type'] = [
    'title' => 'Dedupe Rule Type',
    'description' => 'If no rule id specified, pass "Unsupervised" or "Supervised"',
    'type' => CRM_Utils_Type::T_STRING,
    'api.default' => 'Unsupervised',
  ];

So why isn't that kicking in?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it only seems to kick in when the parameter isn't in the parameters passed to the API call and it seems that at least webform civicrm may be deliberately passing in NULL for this API call https://github.com/civicrm/civicrm-core/blame/master/api/v3/Contact.php#L1608

CRM_Utils_Array::value('exclude', $params, []),
CRM_Utils_Array::value('check_permissions', $params),
CRM_Utils_Array::value('dedupe_rule_id', $params)
Expand Down