Replace CRM_Utils_Array::value with ?? in variable assignments
[civicrm-core.git] / CRM / Contact / Form / Task / Merge.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
7f82e636 19 * This class provides the functionality to Merge contacts.
6a488035
TO
20 */
21class CRM_Contact_Form_Task_Merge extends CRM_Contact_Form_Task {
22
23 /**
fe482240 24 * Build all the data structures needed to build the form.
6a488035 25 */
00be9182 26 public function preProcess() {
6a488035
TO
27 parent::preProcess();
28 $statusMsg = NULL;
be2fb01f 29 $contactIds = [];
6a488035
TO
30 if (is_array($this->_contactIds)) {
31 $contactIds = array_unique($this->_contactIds);
32 }
33 if (count($contactIds) != 2) {
34 $statusMsg = ts('Merge operation requires selecting two contacts.');
35 }
36
37 // do check for same contact type.
be2fb01f 38 $contactTypes = [];
6a488035
TO
39 if (!$statusMsg) {
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;
8d7a9d07 44 if (count($contactTypes) > 1) {
353ffa53 45 break;
8d7a9d07 46 }
6a488035
TO
47 }
48 if (count($contactTypes) > 1) {
49 $statusMsg = ts('Selected records must all be the same contact type (i.e. all Individuals).');
50 }
51 }
52 if ($statusMsg) {
53 CRM_Core_Error::statusBounce($statusMsg);
54 }
55
56 // redirect to merge form directly.
57 $cid = $contactIds[0];
58 $oid = $contactIds[1];
59
60 //don't allow to delete logged in user.
61 $session = CRM_Core_Session::singleton();
62 if ($oid == $session->get('userID')) {
63 $oid = $cid;
64 $cid = $session->get('userID');
65 }
66
67 $url = CRM_Utils_System::url('civicrm/contact/merge', "reset=1&cid={$cid}&oid={$oid}");
68
69 // redirect to merge page.
70 CRM_Utils_System::redirect($url);
71 }
96025800 72
6a488035 73}