projects
/
civicrm-core.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-03-02-21-30-06
[civicrm-core.git]
/
CRM
/
Dedupe
/
Merger.php
diff --git
a/CRM/Dedupe/Merger.php
b/CRM/Dedupe/Merger.php
index c698a3254ee5b8b8f6c4353cc0b350c531621aba..5bb0785828a00e2e8c81227c2a2d5e4a465e8eeb 100644
(file)
--- a/
CRM/Dedupe/Merger.php
+++ b/
CRM/Dedupe/Merger.php
@@
-23,7
+23,7
@@
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+
*/
/**
*
/**
*
@@
-34,10
+34,10
@@
*/
class CRM_Dedupe_Merger {
*/
class CRM_Dedupe_Merger {
- // FIXME: consider creating a common structure with cidRefs() and eidRefs()
- // FIXME: the sub-pages references by the URLs should
- // be loaded dynamically on the merge form instead
/**
/**
+ * FIXME: consider creating a common structure with cidRefs() and eidRefs()
+ * FIXME: the sub-pages references by the URLs should
+ * be loaded dynamically on the merge form instead
* @return array
*/
public static function relTables() {
* @return array
*/
public static function relTables() {
@@
-156,7
+156,7
@@
class CRM_Dedupe_Merger {
}
/**
}
/**
- * Returns the related tables groups for which a contact has any info entered
+ * Returns the related tables groups for which a contact has any info entered
.
*/
public static function getActiveRelTables($cid) {
$cid = (int) $cid;
*/
public static function getActiveRelTables($cid) {
$cid = (int) $cid;
@@
-243,12
+243,12
@@
WHERE
}
/**
}
/**
- * Return tables using locations
+ * Return tables using locations
.
*/
public static function locTables() {
static $locTables;
if (!$locTables) {
*/
public static function locTables() {
static $locTables;
if (!$locTables) {
- $locTables = array(
'civicrm_email', 'civicrm_address', 'civicrm_phone'
);
+ $locTables = array(
'civicrm_email', 'civicrm_address', 'civicrm_phone'
);
// Allow hook_civicrm_merge() to adjust $locTables
CRM_Utils_Hook::merge('locTables', $locTables);
// Allow hook_civicrm_merge() to adjust $locTables
CRM_Utils_Hook::merge('locTables', $locTables);
@@
-415,7
+415,6
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
* Based on the provided two contact_ids and a set of tables, move the
* belongings of the other contact to the main one.
*
* Based on the provided two contact_ids and a set of tables, move the
* belongings of the other contact to the main one.
*
- * @static
*/
public static function moveContactBelongings($mainId, $otherId, $tables = FALSE, $tableOperations = array()) {
$cidRefs = self::cidRefs();
*/
public static function moveContactBelongings($mainId, $otherId, $tables = FALSE, $tableOperations = array()) {
$cidRefs = self::cidRefs();
@@
-524,7
+523,6
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
* Contact details.
*
* @return array
* Contact details.
*
* @return array
- * @static
*/
public static function findDifferences($main, $other) {
$result = array(
*/
public static function findDifferences($main, $other) {
$result = array(
@@
-565,12
+563,11
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
* Helps decide how to behave when there are conflicts.
* A 'safe' value skips the merge if there are any un-resolved conflicts.
* Does a force merge otherwise.
* Helps decide how to behave when there are conflicts.
* A 'safe' value skips the merge if there are any un-resolved conflicts.
* Does a force merge otherwise.
- * @param bool $autoFlip
Wether
to let api decide which contact to retain and which to delete.
+ * @param bool $autoFlip to let api decide which contact to retain and which to delete.
* Wether to let api decide which contact to retain and which to delete.
* @param bool $redirectForPerformance
*
* @return array|bool
* Wether to let api decide which contact to retain and which to delete.
* @param bool $redirectForPerformance
*
* @return array|bool
- * @static
*/
public static function batchMerge($rgid, $gid = NULL, $mode = 'safe', $autoFlip = TRUE, $redirectForPerformance = FALSE) {
$contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
*/
public static function batchMerge($rgid, $gid = NULL, $mode = 'safe', $autoFlip = TRUE, $redirectForPerformance = FALSE) {
$contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
@@
-611,17
+608,16
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
* Helps decide how to behave when there are conflicts.
* A 'safe' value skips the merge if there are any un-resolved conflicts.
* Does a force merge otherwise (aggressive mode).
* Helps decide how to behave when there are conflicts.
* A 'safe' value skips the merge if there are any un-resolved conflicts.
* Does a force merge otherwise (aggressive mode).
- * @param bool $autoFlip
Wether
to let api decide which contact to retain and which to delete.
+ * @param bool $autoFlip to let api decide which contact to retain and which to delete.
* Wether to let api decide which contact to retain and which to delete.
*
*
* @param bool $redirectForPerformance
*
* @return array|bool
* Wether to let api decide which contact to retain and which to delete.
*
*
* @param bool $redirectForPerformance
*
* @return array|bool
- * @static
*/
public static function merge($dupePairs = array(), $cacheParams = array(), $mode = 'safe',
*/
public static function merge($dupePairs = array(), $cacheParams = array(), $mode = 'safe',
- $autoFlip = TRUE, $redirectForPerformance = FALSE
+
$autoFlip = TRUE, $redirectForPerformance = FALSE
) {
$cacheKeyString = CRM_Utils_Array::value('cache_key_string', $cacheParams);
$resultStats = array('merged' => array(), 'skipped' => array());
) {
$cacheKeyString = CRM_Utils_Array::value('cache_key_string', $cacheParams);
$resultStats = array('merged' => array(), 'skipped' => array());
@@
-649,7
+645,7
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
// Generate var $migrationInfo. The variable structure is exactly same as
// $formValues submitted during a UI merge for a pair of contacts.
// Generate var $migrationInfo. The variable structure is exactly same as
// $formValues submitted during a UI merge for a pair of contacts.
- $rowsElementsAndInfo =
&
CRM_Dedupe_Merger::getRowsElementsAndInfo($mainId, $otherId);
+ $rowsElementsAndInfo = CRM_Dedupe_Merger::getRowsElementsAndInfo($mainId, $otherId);
$migrationInfo = &$rowsElementsAndInfo['migration_info'];
$migrationInfo = &$rowsElementsAndInfo['migration_info'];
@@
-662,10
+658,10
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
// go ahead with merge if there is no conflict
if (!CRM_Dedupe_Merger::skipMerge($mainId, $otherId, $migrationInfo, $mode)) {
CRM_Dedupe_Merger::moveAllBelongings($mainId, $otherId, $migrationInfo);
// go ahead with merge if there is no conflict
if (!CRM_Dedupe_Merger::skipMerge($mainId, $otherId, $migrationInfo, $mode)) {
CRM_Dedupe_Merger::moveAllBelongings($mainId, $otherId, $migrationInfo);
- $resultStats['merged'][] = array('main_d' => $mainId, 'other_id' => $otherId);
+ $resultStats['merged'][] = array('main_
i
d' => $mainId, 'other_id' => $otherId);
}
else {
}
else {
- $resultStats['skipped'][] = array('main_d' => $mainId, 'other_id' => $otherId);
+ $resultStats['skipped'][] = array('main_
i
d' => $mainId, 'other_id' => $otherId);
}
// delete entry from PrevNextCache table so we don't consider the pair next time
}
// delete entry from PrevNextCache table so we don't consider the pair next time
@@
-708,7
+704,6
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
* Does a force merge otherwise (aggressive mode).
*
* @return bool
* Does a force merge otherwise (aggressive mode).
*
* @return bool
- * @static
*/
public static function skipMerge($mainId, $otherId, &$migrationInfo, $mode = 'safe') {
$conflicts = array();
*/
public static function skipMerge($mainId, $otherId, &$migrationInfo, $mode = 'safe') {
$conflicts = array();
@@
-726,7
+721,8
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
}
elseif ((in_array(substr($key, 5), CRM_Dedupe_Merger::getContactFields()) or
substr($key, 0, 12) == 'move_custom_'
}
elseif ((in_array(substr($key, 5), CRM_Dedupe_Merger::getContactFields()) or
substr($key, 0, 12) == 'move_custom_'
- ) and $val != NULL) {
+ ) and $val != NULL
+ ) {
// Rule: if both main-contact has other-contact, let $mode decide if to merge a
// particular field or not
if (!empty($migrationInfo['rows'][$key]['main'])) {
// Rule: if both main-contact has other-contact, let $mode decide if to merge a
// particular field or not
if (!empty($migrationInfo['rows'][$key]['main'])) {
@@
-750,14
+746,13
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
// Rule: resolve address conflict if any -
if ($fieldName == 'address') {
$mainNewLocTypeId = $migrationInfo['location'][$fieldName][$fieldCount]['locTypeId'];
// Rule: resolve address conflict if any -
if ($fieldName == 'address') {
$mainNewLocTypeId = $migrationInfo['location'][$fieldName][$fieldCount]['locTypeId'];
- if (!empty($migrationInfo['main_loc_
address
']) &&
- array_key_exists("main_
{$mainNewLocTypeId}", $migrationInfo['main_loc_address
'])) {
+ if (!empty($migrationInfo['main_loc_
block
']) &&
+ array_key_exists("main_
address{$mainNewLocTypeId}", $migrationInfo['main_loc_block
'])) {
// main loc already has some address for the loc-type. Its a overwrite situation.
// main loc already has some address for the loc-type. Its a overwrite situation.
-
// look for next available loc-type
$newTypeId = NULL;
foreach ($allLocationTypes as $typeId => $typeLabel) {
// look for next available loc-type
$newTypeId = NULL;
foreach ($allLocationTypes as $typeId => $typeLabel) {
- if (!array_key_exists("main_
{$typeId}", $migrationInfo['main_loc_address
'])) {
+ if (!array_key_exists("main_
address{$typeId}", $migrationInfo['main_loc_block
'])) {
$newTypeId = $typeId;
}
}
$newTypeId = $typeId;
}
}
@@
-817,14
+812,17
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
* Duplicate contact which would be deleted after merge operation.
*
* @return array|bool|int
* Duplicate contact which would be deleted after merge operation.
*
* @return array|bool|int
- * @static
*/
public static function getRowsElementsAndInfo($mainId, $otherId) {
$qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
// Fetch contacts
foreach (array('main' => $mainId, 'other' => $otherId) as $moniker => $cid) {
*/
public static function getRowsElementsAndInfo($mainId, $otherId) {
$qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
// Fetch contacts
foreach (array('main' => $mainId, 'other' => $otherId) as $moniker => $cid) {
- $params = array('contact_id' => $cid, 'version' => 3, 'return' => array_merge(array('display_name'), self::getContactFields()));
+ $params = array(
+ 'contact_id' => $cid,
+ 'version' => 3,
+ 'return' => array_merge(array('display_name'), self::getContactFields()),
+ );
$result = civicrm_api('contact', 'get', $params);
if (empty($result['values'][$cid]['contact_type'])) {
$result = civicrm_api('contact', 'get', $params);
if (empty($result['values'][$cid]['contact_type'])) {
@@
-855,8
+853,7
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
$specialValues[$moniker]['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . $prefCommList . CRM_Core_DAO::VALUE_SEPARATOR;
}
$names = array(
$specialValues[$moniker]['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . $prefCommList . CRM_Core_DAO::VALUE_SEPARATOR;
}
$names = array(
- 'preferred_communication_method' =>
- array(
+ 'preferred_communication_method' => array(
'newName' => 'preferred_communication_method_display',
'groupName' => 'preferred_communication_method',
),
'newName' => 'preferred_communication_method_display',
'groupName' => 'preferred_communication_method',
),
@@
-1039,7
+1036,7
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
array(
1 => $block,
2 => $count,
array(
1 => $block,
2 => $count,
- 3 => $allLocationTypes[$locTypeId]
+ 3 => $allLocationTypes[$locTypeId]
,
)
);
)
);
@@
-1058,8
+1055,11
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
$js = array('onChange' => "mergeBlock('$name', this, $count );");
}
$elements[] = array(
$js = array('onChange' => "mergeBlock('$name', this, $count );");
}
$elements[] = array(
- 'select', "location[{$name}][$count][locTypeId]", NULL,
- $defaultLocType + $locTypeValues, $js,
+ 'select',
+ "location[{$name}][$count][locTypeId]",
+ NULL,
+ $defaultLocType + $locTypeValues,
+ $js,
);
// keep location-type-id same as that of other-contact
$migrationInfo['location'][$name][$count]['locTypeId'] = $locTypeId;
);
// keep location-type-id same as that of other-contact
$migrationInfo['location'][$name][$count]['locTypeId'] = $locTypeId;
@@
-1214,7
+1214,6
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
* @param $migrationInfo
*
* @return bool
* @param $migrationInfo
*
* @return bool
- * @static
*/
public static function moveAllBelongings($mainId, $otherId, $migrationInfo) {
if (empty($migrationInfo)) {
*/
public static function moveAllBelongings($mainId, $otherId, $migrationInfo) {
if (empty($migrationInfo)) {
@@
-1229,7
+1228,7
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
$value = '0';
}
if ((in_array(substr($key, 5), CRM_Dedupe_Merger::getContactFields()) ||
$value = '0';
}
if ((in_array(substr($key, 5), CRM_Dedupe_Merger::getContactFields()) ||
- substr($key, 0, 12) == 'move_custom_') &&
+
substr($key, 0, 12) == 'move_custom_') &&
$value != NULL
) {
$submitted[substr($key, 5)] = $value;
$value != NULL
) {
$submitted[substr($key, 5)] = $value;
@@
-1426,10
+1425,13
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
//keep state and country as array format.
//for checkbox and m-select format w/ VALUE_SEPARATOR
if (in_array($htmlType, array(
//keep state and country as array format.
//for checkbox and m-select format w/ VALUE_SEPARATOR
if (in_array($htmlType, array(
- 'CheckBox', 'Multi-Select', 'AdvMulti-Select'))) {
+ 'CheckBox',
+ 'Multi-Select',
+ 'AdvMulti-Select',
+ ))) {
$submitted[$key] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
$submitted[$key] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
- $mergeValue
- ) . CRM_Core_DAO::VALUE_SEPARATOR;
+
$mergeValue
+
) . CRM_Core_DAO::VALUE_SEPARATOR;
}
else {
$submitted[$key] = $mergeValue;
}
else {
$submitted[$key] = $mergeValue;
@@
-1437,7
+1439,9
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
}
}
elseif (in_array($htmlType, array(
}
}
elseif (in_array($htmlType, array(
- 'Multi-Select Country', 'Multi-Select State/Province'))) {
+ 'Multi-Select Country',
+ 'Multi-Select State/Province',
+ ))) {
//we require submitted values should be in array format
if ($value) {
$mergeValueArray = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
//we require submitted values should be in array format
if ($value) {
$mergeValueArray = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
@@
-1486,7
+1490,7
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
// move the other contact's file to main contact
//NYSS need to INSERT or UPDATE depending on whether main contact has an existing record
// move the other contact's file to main contact
//NYSS need to INSERT or UPDATE depending on whether main contact has an existing record
- if (
CRM_Core_DAO::singleValueQuery("SELECT id FROM {$tableName} WHERE entity_id = {$mainId}")
) {
+ if (
CRM_Core_DAO::singleValueQuery("SELECT id FROM {$tableName} WHERE entity_id = {$mainId}")
) {
$sql = "UPDATE {$tableName} SET {$columnName} = {$fileIds[$otherId]} WHERE entity_id = {$mainId}";
}
else {
$sql = "UPDATE {$tableName} SET {$columnName} = {$fileIds[$otherId]} WHERE entity_id = {$mainId}";
}
else {
@@
-1494,10
+1498,11
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
}
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
}
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
- if (
CRM_Core_DAO::singleValueQuery("
+ if (CRM_Core_DAO::singleValueQuery("
SELECT id
FROM civicrm_entity_file
SELECT id
FROM civicrm_entity_file
- WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$otherId]}") ) {
+ WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$otherId]}")
+ ) {
$sql = "
UPDATE civicrm_entity_file
SET entity_id = {$mainId}
$sql = "
UPDATE civicrm_entity_file
SET entity_id = {$mainId}
@@
-1554,7
+1559,7
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
// CRM-15681 merge sub_types
if ($other_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['other_details'])) {
if ($main_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['main_details'])) {
// CRM-15681 merge sub_types
if ($other_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['other_details'])) {
if ($main_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['main_details'])) {
- $submitted['contact_sub_type'] = array_unique(
array_merge($main_sub_types, $other_sub_types));
+ $submitted['contact_sub_type'] = array_unique(array_merge($main_sub_types, $other_sub_types));
}
else {
$submitted['contact_sub_type'] = $other_sub_types;
}
else {
$submitted['contact_sub_type'] = $other_sub_types;
@@
-1577,10
+1582,10
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
}
//CRM-14312 include prefix/suffix from mainId if not overridden for proper construction of display/sort name
}
//CRM-14312 include prefix/suffix from mainId if not overridden for proper construction of display/sort name
- if (
!isset($submitted['prefix_id']) && !empty($migrationInfo['main_details']['prefix_id'])
) {
+ if (
!isset($submitted['prefix_id']) && !empty($migrationInfo['main_details']['prefix_id'])
) {
$submitted['prefix_id'] = $migrationInfo['main_details']['prefix_id'];
}
$submitted['prefix_id'] = $migrationInfo['main_details']['prefix_id'];
}
- if (
!isset($submitted['suffix_id']) && !empty($migrationInfo['main_details']['suffix_id'])
) {
+ if (
!isset($submitted['suffix_id']) && !empty($migrationInfo['main_details']['suffix_id'])
) {
$submitted['suffix_id'] = $migrationInfo['main_details']['suffix_id'];
}
$submitted['suffix_id'] = $migrationInfo['main_details']['suffix_id'];
}
@@
-1594,12
+1599,23
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
}
/**
}
/**
- * @return array of field names which will be compared, so everything except ID.
+ * @return array
+ * Array of field names which will be compared, so everything except ID.
*/
public static function getContactFields() {
$contactFields = CRM_Contact_DAO_Contact::fields();
*/
public static function getContactFields() {
$contactFields = CRM_Contact_DAO_Contact::fields();
- $invalidFields = array('api_key', 'contact_is_deleted', 'created_date', 'display_name', 'hash', 'id', 'modified_date',
- 'primary_contact_id', 'sort_name', 'user_unique_id');
+ $invalidFields = array(
+ 'api_key',
+ 'contact_is_deleted',
+ 'created_date',
+ 'display_name',
+ 'hash',
+ 'id',
+ 'modified_date',
+ 'primary_contact_id',
+ 'sort_name',
+ 'user_unique_id',
+ );
foreach ($contactFields as $field => $value) {
if (in_array($field, $invalidFields)) {
unset($contactFields[$field]);
foreach ($contactFields as $field => $value) {
if (in_array($field, $invalidFields)) {
unset($contactFields[$field]);
@@
-1610,10
+1626,10
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
/**
* Added for CRM-12695
/**
* Added for CRM-12695
- * Based on the contactI
d
provided
+ * Based on the contactI
D
provided
* add/update membership(s) to related contacts
*
* add/update membership(s) to related contacts
*
- * @param
contactId
+ * @param
int $contactID
*/
public static function addMembershipToRealtedContacts($contactID) {
$dao = new CRM_Member_DAO_Membership();
*/
public static function addMembershipToRealtedContacts($contactID) {
$dao = new CRM_Member_DAO_Membership();
@@
-1633,11
+1649,12
@@
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m
'start_date' => CRM_Utils_Date::isoToMysql($dao->start_date),
'end_date' => CRM_Utils_Date::isoToMysql($dao->end_date),
'source' => $dao->source,
'start_date' => CRM_Utils_Date::isoToMysql($dao->start_date),
'end_date' => CRM_Utils_Date::isoToMysql($dao->end_date),
'source' => $dao->source,
- 'status_id' => $dao->status_id
+ 'status_id' => $dao->status_id
,
);
// create/update membership(s) for related contact(s)
CRM_Member_BAO_Membership::createRelatedMemberships($membershipParams, $dao);
} // end of if relationshipTypeId
}
}
);
// create/update membership(s) for related contact(s)
CRM_Member_BAO_Membership::createRelatedMemberships($membershipParams, $dao);
} // end of if relationshipTypeId
}
}
+
}
}