Documentation

CRM_Dedupe_MergeHandler
in package

This class exists primarily for the purposes of supporting code clean up in the Merger class.

It is expected to be fast-moving and calling it outside the refactoring work is not advised.

Tags
copyright

CiviCRM LLC https://civicrm.org/licensing

Table of Contents

Properties

$migrationInfo  : array<string|int, mixed>
Migration info array.
$toKeepID  : int
ID of contact to be kept.
$toRemoveID  : int
ID of contact to be merged and deleted.

Methods

__construct()  : mixed
CRM_Dedupe_MergeHandler constructor.
contactToKeepHasLocationBlocksForEntity()  : bool
Does the contact to keep have location blocks for the given entity.
copyDataToNewBlockDAO()  : CRM_Core_DAO_Address|CRM_Core_DAO_Email|CRM_Core_DAO_IM|CRM_Core_DAO_Phone|CRM_Core_DAO_Website
Copy the data to be moved to a new DAO object.
getBlocksToUpdateForDeletedContact()  : array<string|int, mixed>
Get blocks, if any, to update for the deleted contact.
getDAOForLocationEntity()  : CRM_Core_DAO_Address|CRM_Core_DAO_Email|CRM_Core_DAO_IM|CRM_Core_DAO_Phone|CRM_Core_DAO_Website
Get the DAO object appropriate to the location entity.
getLocationBlocksForContactToKeep()  : array<string|int, mixed>
Get the location blocks for the contact to be kept.
getLocationBlocksForContactToRemove()  : array<string|int, mixed>
Get the location blocks for the contact to be deleted.
getLocationBlocksToMerge()  : array<string|int, mixed>
Get the location blocks designated to be moved during the merge.
getMigrationInfo()  : array<string|int, mixed>
getTablesDynamicallyRelatedToContactTable()  : array<string|int, mixed>
Get an array of tables that have a dynamic reference to the contact table.
getTablesRelatedToTheMergePair()  : mixed
Get an array of tables that relate to the contact entity and will need consideration in a merge.
getToKeepID()  : mixed
getToRemoveID()  : mixed
mergeLocations()  : void
Merge location.
setMigrationInfo()  : mixed
setToKeepID()  : mixed
setToRemoveID()  : mixed
getLocationBlocksToMoveForEntity()  : array<string|int, mixed>
Get the details of the blocks to be transferred over for the given entity.
getSelectedLocationType()  : int|null
Get the selected location type for the given location block.
getSelectedType()  : int|null
Get the selected type for the given location block.

Properties

$migrationInfo

Migration info array.

protected array<string|int, mixed> $migrationInfo = []

This is a nasty bunch of data used in mysterious ways. We want to work to make it more sensible but for now we store it.

$toKeepID

ID of contact to be kept.

protected int $toKeepID

$toRemoveID

ID of contact to be merged and deleted.

protected int $toRemoveID

Methods

__construct()

CRM_Dedupe_MergeHandler constructor.

public __construct(int $toKeepID, int $toRemoveID) : mixed
Parameters
$toKeepID : int

ID of contact to be kept.

$toRemoveID : int

ID of contact to be removed.

contactToKeepHasLocationBlocksForEntity()

Does the contact to keep have location blocks for the given entity.

public contactToKeepHasLocationBlocksForEntity(string $entity) : bool
Parameters
$entity : string
Return values
bool

copyDataToNewBlockDAO()

Copy the data to be moved to a new DAO object.

public copyDataToNewBlockDAO(int $otherBlockId, string $name, int $blkCount) : CRM_Core_DAO_Address|CRM_Core_DAO_Email|CRM_Core_DAO_IM|CRM_Core_DAO_Phone|CRM_Core_DAO_Website

This is intended as a refactoring step - not the long term function. Do not call from any function other than the one it is taken from (Merger::mergeLocations).

Parameters
$otherBlockId : int
$name : string
$blkCount : int
Tags
throws
CRM_Core_Exception
Return values
CRM_Core_DAO_Address|CRM_Core_DAO_Email|CRM_Core_DAO_IM|CRM_Core_DAO_Phone|CRM_Core_DAO_Website

getBlocksToUpdateForDeletedContact()

Get blocks, if any, to update for the deleted contact.

public getBlocksToUpdateForDeletedContact(string $entity) : array<string|int, mixed>

