$config = CRM_Core_Config::singleton();
if ($config->userSystem->is_drupal) {
$userRecordUrl = CRM_Utils_System::url('user/%ufid');
- $title = ts('%1 User: %2; user id: %3', array(1 => $config->userFramework, 2 => '$ufname', 3 => '$ufid'));
+ $title = ts('%1 User: %2; user id: %3', [
+ 1 => $config->userFramework,
+ 2 => '$ufname',
+ 3 => '$ufid',
+ ]);
}
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', array(1 => $config->userFramework, 2 => '$ufname', 3 => '$ufid'));
+ $title = ts('%1 User: %2; user id: %3', [
+ 1 => $config->userFramework,
+ 2 => '$ufname',
+ 3 => '$ufid',
+ ]);
}
- $relTables = array(
- 'rel_table_contributions' => array(
+ $relTables = [
+ 'rel_table_contributions' => [
'title' => ts('Contributions'),
- 'tables' => array('civicrm_contribution', 'civicrm_contribution_recur', 'civicrm_contribution_soft'),
+ 'tables' => [
+ 'civicrm_contribution',
+ 'civicrm_contribution_recur',
+ 'civicrm_contribution_soft',
+ ],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=contribute'),
- ),
- 'rel_table_contribution_page' => array(
+ ],
+ 'rel_table_contribution_page' => [
'title' => ts('Contribution Pages'),
- 'tables' => array('civicrm_contribution_page'),
+ 'tables' => ['civicrm_contribution_page'],
'url' => CRM_Utils_System::url('civicrm/admin/contribute', 'reset=1&cid=$cid'),
- ),
- 'rel_table_memberships' => array(
+ ],
+ 'rel_table_memberships' => [
'title' => ts('Memberships'),
- 'tables' => array('civicrm_membership', 'civicrm_membership_log', 'civicrm_membership_type'),
+ 'tables' => [
+ 'civicrm_membership',
+ 'civicrm_membership_log',
+ 'civicrm_membership_type',
+ ],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=member'),
- ),
- 'rel_table_participants' => array(
+ ],
+ 'rel_table_participants' => [
'title' => ts('Participants'),
- 'tables' => array('civicrm_participant'),
+ 'tables' => ['civicrm_participant'],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=participant'),
- ),
- 'rel_table_events' => array(
+ ],
+ 'rel_table_events' => [
'title' => ts('Events'),
- 'tables' => array('civicrm_event'),
+ 'tables' => ['civicrm_event'],
'url' => CRM_Utils_System::url('civicrm/event/manage', 'reset=1&cid=$cid'),
- ),
- 'rel_table_activities' => array(
+ ],
+ 'rel_table_activities' => [
'title' => ts('Activities'),
- 'tables' => array('civicrm_activity', 'civicrm_activity_contact'),
+ 'tables' => ['civicrm_activity', 'civicrm_activity_contact'],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=activity'),
- ),
- 'rel_table_relationships' => array(
+ ],
+ 'rel_table_relationships' => [
'title' => ts('Relationships'),
- 'tables' => array('civicrm_relationship'),
+ 'tables' => ['civicrm_relationship'],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=rel'),
- ),
- 'rel_table_custom_groups' => array(
+ ],
+ 'rel_table_custom_groups' => [
'title' => ts('Custom Groups'),
- 'tables' => array('civicrm_custom_group'),
+ 'tables' => ['civicrm_custom_group'],
'url' => CRM_Utils_System::url('civicrm/admin/custom/group', 'reset=1'),
- ),
- 'rel_table_uf_groups' => array(
+ ],
+ 'rel_table_uf_groups' => [
'title' => ts('Profiles'),
- 'tables' => array('civicrm_uf_group'),
+ 'tables' => ['civicrm_uf_group'],
'url' => CRM_Utils_System::url('civicrm/admin/uf/group', 'reset=1'),
- ),
- 'rel_table_groups' => array(
+ ],
+ 'rel_table_groups' => [
'title' => ts('Groups'),
- 'tables' => array('civicrm_group_contact'),
+ 'tables' => ['civicrm_group_contact'],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=group'),
- ),
- 'rel_table_notes' => array(
+ ],
+ 'rel_table_notes' => [
'title' => ts('Notes'),
- 'tables' => array('civicrm_note'),
+ 'tables' => ['civicrm_note'],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=note'),
- ),
- 'rel_table_tags' => array(
+ ],
+ 'rel_table_tags' => [
'title' => ts('Tags'),
- 'tables' => array('civicrm_entity_tag'),
+ 'tables' => ['civicrm_entity_tag'],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=tag'),
- ),
- 'rel_table_mailings' => array(
+ ],
+ 'rel_table_mailings' => [
'title' => ts('Mailings'),
- 'tables' => array('civicrm_mailing', 'civicrm_mailing_event_queue', 'civicrm_mailing_event_subscribe'),
+ 'tables' => [
+ 'civicrm_mailing',
+ 'civicrm_mailing_event_queue',
+ 'civicrm_mailing_event_subscribe',
+ ],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=mailing'),
- ),
- 'rel_table_cases' => array(
+ ],
+ 'rel_table_cases' => [
'title' => ts('Cases'),
- 'tables' => array('civicrm_case_contact'),
+ 'tables' => ['civicrm_case_contact'],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=case'),
- ),
- 'rel_table_grants' => array(
+ ],
+ 'rel_table_grants' => [
'title' => ts('Grants'),
- 'tables' => array('civicrm_grant'),
+ 'tables' => ['civicrm_grant'],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=grant'),
- ),
- 'rel_table_pcp' => array(
+ ],
+ 'rel_table_pcp' => [
'title' => ts('PCPs'),
- 'tables' => array('civicrm_pcp'),
+ 'tables' => ['civicrm_pcp'],
'url' => CRM_Utils_System::url('civicrm/contribute/pcp/manage', 'reset=1'),
- ),
- 'rel_table_pledges' => array(
+ ],
+ 'rel_table_pledges' => [
'title' => ts('Pledges'),
- 'tables' => array('civicrm_pledge', 'civicrm_pledge_payment'),
+ 'tables' => ['civicrm_pledge', 'civicrm_pledge_payment'],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=pledge'),
- ),
- 'rel_table_users' => array(
+ ],
+ 'rel_table_users' => [
'title' => $title,
- 'tables' => array('civicrm_uf_match'),
+ 'tables' => ['civicrm_uf_match'],
'url' => $userRecordUrl,
- ),
- );
+ ],
+ ];
$relTables += self::getMultiValueCustomSets('relTables');
*/
public static function getActiveRelTables($cid) {
$cid = (int) $cid;
- $groups = array();
+ $groups = [];
$relTables = self::relTables();
$cidRefs = self::cidRefs();
$eidRefs = self::eidRefs();
foreach ($relTables as $group => $params) {
- $sqls = array();
+ $sqls = [];
foreach ($params['tables'] as $table) {
if (isset($cidRefs[$table])) {
foreach ($cidRefs[$table] as $field) {
CRM_Utils_Hook::merge('cidRefs', $contactReferences);
if ($contactReferences !== $coreReferences) {
- Civi::log()->warning("Deprecated hook ::merge in context of 'cidRefs. Use entityTypes instead.", array('civi.tag' => 'deprecated'));
+ Civi::log()
+ ->warning("Deprecated hook ::merge in context of 'cidRefs. Use entityTypes instead.", ['civi.tag' => 'deprecated']);
}
\Civi::$statics[__CLASS__]['contact_references'] = $contactReferences;
return \Civi::$statics[__CLASS__]['contact_references'];
if (!$eidRefs) {
// FIXME: this should be generated dynamically from the schema
// tables that reference contacts with entity_{id,table}
- $eidRefs = array(
- 'civicrm_acl' => array('entity_table' => 'entity_id'),
- 'civicrm_acl_entity_role' => array('entity_table' => 'entity_id'),
- 'civicrm_entity_file' => array('entity_table' => 'entity_id'),
- 'civicrm_log' => array('entity_table' => 'entity_id'),
- 'civicrm_mailing_group' => array('entity_table' => 'entity_id'),
- 'civicrm_note' => array('entity_table' => 'entity_id'),
- );
+ $eidRefs = [
+ 'civicrm_acl' => ['entity_table' => 'entity_id'],
+ 'civicrm_acl_entity_role' => ['entity_table' => 'entity_id'],
+ 'civicrm_entity_file' => ['entity_table' => 'entity_id'],
+ 'civicrm_log' => ['entity_table' => 'entity_id'],
+ 'civicrm_mailing_group' => ['entity_table' => 'entity_id'],
+ 'civicrm_note' => ['entity_table' => 'entity_id'],
+ ];
// Allow hook_civicrm_merge() to adjust $eidRefs
CRM_Utils_Hook::merge('eidRefs', $eidRefs);
public static function locTables() {
static $locTables;
if (!$locTables) {
- $locTables = array('civicrm_email', 'civicrm_address', 'civicrm_phone');
+ $locTables = ['civicrm_email', 'civicrm_address', 'civicrm_phone'];
// Allow hook_civicrm_merge() to adjust $locTables
CRM_Utils_Hook::merge('locTables', $locTables);
public static function getMultiValueCustomSets($request) {
if (!isset(Civi::$statics[__CLASS__]['multiValueCustomSets'])) {
- $data = array(
- 'relTables' => array(),
- 'cidRefs' => array(),
- );
- $result = civicrm_api3('custom_group', 'get', array(
+ $data = [
+ 'relTables' => [],
+ 'cidRefs' => [],
+ ];
+ $result = civicrm_api3('custom_group', 'get', [
'is_multiple' => 1,
- 'extends' => array('IN' => array('Individual', 'Organization', 'Household', 'Contact')),
- 'return' => array('id', 'title', 'table_name', 'style'),
- ));
+ 'extends' => [
+ 'IN' => [
+ 'Individual',
+ 'Organization',
+ 'Household',
+ 'Contact',
+ ],
+ ],
+ 'return' => ['id', 'title', 'table_name', 'style'],
+ ]);
foreach ($result['values'] as $custom) {
- $data['cidRefs'][$custom['table_name']] = array('entity_id');
+ $data['cidRefs'][$custom['table_name']] = ['entity_id'];
$urlSuffix = $custom['style'] == 'Tab' ? '&selectedChild=custom_' . $custom['id'] : '';
- $data['relTables']['rel_table_custom_' . $custom['id']] = array(
+ $data['relTables']['rel_table_custom_' . $custom['id']] = [
'title' => $custom['title'],
- 'tables' => array($custom['table_name']),
+ 'tables' => [$custom['table_name']],
'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid' . $urlSuffix),
- );
+ ];
}
// Store the result in a static variable cache
public static function cpTables() {
static $tables;
if (!$tables) {
- $tables = array(
- 'civicrm_case_contact' => array('CRM_Case_BAO_Case' => 'mergeContacts'),
- 'civicrm_group_contact' => array('CRM_Contact_BAO_GroupContact' => 'mergeGroupContact'),
+ $tables = [
+ 'civicrm_case_contact' => ['CRM_Case_BAO_Case' => 'mergeContacts'],
+ 'civicrm_group_contact' => ['CRM_Contact_BAO_GroupContact' => 'mergeGroupContact'],
// Empty array == do nothing - this table is handled by mergeGroupContact
- 'civicrm_subscription_history' => array(),
- 'civicrm_relationship' => array('CRM_Contact_BAO_Relationship' => 'mergeRelationships'),
- 'civicrm_membership' => array('CRM_Member_BAO_Membership' => 'mergeMemberships'),
- );
+ 'civicrm_subscription_history' => [],
+ 'civicrm_relationship' => ['CRM_Contact_BAO_Relationship' => 'mergeRelationships'],
+ 'civicrm_membership' => ['CRM_Member_BAO_Membership' => 'mergeMemberships'],
+ ];
}
return $tables;
}
public static function paymentTables() {
static $tables;
if (!$tables) {
- $tables = array('civicrm_pledge', 'civicrm_membership', 'civicrm_participant');
+ $tables = ['civicrm_pledge', 'civicrm_membership', 'civicrm_participant'];
}
return $tables;
}
* @return array
*/
public static function paymentSql($tableName, $mainContactId, $otherContactId) {
- $sqls = array();
+ $sqls = [];
if (!$tableName || !$mainContactId || !$otherContactId) {
return $sqls;
}
*
* @return array
*/
- public static function operationSql($mainId, $otherId, $tableName, $tableOperations = array(), $mode = 'add') {
- $sqls = array();
+ public static function operationSql($mainId, $otherId, $tableName, $tableOperations = [], $mode = 'add') {
+ $sqls = [];
if (!$tableName || !$mainId || !$otherId) {
return $sqls;
}
if (in_array("civicrm_membership", $tables)) {
$membershipIDs = CRM_Utils_Array::collect('id',
CRM_Utils_Array::value('values',
- civicrm_api3("Membership", "get", array(
- "contact_id" => $otherID,
- "return" => "id",
- )
+ civicrm_api3("Membership", "get", [
+ "contact_id" => $otherID,
+ "return" => "id",
+ ]
)
));
if (!empty($membershipIDs)) {
- civicrm_api3("Membership", "get", array(
- 'owner_membership_id' => array('IN' => $membershipIDs),
- 'api.Membership.delete' => array('id' => '$value.id'),
- ));
+ civicrm_api3("Membership", "get", [
+ 'owner_membership_id' => ['IN' => $membershipIDs],
+ 'api.Membership.delete' => ['id' => '$value.id'],
+ ]);
}
}
}
* @param array $tableOperations
* @param array $customTableToCopyFrom
*/
- public static function moveContactBelongings($mainId, $otherId, $tables = FALSE, $tableOperations = array(), $customTableToCopyFrom = NULL) {
+ public static function moveContactBelongings($mainId, $otherId, $tables = FALSE, $tableOperations = [], $customTableToCopyFrom = NULL) {
$cidRefs = self::cidRefs();
$eidRefs = self::eidRefs();
$cpTables = self::cpTables();
$paymentTables = self::paymentTables();
// getting all custom tables
- $customTables = array();
+ $customTables = [];
if ($customTableToCopyFrom !== NULL) {
// @todo this duplicates cidRefs?
CRM_Core_DAO::appendCustomTablesExtendingContacts($customTables);
$otherId = (int) $otherId;
$multi_value_tables = array_keys(CRM_Dedupe_Merger::getMultiValueCustomSets('cidRefs'));
- $sqls = array();
+ $sqls = [];
foreach ($affected as $table) {
// skipping non selected single-value custom table's value migration
if (!in_array($table, $multi_value_tables)) {
// call the SQL queries in one transaction
$transaction = new CRM_Core_Transaction();
foreach ($sqls as $sql) {
- CRM_Core_DAO::executeQuery($sql, array(), TRUE, NULL, TRUE);
+ CRM_Core_DAO::executeQuery($sql, [], TRUE, NULL, TRUE);
}
CRM_Dedupe_Merger::addMembershipToRealtedContacts($mainId);
$transaction->commit();
* @return array
*/
public static function retrieveFields($main, $other) {
- $result = array(
- 'contact' => array(),
- 'custom' => array(),
- );
+ $result = [
+ 'contact' => [],
+ 'custom' => [],
+ ];
foreach (self::getContactFields() as $validField) {
// CRM-17556 Get all non-empty fields, to make comparison easier
if (!empty($main[$validField]) || !empty($other[$validField])) {
*
* @return array|bool
*/
- public static function batchMerge($rgid, $gid = NULL, $mode = 'safe', $batchLimit = 1, $isSelected = 2, $criteria = array(), $checkPermissions = TRUE, $reloadCacheIfEmpty = NULL) {
+ public static function batchMerge($rgid, $gid = NULL, $mode = 'safe', $batchLimit = 1, $isSelected = 2, $criteria = [], $checkPermissions = TRUE, $reloadCacheIfEmpty = NULL) {
$redirectForPerformance = ($batchLimit > 1) ? TRUE : FALSE;
if (!isset($reloadCacheIfEmpty)) {
}
$dupePairs = self::getDuplicatePairs($rgid, $gid, $reloadCacheIfEmpty, $batchLimit, $isSelected, '', ($mode == 'aggressive'), $criteria, $checkPermissions);
- $cacheParams = array(
+ $cacheParams = [
'cache_key_string' => self::getMergeCacheKeyString($rgid, $gid, $criteria, $checkPermissions),
// @todo stop passing these parameters in & instead calculate them in the merge function based
// on the 'real' params like $isRespectExclusions $batchLimit and $isSelected.
'join' => self::getJoinOnDedupeTable(),
'where' => self::getWhereString($isSelected),
'limit' => (int) $batchLimit,
- );
+ ];
return CRM_Dedupe_Merger::merge($dupePairs, $cacheParams, $mode, $redirectForPerformance, $checkPermissions);
}
* @param string $cacheKeyString
* @param array $result
*/
- public static function updateMergeStats($cacheKeyString, $result = array()) {
+ public static function updateMergeStats($cacheKeyString, $result = []) {
// gather latest stats
- $merged = count($result['merged']);
+ $merged = count($result['merged']);
$skipped = count($result['skipped']);
if ($merged <= 0 && $skipped <= 0) {
CRM_Dedupe_Merger::resetMergeStats($cacheKeyString);
// store the updated stats
- $data = array(
- 'merged' => $merged,
+ $data = [
+ 'merged' => $merged,
'skipped' => $skipped,
- );
+ ];
$data = CRM_Core_DAO::escapeString(serialize($data));
- $values = array();
+ $values = [];
$values[] = " ( 'civicrm_contact', 0, 0, '{$cacheKeyString}_stats', '$data' ) ";
CRM_Core_BAO_PrevNextCache::setItem($values);
}
public static function getMergeStatsMsg($stats) {
$msg = '';
if (!empty($stats['merged'])) {
- $msg = '<p>' . ts('One contact merged.', array('count' => $stats['merged'], 'plural' => '%count contacts merged.')) . '</p>';
+ $msg = '<p>' . ts('One contact merged.', [
+ 'count' => $stats['merged'],
+ 'plural' => '%count contacts merged.',
+ ]) . '</p>';
}
if (!empty($stats['skipped'])) {
- $msg .= '<p>' . ts('One contact was skipped.', array('count' => $stats['skipped'], 'plural' => '%count contacts were skipped.')) . '</p>';
+ $msg .= '<p>' . ts('One contact was skipped.', [
+ 'count' => $stats['skipped'],
+ 'plural' => '%count contacts were skipped.',
+ ]) . '</p>';
}
return $msg;
}
*
* @return array|bool
*/
- public static function merge($dupePairs = array(), $cacheParams = array(), $mode = 'safe',
- $redirectForPerformance = FALSE, $checkPermissions = TRUE
+ public static function merge($dupePairs = [], $cacheParams = [], $mode = 'safe',
+ $redirectForPerformance = FALSE, $checkPermissions = TRUE
) {
$cacheKeyString = CRM_Utils_Array::value('cache_key_string', $cacheParams);
- $resultStats = array('merged' => array(), 'skipped' => array());
+ $resultStats = ['merged' => [], 'skipped' => []];
// we don't want dupe caching to get reset after every-merge, and therefore set the
CRM_Core_Config::setPermitCacheFlushMode(FALSE);
- $deletedContacts = array();
+ $deletedContacts = [];
while (!empty($dupePairs)) {
foreach ($dupePairs as $index => $dupes) {
$cacheParams['where'],
0,
$cacheParams['limit'],
- array(),
+ [],
'',
FALSE
);
*
* @return bool
*/
- public static function skipMerge($mainId, $otherId, &$migrationInfo, $mode = 'safe', &$conflicts = array()) {
+ public static function skipMerge($mainId, $otherId, &$migrationInfo, $mode = 'safe', &$conflicts = []) {
$originalMigrationInfo = $migrationInfo;
foreach ($migrationInfo as $key => $val) {
// there's a conflict (to handle "gotchas"). fields_in_conflict could be modified here
// merge happens with new values filled in here. For a particular field / row not to be merged
// field should be unset from fields_in_conflict.
- $migrationData = array(
+ $migrationData = [
'old_migration_info' => $originalMigrationInfo,
'mode' => $mode,
'fields_in_conflict' => $conflicts,
'merge_mode' => $mode,
'migration_info' => $migrationInfo,
- );
+ ];
CRM_Utils_Hook::merge('batch', $migrationData, $mainId, $otherId);
$conflicts = $migrationData['fields_in_conflict'];
// allow hook to override / manipulate migrationInfo as well
* @return bool
*/
static public function locationIsSame($mainAddress, $comparisonAddress) {
- $keysToIgnore = array('id', 'is_primary', 'is_billing', 'manual_geo_code', 'contact_id', 'reset_date', 'hold_date');
+ $keysToIgnore = [
+ 'id',
+ 'is_primary',
+ 'is_billing',
+ 'manual_geo_code',
+ 'contact_id',
+ 'reset_date',
+ 'hold_date',
+ ];
foreach ($comparisonAddress as $field => $value) {
if (in_array($field, $keysToIgnore)) {
continue;
* @return array
*/
public static function getLocationBlockInfo() {
- $locationBlocks = array(
- 'address' => array(
+ $locationBlocks = [
+ 'address' => [
'label' => 'Address',
'displayField' => 'display',
'sortString' => 'location_type_id',
'hasLocation' => TRUE,
'hasType' => FALSE,
- ),
- 'email' => array(
+ ],
+ 'email' => [
'label' => 'Email',
'displayField' => 'display',
'sortString' => 'location_type_id',
'hasLocation' => TRUE,
'hasType' => FALSE,
- ),
- 'im' => array(
+ ],
+ 'im' => [
'label' => 'IM',
'displayField' => 'name',
'sortString' => 'location_type_id,provider_id',
'hasLocation' => TRUE,
'hasType' => 'provider_id',
- ),
- 'phone' => array(
+ ],
+ 'phone' => [
'label' => 'Phone',
'displayField' => 'phone',
'sortString' => 'location_type_id,phone_type_id',
'hasLocation' => TRUE,
'hasType' => 'phone_type_id',
- ),
- 'website' => array(
+ ],
+ 'website' => [
'label' => 'Website',
'displayField' => 'url',
'sortString' => 'website_type_id',
'hasLocation' => FALSE,
'hasType' => 'website_type_id',
- ),
- );
+ ],
+ ];
return $locationBlocks;
}
$compareFields = self::retrieveFields($main, $other);
- $rows = $elements = $relTableElements = $migrationInfo = array();
+ $rows = $elements = $relTableElements = $migrationInfo = [];
foreach ($compareFields['contact'] as $field) {
if ($field == 'contact_sub_type') {
// CRM-15681 don't display sub-types in UI
continue;
}
- foreach (array('main', 'other') as $moniker) {
+ foreach (['main', 'other'] as $moniker) {
$contact = &$$moniker;
$value = CRM_Utils_Array::value($field, $contact);
if (isset($specialValues[$moniker][$field]) && is_string($specialValues[$moniker][$field])) {
$label = CRM_Utils_Array::value('individual_suffix', $contact);
}
elseif ($field == 'gender_id' && !empty($value)) {
- $genderOptions = civicrm_api3('contact', 'getoptions', array('field' => 'gender_id'));
+ $genderOptions = civicrm_api3('contact', 'getoptions', ['field' => 'gender_id']);
$label = $genderOptions['values'][$value];
}
elseif ($field == 'current_employer_id' && !empty($value)) {
// Display a checkbox to migrate, only if the values are different
if ($value != $main[$field]) {
- $elements[] = array('advcheckbox', "move_$field", NULL, NULL, NULL, $value);
+ $elements[] = [
+ 'advcheckbox',
+ "move_$field",
+ NULL,
+ NULL,
+ NULL,
+ $value,
+ ];
}
$migrationInfo["move_$field"] = $value;
// Set up useful information about the location blocks
$locationBlocks = self::getLocationBlockInfo();
- $locations = array(
- 'main' => array(),
- 'other' => array(),
- );
+ $locations = [
+ 'main' => [],
+ 'other' => [],
+ ];
// @todo This could probably be defined and used earlier
- $mergeTargets = array(
+ $mergeTargets = [
'main' => $mainId,
'other' => $otherId,
- );
+ ];
foreach ($locationBlocks as $blockName => $blockInfo) {
// Collect existing fields from both 'main' and 'other' contacts first
// This allows us to match up location/types when building the table rows
foreach ($mergeTargets as $moniker => $cid) {
- $searchParams = array(
+ $searchParams = [
'contact_id' => $cid,
// CRM-17556 Order by field-specific criteria
- 'options' => array(
+ 'options' => [
'sort' => $blockInfo['sortString'],
- ),
- );
+ ],
+ ];
$values = civicrm_api3($blockName, 'get', $searchParams);
if ($values['count']) {
$cnt = 0;
}
// Add checkbox to migrate data from 'other' to 'main'
- $elements[] = array('advcheckbox', "move_location_{$blockName}_{$count}");
+ $elements[] = ['advcheckbox', "move_location_{$blockName}_{$count}"];
// Add checkbox to set the 'other' location as primary
- $elements[] = array('advcheckbox', "location_blocks[$blockName][$count][set_other_primary]", NULL, ts('Set as primary'));
+ $elements[] = [
+ 'advcheckbox',
+ "location_blocks[$blockName][$count][set_other_primary]",
+ NULL,
+ ts('Set as primary'),
+ ];
// Flag up this field to skipMerge function (@todo: do we need to?)
$migrationInfo["move_location_{$blockName}_{$count}"] = 1;
// Add a hidden field to store the ID of the target main contact block
- $elements[] = array('hidden', "location_blocks[$blockName][$count][mainContactBlockId]", $mainContactBlockId);
+ $elements[] = [
+ 'hidden',
+ "location_blocks[$blockName][$count][mainContactBlockId]",
+ $mainContactBlockId,
+ ];
// Setup variables
$thisTypeId = FALSE;
if ($blockInfo['hasLocation']) {
// Load the location options for this entity
- $locationOptions = civicrm_api3($blockName, 'getoptions', array('field' => 'location_type_id'));
+ $locationOptions = civicrm_api3($blockName, 'getoptions', ['field' => 'location_type_id']);
$thisLocId = $value['location_type_id'];
// Put this field's location type at the top of the list
$tmpIdList = $locationOptions['values'];
- $defaultLocId = array($thisLocId => $tmpIdList[$thisLocId]);
+ $defaultLocId = [$thisLocId => $tmpIdList[$thisLocId]];
unset($tmpIdList[$thisLocId]);
// Add the element
- $elements[] = array(
+ $elements[] = [
'select',
"location_blocks[$blockName][$count][locTypeId]",
NULL,
$defaultLocId + $tmpIdList,
- );
+ ];
// Add the relevant information to the $migrationInfo
// Keep location-type-id same as that of other-contact
// @todo Check this logic out
$migrationInfo['location_blocks'][$blockName][$count]['locTypeId'] = $thisLocId;
if ($blockName != 'address') {
- $elements[] = array('advcheckbox', "location_blocks[{$blockName}][$count][operation]", NULL, ts('Add new'));
+ $elements[] = [
+ 'advcheckbox',
+ "location_blocks[{$blockName}][$count][operation]",
+ NULL,
+ ts('Add new'),
+ ];
// always use add operation
$migrationInfo['location_blocks'][$blockName][$count]['operation'] = 1;
}
if ($blockInfo['hasType']) {
// Load the type options for this entity
- $typeOptions = civicrm_api3($blockName, 'getoptions', array('field' => $blockInfo['hasType']));
+ $typeOptions = civicrm_api3($blockName, 'getoptions', ['field' => $blockInfo['hasType']]);
$thisTypeId = CRM_Utils_Array::value($blockInfo['hasType'], $value);
// Put this field's location type at the top of the list
$tmpIdList = $typeOptions['values'];
- $defaultTypeId = array($thisTypeId => CRM_Utils_Array::value($thisTypeId, $tmpIdList));
+ $defaultTypeId = [$thisTypeId => CRM_Utils_Array::value($thisTypeId, $tmpIdList)];
unset($tmpIdList[$thisTypeId]);
// Add the element
- $elements[] = array(
+ $elements[] = [
'select',
"location_blocks[$blockName][$count][typeTypeId]",
NULL,
$defaultTypeId + $tmpIdList,
- );
+ ];
// Add the information to the migrationInfo
$migrationInfo['location_blocks'][$blockName][$count]['typeTypeId'] = $thisTypeId;
continue;
}
- $relTableElements[] = array('checkbox', "move_$name");
+ $relTableElements[] = ['checkbox', "move_$name"];
$migrationInfo["move_$name"] = 1;
$relTables[$name]['main_url'] = str_replace('$cid', $mainId, $relTables[$name]['url']);
if ($name == 'rel_table_users') {
$relTables[$name]['main_url'] = str_replace('%ufid', $mainUfId, $relTables[$name]['url']);
$relTables[$name]['other_url'] = str_replace('%ufid', $otherUfId, $relTables[$name]['url']);
- $find = array('$ufid', '$ufname');
+ $find = ['$ufid', '$ufname'];
if ($mainUser) {
- $replace = array($mainUfId, $mainUser->name);
+ $replace = [$mainUfId, $mainUser->name];
$relTables[$name]['main_title'] = str_replace($find, $replace, $relTables[$name]['title']);
}
if ($otherUser) {
- $replace = array($otherUfId, $otherUser->name);
+ $replace = [$otherUfId, $otherUser->name];
$relTables[$name]['other_title'] = str_replace($find, $replace, $relTables[$name]['title']);
}
}
$attributes = [];
}
}
- $elements[] = array('checkbox', "operation[move_{$name}][add]", NULL, ts('add new'), $attributes);
+ $elements[] = [
+ 'checkbox',
+ "operation[move_{$name}][add]",
+ NULL,
+ ts('add new'),
+ $attributes,
+ ];
$migrationInfo["operation"]["move_{$name}"]['add'] = 1;
}
}
}
$rows["move_custom_$fid"]['title'] = $field['label'];
- $elements[] = array('advcheckbox', "move_custom_$fid", NULL, NULL, NULL, $value);
+ $elements[] = [
+ 'advcheckbox',
+ "move_custom_$fid",
+ NULL,
+ NULL,
+ NULL,
+ $value,
+ ];
$migrationInfo["move_custom_$fid"] = $value;
}
}
}
- $result = array(
+ $result = [
'rows' => $rows,
'elements' => $elements,
'rel_table_elements' => $relTableElements,
'main_details' => $main,
'other_details' => $other,
'migration_info' => $migrationInfo,
- );
+ ];
$result['main_details']['location_blocks'] = $locations['main'];
$result['other_details']['location_blocks'] = $locations['other'];
$qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
$relTables = CRM_Dedupe_Merger::relTables();
- $submittedCustomFields = $moveTables = $locationMigrationInfo = $tableOperations = $removeTables = array();
+ $submittedCustomFields = $moveTables = $locationMigrationInfo = $tableOperations = $removeTables = [];
foreach ($migrationInfo as $key => $value) {
if ($value == $qfZeroBug) {
if (!empty($removeTables)) {
// **** CRM-20421
CRM_Dedupe_Merger::removeContactBelongings($otherId, $removeTables);
- $removeTables = array();
+ $removeTables = [];
}
// FIXME: fix gender, prefix and postfix, so they're edible by createProfileContact()
- $names['gender'] = array('newName' => 'gender_id', 'groupName' => 'gender');
- $names['individual_prefix'] = array('newName' => 'prefix_id', 'groupName' => 'individual_prefix');
- $names['individual_suffix'] = array('newName' => 'suffix_id', 'groupName' => 'individual_suffix');
- $names['communication_style'] = array('newName' => 'communication_style_id', 'groupName' => 'communication_style');
- $names['addressee'] = array('newName' => 'addressee_id', 'groupName' => 'addressee');
- $names['email_greeting'] = array('newName' => 'email_greeting_id', 'groupName' => 'email_greeting');
- $names['postal_greeting'] = array('newName' => 'postal_greeting_id', 'groupName' => 'postal_greeting');
+ $names['gender'] = ['newName' => 'gender_id', 'groupName' => 'gender'];
+ $names['individual_prefix'] = [
+ 'newName' => 'prefix_id',
+ 'groupName' => 'individual_prefix',
+ ];
+ $names['individual_suffix'] = [
+ 'newName' => 'suffix_id',
+ 'groupName' => 'individual_suffix',
+ ];
+ $names['communication_style'] = [
+ 'newName' => 'communication_style_id',
+ 'groupName' => 'communication_style',
+ ];
+ $names['addressee'] = [
+ 'newName' => 'addressee_id',
+ 'groupName' => 'addressee',
+ ];
+ $names['email_greeting'] = [
+ 'newName' => 'email_greeting_id',
+ 'groupName' => 'email_greeting',
+ ];
+ $names['postal_greeting'] = [
+ 'newName' => 'postal_greeting_id',
+ 'groupName' => 'postal_greeting',
+ ];
CRM_Core_OptionGroup::lookupValues($submitted, $names, TRUE);
// fix custom fields so they're edible by createProfileContact()
- $treeCache = array();
+ $treeCache = [];
if (!array_key_exists($migrationInfo['main_details']['contact_type'], $treeCache)) {
$treeCache[$migrationInfo['main_details']['contact_type']] = CRM_Core_BAO_CustomGroup::getTree(
$migrationInfo['main_details']['contact_type'],
NULL,
NULL,
-1,
- array(),
+ [],
NULL,
TRUE,
NULL,
);
}
- $cFields = array();
+ $cFields = [];
foreach ($treeCache[$migrationInfo['main_details']['contact_type']] as $key => $group) {
if (!isset($group['fields'])) {
continue;
}
if (!isset($submitted)) {
- $submitted = array();
+ $submitted = [];
}
foreach ($submitted as $key => $value) {
if (substr($key, 0, 7) == 'custom_') {
case 'Multi-Select State/Province':
// Merge values from both contacts for multivalue fields, CRM-4385
// get the existing custom values from db.
- $customParams = array('entityID' => $mainId, $key => TRUE);
+ $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 = array();
+ $mergeValue = $submittedCustomFields = [];
if ($value == 'null') {
// CRM-19074 if someone has deliberately chosen to overwrite with 'null', respect it.
$submitted[$key] = $value;
//keep state and country as array format.
//for checkbox and m-select format w/ VALUE_SEPARATOR
- if (in_array($htmlType, array(
+ 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;
}
}
}
- elseif (in_array($htmlType, array(
+ 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 = array();
+ $mergeValue = [];
foreach ($mergeValueArray as $k => $v) {
if ($v != '') {
$mergeValue[] = $v;
// like, delete a file...
if (!isset($customFiles)) {
- $customFiles = array();
+ $customFiles = [];
}
foreach ($customFiles as $customId) {
list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($customId);
// get the contact_id -> file_id mapping
- $fileIds = array();
+ $fileIds = [];
$sql = "SELECT entity_id, {$columnName} AS file_id FROM {$tableName} WHERE entity_id IN ({$mainId}, {$otherId})";
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
}
// move view only custom fields CRM-5362
- $viewOnlyCustomFields = array();
+ $viewOnlyCustomFields = [];
foreach ($submitted as $key => $value) {
$fid = CRM_Core_BAO_CustomField::getKeyID($key);
if ($fid && array_key_exists($fid, $cFields) && !empty($cFields[$fid]['attributes']['is_view'])
}
if (!$checkPermissions || (CRM_Core_Permission::check('merge duplicate contacts') &&
- CRM_Core_Permission::check('delete contacts'))
+ CRM_Core_Permission::check('delete contacts'))
) {
// if ext id is submitted then set it null for contact to be deleted
if (!empty($submitted['external_identifier'])) {
$query = "UPDATE civicrm_contact SET external_identifier = null WHERE id = {$otherId}";
CRM_Core_DAO::executeQuery($query);
}
- civicrm_api3('contact', 'delete', array('id' => $otherId));
+ civicrm_api3('contact', 'delete', ['id' => $otherId]);
}
// CRM-15681 merge sub_types
* Array of custom table names
*/
private static function getAffectedCustomTables($customFieldIDs) {
- $customTableToCopyValues = array();
+ $customTableToCopyValues = [];
foreach ($customFieldIDs as $fieldID) {
if (!empty($fieldID)) {
- $customField = civicrm_api3('custom_field', 'getsingle', array(
+ $customField = civicrm_api3('custom_field', 'getsingle', [
'id' => $fieldID,
'is_active' => TRUE,
- ));
+ ]);
if (!civicrm_error($customField) && !empty($customField['custom_group_id'])) {
- $customGroup = civicrm_api3('custom_group', 'getsingle', array(
+ $customGroup = civicrm_api3('custom_group', 'getsingle', [
'id' => $customField['custom_group_id'],
'is_active' => TRUE,
- ));
+ ]);
if (!civicrm_error($customGroup) && !empty($customGroup['table_name'])) {
$customTableToCopyValues[] = $customGroup['table_name'];
*/
public static function getContactFields() {
$contactFields = CRM_Contact_DAO_Contact::fields();
- $invalidFields = array(
+ $invalidFields = [
'api_key',
'created_date',
'display_name',
'primary_contact_id',
'sort_name',
'user_unique_id',
- );
+ ];
foreach ($contactFields as $field => $value) {
if (in_array($field, $invalidFields)) {
unset($contactFields[$field]);
while ($dao->fetch()) {
$relationshipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $dao->membership_type_id, 'relationship_type_id', 'id');
if ($relationshipTypeId) {
- $membershipParams = array(
+ $membershipParams = [
'id' => $dao->id,
'contact_id' => $dao->contact_id,
'membership_type_id' => $dao->membership_type_id,
'end_date' => CRM_Utils_Date::isoToMysql($dao->end_date),
'source' => $dao->source,
'status_id' => $dao->status_id,
- );
+ ];
// create/update membership(s) for related contact(s)
CRM_Member_BAO_Membership::createRelatedMemberships($membershipParams, $dao);
} // end of if relationshipTypeId
* @throws \CiviCRM_API3_Exception
*/
public static function createMergeActivities($mainId, $otherId) {
- $params = array(
+ $params = [
1 => $otherId,
2 => $mainId,
- );
- $activity = civicrm_api3('activity', 'create', array(
+ ];
+ $activity = civicrm_api3('activity', 'create', [
'source_contact_id' => CRM_Core_Session::getLoggedInContactID() ? CRM_Core_Session::getLoggedInContactID() :
$mainId,
'subject' => ts('Contact ID %1 has been merged and deleted.', $params),
'target_contact_id' => $mainId,
'activity_type_id' => 'Contact Merged',
'status_id' => 'Completed',
- ));
- if (civicrm_api3('Setting', 'getvalue', array('name' => 'contact_undelete', 'group' => 'CiviCRM Preferences'))) {
- civicrm_api3('activity', 'create', array(
+ ]);
+ if (civicrm_api3('Setting', 'getvalue', [
+ 'name' => 'contact_undelete',
+ 'group' => 'CiviCRM Preferences',
+ ])) {
+ civicrm_api3('activity', 'create', [
'source_contact_id' => CRM_Core_Session::getLoggedInContactID() ? CRM_Core_Session::getLoggedInContactID() :
$otherId,
'subject' => ts('Contact ID %1 has been merged into Contact ID %2 and deleted.', $params),
'activity_type_id' => 'Contact Deleted by Merge',
'parent_id' => $activity['id'],
'status_id' => 'Completed',
- ));
+ ]);
}
}
* @return array
* Array of matches meeting the criteria.
*/
- public static function getDuplicatePairs($rule_group_id, $group_id, $reloadCacheIfEmpty, $batchLimit, $isSelected, $orderByClause = '', $includeConflicts = TRUE, $criteria = array(), $checkPermissions = TRUE, $searchLimit = 0) {
+ public static function getDuplicatePairs($rule_group_id, $group_id, $reloadCacheIfEmpty, $batchLimit, $isSelected, $orderByClause = '', $includeConflicts = TRUE, $criteria = [], $checkPermissions = TRUE, $searchLimit = 0) {
$where = self::getWhereString($isSelected);
$cacheKeyString = self::getMergeCacheKeyString($rule_group_id, $group_id, $criteria, $checkPermissions);
$join = self::getJoinOnDedupeTable();
- $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, $batchLimit, array(), $orderByClause, $includeConflicts);
+ $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, $batchLimit, [], $orderByClause, $includeConflicts);
if (empty($dupePairs) && $reloadCacheIfEmpty) {
// If we haven't found any dupes, probably cache is empty.
// Try filling cache and give another try. We don't need to specify include conflicts here are there will not be any
// until we have done some processing.
CRM_Core_BAO_PrevNextCache::refillCache($rule_group_id, $group_id, $cacheKeyString, $criteria, $checkPermissions, $searchLimit);
- $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, $batchLimit, array(), $orderByClause, $includeConflicts);
+ $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, $batchLimit, [], $orderByClause, $includeConflicts);
return $dupePairs;
}
return $dupePairs;
*
* @return string
*/
- public static function getMergeCacheKeyString($rule_group_id, $group_id, $criteria = array(), $checkPermissions = TRUE) {
+ public static function getMergeCacheKeyString($rule_group_id, $group_id, $criteria = [], $checkPermissions = TRUE) {
$contactType = CRM_Dedupe_BAO_RuleGroup::getContactTypeForRuleGroup($rule_group_id);
$cacheKeyString = "merge_{$contactType}";
$cacheKeyString .= $rule_group_id ? "_{$rule_group_id}" : '_0';
*/
public static function getSpecialValues($contact) {
$preferred_communication_method = CRM_Utils_Array::value('preferred_communication_method', $contact);
- $value = empty($preferred_communication_method) ? array() : $preferred_communication_method;
- $specialValues = array(
+ $value = empty($preferred_communication_method) ? [] : $preferred_communication_method;
+ $specialValues = [
'preferred_communication_method' => $value,
'communication_style_id' => $value,
- );
+ ];
if (!empty($contact['preferred_communication_method'])) {
// api 3 returns pref_comm_method as an array, which breaks the lookup; so we reconstruct
$prefCommList = is_array($specialValues['preferred_communication_method']) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $specialValues['preferred_communication_method']) : $specialValues['preferred_communication_method'];
$specialValues['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . $prefCommList . CRM_Core_DAO::VALUE_SEPARATOR;
}
- $names = array(
- 'preferred_communication_method' => array(
+ $names = [
+ 'preferred_communication_method' => [
'newName' => 'preferred_communication_method_display',
'groupName' => 'preferred_communication_method',
- ),
- );
+ ],
+ ];
CRM_Core_OptionGroup::lookupValues($specialValues, $names);
if (!empty($contact['communication_style'])) {
return \Civi::$statics[__CLASS__]['merge_fields_metadata'];
}
$fields = CRM_Contact_DAO_Contact::fields();
- static $optionValueFields = array();
+ static $optionValueFields = [];
if (empty($optionValueFields)) {
$optionValueFields = CRM_Core_OptionValue::getFields();
}
* @throws CRM_Core_Exception
*/
public static function getMergeContactDetails($contact_id) {
- $params = array(
+ $params = [
'contact_id' => $contact_id,
'version' => 3,
- 'return' => array_merge(array('display_name'), self::getContactFields()),
- );
+ 'return' => array_merge(['display_name'], self::getContactFields()),
+ ];
$result = civicrm_api('contact', 'get', $params);
// CRM-18480: Cancel the process if the contact is already deleted
if (isset($result['values'][$contact_id]['contact_is_deleted']) && !empty($result['values'][$contact_id]['contact_is_deleted'])) {
- throw new CRM_Core_Exception(ts('Cannot merge because one contact (ID %1) has been deleted.', array(
+ throw new CRM_Core_Exception(ts('Cannot merge because one contact (ID %1) has been deleted.', [
1 => $contact_id,
- )));
+ ]));
}
return $result['values'][$contact_id];
}
$locBlocks[$fieldName][$fieldCount]['operation'] = $operation;
}
- $blocksDAO = array();
+ $blocksDAO = [];
// @todo Handle OpenID (not currently in API).
if (!empty($locBlocks)) {
$locationBlocks = self::getLocationBlockInfo();
- $primaryBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($mainId, array('is_primary' => 1));
- $billingBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($mainId, array('is_billing' => 1));
+ $primaryBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($mainId, ['is_primary' => 1]);
+ $billingBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($mainId, ['is_billing' => 1]);
foreach ($locBlocks as $name => $block) {
- $blocksDAO[$name] = array('delete' => array(), 'update' => array());
+ $blocksDAO[$name] = ['delete' => [], 'update' => []];
if (!is_array($block) || CRM_Utils_System::isNull($block)) {
continue;
}
protected static function dedupePair(&$migrationInfo, &$resultStats, &$deletedContacts, $mode, $checkPermissions, $mainId, $otherId, $cacheKeyString) {
// go ahead with merge if there is no conflict
- $conflicts = array();
+ $conflicts = [];
if (!CRM_Dedupe_Merger::skipMerge($mainId, $otherId, $migrationInfo, $mode, $conflicts)) {
CRM_Dedupe_Merger::moveAllBelongings($mainId, $otherId, $migrationInfo, $checkPermissions);
- $resultStats['merged'][] = array(
+ $resultStats['merged'][] = [
'main_id' => $mainId,
'other_id' => $otherId,
- );
+ ];
$deletedContacts[] = $otherId;
}
else {
- $resultStats['skipped'][] = array(
+ $resultStats['skipped'][] = [
'main_id' => $mainId,
'other_id' => $otherId,
- );
+ ];
}
// store any conflicts