3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class provides the functionality to Merge contacts.
21 class CRM_Contact_Form_Task_Merge
extends CRM_Contact_Form_Task
{
24 * Build all the data structures needed to build the form.
26 public function preProcess() {
30 if (is_array($this->_contactIds
)) {
31 $contactIds = array_unique($this->_contactIds
);
33 if (count($contactIds) != 2) {
34 $statusMsg = ts('Merge operation requires selecting two contacts.');
37 // do check for same contact type.
40 $sql = "SELECT contact_type FROM civicrm_contact WHERE id IN (" . implode(',', $contactIds) . ")";
41 $contact = CRM_Core_DAO
::executeQuery($sql);
42 while ($contact->fetch()) {
43 $contactTypes[$contact->contact_type
] = TRUE;
44 if (count($contactTypes) > 1) {
48 if (count($contactTypes) > 1) {
49 $statusMsg = ts('Selected records must all be the same contact type (i.e. all Individuals).');
53 CRM_Core_Error
::statusBounce($statusMsg);
56 // redirect to merge form directly.
57 $cid = $contactIds[0];
58 $oid = $contactIds[1];
60 //don't allow to delete logged in user.
61 $session = CRM_Core_Session
::singleton();
62 if ($oid == $session->get('userID')) {
64 $cid = $session->get('userID');
67 $url = CRM_Utils_System
::url('civicrm/contact/merge', "reset=1&cid={$cid}&oid={$oid}");
69 // redirect to merge page.
70 CRM_Utils_System
::redirect($url);