If the deleted contact no longer has a primary address but still has one or more blocks we want to ensure the remaining block is updated to have is_primary = 1 in case the contact is ever undeleted.

Parameters
$entity : string
Tags
throws
CRM_Core_Exception
Return values
array<string|int, mixed>

getDAOForLocationEntity()

Get the DAO object appropriate to the location entity.

public getDAOForLocationEntity(string $entity[, int|null $locationTypeID = NULL ][, int|null $typeID = NULL ]) : CRM_Core_DAO_Address|CRM_Core_DAO_Email|CRM_Core_DAO_IM|CRM_Core_DAO_Phone|CRM_Core_DAO_Website
Parameters
$entity : string
$locationTypeID : int|null = NULL
$typeID : int|null = NULL
Tags
throws
CRM_Core_Exception
Return values
CRM_Core_DAO_Address|CRM_Core_DAO_Email|CRM_Core_DAO_IM|CRM_Core_DAO_Phone|CRM_Core_DAO_Website

getLocationBlocksForContactToKeep()

Get the location blocks for the contact to be kept.

public getLocationBlocksForContactToKeep() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLocationBlocksForContactToRemove()

Get the location blocks for the contact to be deleted.

public getLocationBlocksForContactToRemove() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLocationBlocksToMerge()

Get the location blocks designated to be moved during the merge.

public getLocationBlocksToMerge() : array<string|int, mixed>

Note this is a refactoring step and future refactors should develop a more coherent array

Return values
array<string|int, mixed>

The format is ['address' => [0 => ['is_replace' => TRUE]], 'email' => [0...],[1....] where the entity is address, the internal indexing for the addresses on both contact is 1 and the intent to replace the existing address is TRUE.

getMigrationInfo()

public getMigrationInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTablesDynamicallyRelatedToContactTable()

Get an array of tables that have a dynamic reference to the contact table.

public getTablesDynamicallyRelatedToContactTable() : array<string|int, mixed>

This would be the case when the table uses entity_table + entity_id rather than an FK.

There are a number of tables that 'could' but don't have contact related data so we do a cached check for this, ensuring the query is only done once per batch run.

Return values
array<string|int, mixed>

getTablesRelatedToTheMergePair()

Get an array of tables that relate to the contact entity and will need consideration in a merge.

public getTablesRelatedToTheMergePair() : mixed

The list of potential tables is filtered by tables which have data for the relevant contacts.

mergeLocations()

Merge location.

public mergeLocations() : void

Based on the data in the $locationMigrationInfo merge the locations for 2 contacts.

The data is in the format received from the merge form (which is a fairly confusing format).

It is converted into an array of DAOs which is passed to the alterLocationMergeData hook before saving or deleting the DAOs. A new hook is added to allow these to be altered after they have been calculated and before saving because

  • the existing format & hook combo is so confusing it is hard for developers to change & inherently fragile
  • passing to a hook right before save means calculations only have to be done once
  • the existing pattern of passing dissimilar data to the same (merge) hook with a different 'type' is just ugly.

The use of the new hook is tested, including the fact it is called before contributions are merged, as this is likely to be significant data in merge hooks.

Tags
throws
CRM_Core_Exception

setMigrationInfo()

public setMigrationInfo(array<string|int, mixed> $migrationInfo) : mixed
Parameters
$migrationInfo : array<string|int, mixed>

setToKeepID()

public setToKeepID(mixed $toKeepID) : mixed
Parameters
$toKeepID : mixed

setToRemoveID()

public setToRemoveID(mixed $toRemoveID) : mixed
Parameters
$toRemoveID : mixed

getLocationBlocksToMoveForEntity()

Get the details of the blocks to be transferred over for the given entity.

protected getLocationBlocksToMoveForEntity(string $entity) : array<string|int, mixed>
Parameters
$entity : string
Return values
array<string|int, mixed>

getSelectedLocationType()

Get the selected location type for the given location block.

protected getSelectedLocationType(string $entity, int $blockIndex) : int|null

This will retrieve any user selection if they specified which location to move a block to.

Parameters
$entity : string
$blockIndex : int
Return values
int|null

getSelectedType()

Get the selected type for the given location block.

protected getSelectedType(string $entity, int $blockIndex) : int|null

This will retrieve any user selection if they specified which type to move a block to (e.g 'Mobile' for phone).

Parameters
$entity : string
$blockIndex : int
Return values
int|null

        
On this page

Search results