* 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
+ * @throws \CiviCRM_API3_Exception
*/
public static function relTables() {
3 => '$ufid',
]);
}
- elseif ($config->userFramework == 'Joomla') {
+ elseif ($config->userFramework === 'Joomla') {
$userRecordUrl = $config->userSystem->getVersion() > 1.5 ? $config->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . '%ufid' : $config->userFrameworkBaseURL . "index2.php?option=com_users&view=user&task=edit&id[]=" . '%ufid';
$title = ts('%1 User: %2; user id: %3', [
1 => $config->userFramework,
* @param int $cid
*
* @return array
+ * @throws \CiviCRM_API3_Exception
*/
public static function getActiveRelTables($cid) {
$cid = (int) $cid;
]);
foreach ($result['values'] as $custom) {
$data['cidRefs'][$custom['table_name']] = ['entity_id'];
- $urlSuffix = $custom['style'] == 'Tab' ? '&selectedChild=custom_' . $custom['id'] : '';
+ $urlSuffix = $custom['style'] === 'Tab' ? '&selectedChild=custom_' . $custom['id'] : '';
$data['relTables']['rel_table_custom_' . $custom['id']] = [
'title' => $custom['title'],
'tables' => [$custom['table_name']],
if (array_key_exists($tableName, $tableOperations) && $tableOperations[$tableName]['add']) {
break;
}
- if ($mode == 'add') {
+ if ($mode === 'add') {
$sqls[] = "
DELETE membership1.* FROM civicrm_membership membership1
INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = membership2.membership_type_id
AND membership1.contact_id = {$mainId}
AND membership2.contact_id = {$otherId} ";
}
- if ($mode == 'payment') {
+ if ($mode === 'payment') {
$sqls[] = "
DELETE contribution.* FROM civicrm_contribution contribution
INNER JOIN civicrm_membership_payment payment ON payment.contribution_id = contribution.id
$preOperationSqls = self::operationSql($mainId, $otherId, $table, $tableOperations);
$sqls = array_merge($sqls, $preOperationSqls);
- $sqls[] = "UPDATE IGNORE $table SET $field = $mainId WHERE $field = $otherId";
- $sqls[] = "DELETE FROM $table WHERE $field = $otherId";
+ $sqls[] = "UPDATE $table SET $field = $mainId WHERE $field = $otherId";
}
}
/**
* Given a contact ID, will check if a record exists in given table.
*
- * @param $contactID
- * @param $table
- * @param $idField
+ * @param int $contactID
+ * @param string $table
+ * @param string $idField
* Field where the contact's ID is stored in the table
*
* @return bool
* Contact details.
*
* @return array
+ *
+ * @throws \CRM_Core_Exception
*/
public static function retrieveFields($main, $other) {
$result = [
// explicitly set to NULL if not 1 or 0 as part of grandfathering out the mystical '2' value.
$isSelected = NULL;
}
- $dupePairs = self::getDuplicatePairs($rgid, $gid, $reloadCacheIfEmpty, $batchLimit, $isSelected, ($mode == 'aggressive'), $criteria, $checkPermissions, $searchLimit);
+ $dupePairs = self::getDuplicatePairs($rgid, $gid, $reloadCacheIfEmpty, $batchLimit, $isSelected, ($mode === 'aggressive'), $criteria, $checkPermissions, $searchLimit);
$cacheParams = [
'cache_key_string' => self::getMergeCacheKeyString($rgid, $gid, $criteria, $checkPermissions, $searchLimit),
* The join string to join prevnext cache on the dedupe table.
*/
public static function getJoinOnDedupeTable() {
- return "
+ return '
LEFT JOIN civicrm_dedupe_exception de
ON (
pn.entity_id1 = de.contact_id1
AND pn.entity_id2 = de.contact_id2 )
- ";
+ ';
}
/**
* @return string
*/
protected static function getWhereString($isSelected) {
- $where = "de.id IS NULL";
+ $where = 'de.id IS NULL';
if ($isSelected === 0 || $isSelected === 1) {
$where .= " AND pn.is_selected = {$isSelected}";
}
*
* @param string $cacheKeyString
* @param array $result
+ *
+ * @throws \CiviCRM_API3_Exception
*/
public static function updateMergeStats($cacheKeyString, $result = []) {
// gather latest stats
* @return array
*/
public static function getLocationBlockInfo() {
- $locationBlocks = [
+ return [
'address' => [
'label' => 'Address',
'displayField' => 'display',
'hasType' => 'website_type_id',
],
];
- return $locationBlocks;
}
/**
$rows = $elements = $relTableElements = $migrationInfo = [];
foreach ($compareFields['contact'] as $field) {
- if ($field == 'contact_sub_type') {
+ if ($field === 'contact_sub_type') {
// CRM-15681 don't display sub-types in UI
continue;
}
$relTables[$name]['main_url'] = str_replace('%ufid', CRM_Core_BAO_UFMatch::getUFId($otherId), $relTables[$name]['url']);
$relTables[$name]['other_url'] = str_replace('%ufid', CRM_Core_BAO_UFMatch::getUFId($otherId), $relTables[$name]['url']);
}
- if ($name == 'rel_table_memberships') {
+ if ($name === 'rel_table_memberships') {
//Enable 'add new' checkbox if main contact does not contain any membership similar to duplicate contact.
$attributes = ['checked' => 'checked'];
$otherContactMemberships = CRM_Member_BAO_Membership::getAllContactMembership($otherId);
self::swapOutFieldsAffectedByQFZeroBug($migrationInfo);
foreach ($migrationInfo as $key => $value) {
- if (substr($key, 0, 12) == 'move_custom_' && $value != NULL) {
+ if (substr($key, 0, 12) === 'move_custom_' && $value != NULL) {
$submitted[substr($key, 5)] = $value;
$submittedCustomFields[] = substr($key, 12);
}
elseif (in_array(substr($key, 5), CRM_Dedupe_Merger::getContactFields()) && $value != NULL) {
$submitted[substr($key, 5)] = $value;
}
- elseif (substr($key, 0, 15) == 'move_rel_table_' and $value == '1') {
+ elseif (substr($key, 0, 15) === 'move_rel_table_' and $value == '1') {
$moveTables = array_merge($moveTables, $relTables[substr($key, 5)]['tables']);
if (array_key_exists('operation', $migrationInfo)) {
foreach ($relTables[substr($key, 5)]['tables'] as $table) {
}
}
}
- elseif (substr($key, 0, 15) == 'move_rel_table_' and $value == '0') {
+ elseif (substr($key, 0, 15) === 'move_rel_table_' and $value == '0') {
$removeTables = array_merge($moveTables, $relTables[substr($key, 5)]['tables']);
}
}
* add/update membership(s) to related contacts
*
* @param int $contactID
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
public static function addMembershipToRealtedContacts($contactID) {
$dao = new CRM_Member_DAO_Membership();
*/
public static function mergeLocations($mainId, $otherId, $migrationInfo) {
foreach ($migrationInfo as $key => $value) {
- $isLocationField = (substr($key, 0, 14) == 'move_location_' and $value != NULL);
+ $isLocationField = (substr($key, 0, 14) === 'move_location_' and $value != NULL);
if (!$isLocationField) {
continue;
}
// Ignore operation for websites
// @todo Tidy this up
$operation = 0;
- if ($fieldName != 'website') {
+ if ($fieldName !== 'website') {
$operation = $migrationInfo['location_blocks'][$fieldName][$fieldCount]['operation'] ?? NULL;
}
// default operation is overwrite.
protected static function swapOutFieldsAffectedByQFZeroBug(&$migrationInfo) {
$qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
foreach ($migrationInfo as $key => &$value) {
- if ($value == $qfZeroBug) {
+ if ($value === $qfZeroBug) {
$value = '0';
}
}
* Goal is to move all custom field handling into 'move' functions on the various BAO
* with an underlying DAO function. For custom fields it has been started on the BAO.
*
- * @param $mainId
- * @param $key
- * @param $cFields
- * @param $submitted
- * @param $value
+ * @param int $mainId
+ * @param string $key
+ * @param array $cFields
+ * @param array $submitted
+ * @param mixed $value
*
* @return array
* @throws \CRM_Core_Exception
*/
protected static function processCustomFields($mainId, $key, $cFields, $submitted, $value) {
- if (substr($key, 0, 7) == 'custom_') {
+ if (substr($key, 0, 7) === 'custom_') {
$fid = (int) substr($key, 7);
if (empty($cFields[$fid])) {
return [$cFields, $submitted];
}
$htmlType = $cFields[$fid]['attributes']['html_type'];
- switch ($htmlType) {
- case 'File':
- // Handled in CustomField->move(). Tested in testMergeCustomFields.
- unset($submitted["custom_$fid"]);
- break;
-
- case 'Select Country':
- // @todo Test in testMergeCustomFields disabled as this does not work, Handle in CustomField->move().
- case 'Select State/Province':
- $submitted[$key] = CRM_Core_BAO_CustomField::displayValue($value, $fid);
- break;
+ $isSerialized = CRM_Core_BAO_CustomField::isSerialized($cFields[$fid]['attributes']);
- case 'Select Date':
- if ($cFields[$fid]['attributes']['is_view']) {
- $submitted[$key] = date('YmdHis', strtotime($submitted[$key]));
- }
- break;
-
- case 'CheckBox':
- case 'Multi-Select':
- case 'Multi-Select Country':
- case 'Multi-Select State/Province':
- // Merge values from both contacts for multivalue fields, CRM-4385
- // get the existing custom values from db.
- $customParams = ['entityID' => $mainId, $key => TRUE];
- $customfieldValues = CRM_Core_BAO_CustomValueTable::getValues($customParams);
- if (!empty($customfieldValues[$key])) {
- $existingValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customfieldValues[$key]);
- if (is_array($existingValue) && !empty($existingValue)) {
- $mergeValue = $submittedCustomFields = [];
- if ($value == 'null') {
- // CRM-19074 if someone has deliberately chosen to overwrite with 'null', respect it.
- $submitted[$key] = $value;
+ if ($htmlType === 'File') {
+ // Handled in CustomField->move(). Tested in testMergeCustomFields.
+ unset($submitted["custom_$fid"]);
+ }
+ elseif (!$isSerialized && ($htmlType === 'Select Country' || $htmlType === 'Select State/Province')) {
+ // @todo Test in testMergeCustomFields disabled as this does not work, Handle in CustomField->move().
+ $submitted[$key] = CRM_Core_BAO_CustomField::displayValue($value, $fid);
+ }
+ elseif ($htmlType === 'Select Date') {
+ if ($cFields[$fid]['attributes']['is_view']) {
+ $submitted[$key] = date('YmdHis', strtotime($submitted[$key]));
+ }
+ }
+ elseif ($isSerialized) {
+ // Merge values from both contacts for multivalue fields, CRM-4385
+ // get the existing custom values from db.
+ $customParams = ['entityID' => $mainId, $key => TRUE];
+ $customfieldValues = CRM_Core_BAO_CustomValueTable::getValues($customParams);
+ if (!empty($customfieldValues[$key])) {
+ $existingValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customfieldValues[$key]);
+ if (is_array($existingValue) && !empty($existingValue)) {
+ $mergeValue = $submittedCustomFields = [];
+ if ($value === 'null') {
+ // CRM-19074 if someone has deliberately chosen to overwrite with 'null', respect it.
+ $submitted[$key] = $value;
+ }
+ else {
+ if ($value) {
+ $submittedCustomFields = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
}
- else {
- if ($value) {
- $submittedCustomFields = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
- }
- // CRM-19653: overwrite or add the existing custom field value with dupicate contact's
- // custom field value stored at $submittedCustomValue.
- foreach ($submittedCustomFields as $k => $v) {
- if ($v != '' && !in_array($v, $mergeValue)) {
- $mergeValue[] = $v;
- }
+ // CRM-19653: overwrite or add the existing custom field value with dupicate contact's
+ // custom field value stored at $submittedCustomValue.
+ foreach ($submittedCustomFields as $k => $v) {
+ if ($v != '' && !in_array($v, $mergeValue)) {
+ $mergeValue[] = $v;
}
+ }
- //keep state and country as array format.
- //for checkbox and m-select format w/ VALUE_SEPARATOR
- if (in_array($htmlType, [
- 'CheckBox',
- 'Multi-Select',
- ])) {
- $submitted[$key] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
- $mergeValue
- ) . CRM_Core_DAO::VALUE_SEPARATOR;
- }
- else {
- $submitted[$key] = $mergeValue;
- }
+ //keep state and country as array format.
+ //for checkbox and m-select format w/ VALUE_SEPARATOR
+ if (in_array($htmlType, ['CheckBox', 'Select'])) {
+ $submitted[$key] = CRM_Utils_Array::implodePadded($mergeValue);
+ }
+ else {
+ $submitted[$key] = $mergeValue;
}
}
}
- elseif (in_array($htmlType, [
- '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);
- //hack to remove null values from array.
- $mergeValue = [];
- foreach ($mergeValueArray as $k => $v) {
- if ($v != '') {
- $mergeValue[] = $v;
- }
+ }
+ elseif (in_array($htmlType, ['Select Country', 'Select State/Province'])) {
+ //we require submitted values should be in array format
+ if ($value) {
+ $mergeValueArray = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
+ //hack to remove null values from array.
+ $mergeValue = [];
+ foreach ($mergeValueArray as $k => $v) {
+ if ($v != '') {
+ $mergeValue[] = $v;
}
- $submitted[$key] = $mergeValue;
}
+ $submitted[$key] = $mergeValue;
}
- break;
-
- default:
- break;
+ }
}
}
return [$cFields, $submitted];
continue;
}
elseif ((in_array(substr($key, 5), CRM_Dedupe_Merger::getContactFields()) or
- substr($key, 0, 12) == 'move_custom_'
+ substr($key, 0, 12) === 'move_custom_'
) and $val != NULL
) {
// Rule: If both main-contact, and other-contact have a field with a
// leaving that investigation as a @todo - until tests can be written.
// Note the handling of this has test coverage - although the data-typing
// of '0' feels flakey we have insurance.
- || ($migrationInfo['rows'][$key]['main'] === '0' && substr($key, 0, 12) == 'move_custom_')
+ || ($migrationInfo['rows'][$key]['main'] === '0' && substr($key, 0, 12) === 'move_custom_')
)
&& $migrationInfo['rows'][$key]['main'] != $migrationInfo['rows'][$key]['other']
) {
$conflicts[$key] = NULL;
}
}
- elseif (substr($key, 0, 14) == 'move_location_' and $val != NULL) {
+ elseif (substr($key, 0, 14) === 'move_location_' and $val != NULL) {
$locField = explode('_', $key);
$fieldName = $locField[2];
$fieldCount = $locField[3];