+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015 |
+ | Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
*/
class CRM_Dedupe_Merger {
'rel_table_mailings' => array(
'title' => ts('Mailings'),
'tables' => array('civicrm_mailing', 'civicrm_mailing_event_queue', 'civicrm_mailing_event_subscribe'),
- 'url' => CRM_Utils_System::url('civicrm/mailing', 'reset=1&force=1&cid=$cid'),
+ 'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=mailing'),
),
'rel_table_cases' => array(
'title' => ts('Cases'),
$$moniker = $result['values'][$cid];
}
- static $fields = array();
- if (empty($fields)) {
- $fields = CRM_Contact_DAO_Contact::fields();
- CRM_Core_DAO::freeResult();
- }
+ $fields = CRM_Contact_DAO_Contact::fields();
// FIXME: there must be a better way
foreach (array('main', 'other') as $moniker) {
// @todo Tidy this up
$operation = 0;
if ($fieldName != 'website') {
- $operation = CRM_Utils_Array::value('operation', $migrationInfo['location_blocks'][$fieldName][$fieldCount]);
+ $operation = CRM_Utils_Array::value('operation', $migrationInfo['location'][$fieldName][$fieldCount]);
}
// default operation is overwrite.
if (!$operation) {
// Add/update location and type information from the form, if applicable
if ($locationBlocks[$name]['hasLocation']) {
- $locTypeId = CRM_Utils_Array::value('locTypeId', $migrationInfo['location_blocks'][$name][$blkCount]);
+ $locTypeId = CRM_Utils_Array::value('locTypeId', $migrationInfo['location'][$name][$blkCount]);
$otherBlockDAO->location_type_id = $locTypeId;
}
if ($locationBlocks[$name]['hasType']) {
- $typeTypeId = CRM_Utils_Array::value('typeTypeId', $migrationInfo['location_blocks'][$name][$blkCount]);
+ $typeTypeId = CRM_Utils_Array::value('typeTypeId', $migrationInfo['location'][$name][$blkCount]);
$otherBlockDAO->{$locationBlocks[$name]['hasType']} = $typeTypeId;
}
// Get main block ID
- $mainBlockId = CRM_Utils_Array::value('mainContactBlockId', $migrationInfo['location_blocks'][$name][$blkCount], 0);
+ $mainBlockId = CRM_Utils_Array::value('mainContactBlockId', $migrationInfo['location'][$name][$blkCount], 0);
// if main contact already has primary & billing, set the flags to 0.
if ($primaryDAOId) {
}
CRM_Contact_BAO_Contact::createProfileContact($submitted, CRM_Core_DAO::$_nullArray, $mainId);
- unset($submitted);
}
CRM_Utils_Hook::post('merge', 'Contact', $mainId, CRM_Core_DAO::$_nullObject);
-
- // Create activity for merge.
- $messageActivity = ts('Contact ID %1 has been merged and deleted.', array(1 => $otherId));
- civicrm_api3('activity', 'create', array(
- 'subject' => $messageActivity,
- 'source_contact_id' => CRM_Core_Session::singleton()->getLoggedInContactID(),
- 'target_contact_id' => $mainId,
- 'activity_type_id' => 'Contact Merged',
- 'status_id' => 'Completed',
- ));
+ self::createMergeActivities($mainId, $otherId);
return TRUE;
}
/**
+ * Get fields in the contact table suitable for merging.
+ *
* @return array
- * Array of field names which will be compared, so everything except ID.
+ * Array of field names to be potentially merged.
*/
public static function getContactFields() {
$contactFields = CRM_Contact_DAO_Contact::fields();
}
}
+ /**
+ * Create activities tracking the merge on affected contacts.
+ *
+ * @param int $mainId
+ * @param int $otherId
+ *
+ * @throws \CiviCRM_API3_Exception
+ */
+ public static function createMergeActivities($mainId, $otherId) {
+ $params = array(
+ 1 => $otherId,
+ 2 => $mainId,
+ );
+ $activity = civicrm_api3('activity', 'create', array(
+ '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(
+ 'subject' => ts('Contact ID %1 has been merged into Contact ID %2 and deleted.', $params),
+ 'target_contact_id' => $otherId,
+ 'activity_type_id' => 'Contact Deleted by Merge',
+ 'parent_id' => $activity['id'],
+ 'status_id' => 'Completed',
+ ));
+ }
+ }
+
}