}
$select = $actualSelectElements = ['sort_name'];
- $where = '';
+
foreach ($list as $value) {
$suffix = substr($value, 0, 2) . substr($value, -1);
switch ($value) {
// add acl clause here
list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
-
+ $whereClauses = ['cc.is_deleted = 0'];
if ($aclWhere) {
- $where .= " AND $aclWhere ";
+ $whereClauses[] = $aclWhere;
}
$isPrependWildcard = \Civi::settings()->get('includeWildCardInName');
if (!empty($params['org'])) {
- $where .= " AND contact_type = \"Organization\"";
+ $whereClauses[] = 'contact_type = "Organization"';
// CRM-7157, hack: get current employer details when
// employee_id is present.
if (!empty($params['contact_sub_type'])) {
$contactSubType = CRM_Utils_Type::escape($params['contact_sub_type'], 'String');
- $where .= " AND cc.contact_sub_type = '{$contactSubType}'";
+ $whereClauses[] = "cc.contact_sub_type = '{$contactSubType}'";
}
if (!empty($params['contact_type'])) {
$contactType = CRM_Utils_Type::escape($params['contact_type'], 'String');
- $where .= " AND cc.contact_type LIKE '{$contactType}'";
+ $whereClauses[] = "cc.contact_type LIKE '{$contactType}'";
}
// Set default for current_employer or return contact with particular id
if (!empty($params['id'])) {
- $where .= " AND cc.id = " . (int) $params['id'];
+ $whereClauses[] = 'cc.id = ' . (int) $params['id'];
}
if (!empty($params['cid'])) {
- $where .= " AND cc.id <> " . (int) $params['cid'];
+ $whereClauses[] = 'cc.id <> ' . (int) $params['cid'];
}
// Contact's based of relationhip type
if ($config->includeNickNameInName) {
$includeNickName = " OR nick_name LIKE '$strSearch'";
}
-
+ $where = ' AND ' . implode(' AND ', $whereClauses);
if (isset($customOptionsWhere)) {
$customOptionsWhere = $customOptionsWhere ?: [0];
- $whereClause = " WHERE (" . implode(' OR ', $customOptionsWhere) . ") $where";
+ $whereClause = ' WHERE (' . implode(' OR ', $customOptionsWhere) . ") $where";
}
elseif (!empty($params['field_name']) && !empty($params['table_name']) && $params['field_name'] != 'sort_name') {
$whereClause = " WHERE ( $table_name.$field_name LIKE '$strSearch') {$where}";
foreach ((array) $params['mode'] as $mode) {
$result[$mode] = CRM_Dedupe_Merger::getConflicts(
$migrationInfo,
- $params['to_remove_id'], $params['to_keep_id'],
+ (int) $params['to_remove_id'], (int) $params['to_keep_id'],
$mode
);
}
* @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'] ?? '',
CRM_Utils_Array::value('exclude', $params, []),
CRM_Utils_Array::value('check_permissions', $params),
CRM_Utils_Array::value('dedupe_rule_id', $params)