Skip to content

Deduplication & Merging

When leads arrive from web forms, email imports, portal signups, and manual entry, duplicate records are inevitable. Contacts prevents most duplicates at write time through ContactDeduplicator and resolves remaining clusters atomically via ContactMergeService.

Open Setup -> Contacts -> Duplicates (requires contacts-admin) to review candidate clusters grouped by confidence level, choose a primary record, and merge duplicates cleanly.

The Duplicates workspace groups exact email/phone matches (100% Match) and fuzzy name-plus-organization clusters (75% Match) for review.
  • Live Upsert Strategy (dedupe_strategy):
    • email_then_phone (default): Matches normalized lowercase primary_email first, then falls back to E.164 phone_e164.
    • email_only: Matches strictly on primary_email.
  • Cluster Detection (findDuplicateGroups()):
    • Primary Exact: Identical normalized primary_email or phone_e164 (100% Match).
    • Secondary Channel (includeChannels: true): Matches overlapping email or phone entries inside contacts-channel rows.
    • Fuzzy Name + Organization/Domain (includeFuzzy: true): Opt-in fuzzy_name_org clusters (75% Match) shown strictly for manual review (never auto-merged by CLI).
  • Organization Matching: findOrganizationByTaxId(), findOrganizationByDomain() (automatically ignores free consumer email domains via isFreeEmailDomain()), and findByExternalRef().

When you merge a duplicate contact into a primary contact (./merge/ or $contacts->mergeContacts()):

  1. Fires Contacts::beforeMerge('contact', $primary, $duplicate, $strategy).
  2. Merges missing scalar fields (respecting allowlisted prefer_duplicate_fields overrides).
  3. Combines and deduplicates contacts-channel, contacts-address, contacts-membership, contacts-consent, roles, tags, domain_meta, and external_refs.
  4. Reassigns all contacts-notes referencing $duplicate->id to $primary->id.
  5. Repoints embedded @fieldset:contacts-profile.linked_contact_id (page_id>0) references on ProcessWire Pages and Users.
  6. Deletes the duplicate contact inside Contacts::runInTransaction().
  7. Fires Contacts::afterMerge('contact', $primary, $duplicateId, $stats) post-commit so all 'contactsParticipant' => true modules repoint their stored foreign UUIDs.

mergeOrganizations() performs the equivalent atomic merge for organizations, reassigning child organizations (reassignedChildren), member contacts (reassignedMembers), notes (reassignedNotes), and embedded @fieldset:contacts-organization / @fieldset:contacts-memberships references.

<?php
declare(strict_types=1);
namespace ProcessWire;
$contacts = Contacts::requireInstance($this);
$stats = $contacts->mergeContacts($primaryContact, $duplicateContact, [
'prefer_duplicate_fields' => ['phone_e164', 'job_title'],
]);
Terminal window
# Preview exact + fuzzy duplicate clusters without mutating records
php vendor/bin/wire contacts:dedupe --scope=contacts --fuzzy --dry-run --json
# Automatically merge exact primary clusters into the earliest primary record
php vendor/bin/wire contacts:dedupe --scope=contacts --auto-merge --force --json

Next steps