3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2020
33 * This class exists primarily for the purposes of supporting code clean up in the Merger class.
35 * It is expected to be fast-moving and calling it outside the refactoring work is not advised.
37 class CRM_Dedupe_MergeHandler
{
40 * ID of contact to be kept.
47 * ID of contact to be merged and deleted.
51 protected $toRemoveID;
56 public function getToKeepID() {
57 return $this->toKeepID
;
61 * @param mixed $toKeepID
63 public function setToKeepID($toKeepID) {
64 $this->toKeepID
= $toKeepID;
70 public function getToRemoveID() {
71 return $this->toRemoveID
;
75 * @param mixed $toRemoveID
77 public function setToRemoveID($toRemoveID) {
78 $this->toRemoveID
= $toRemoveID;
82 * CRM_Dedupe_MergeHandler constructor.
84 * @param int $toKeepID
85 * ID of contact to be kept.
86 * @param int $toRemoveID
87 * ID of contact to be removed.
89 public function __construct(int $toKeepID, int $toRemoveID) {
90 $this->setToKeepID($toKeepID);
91 $this->setToRemoveID($toRemoveID);
95 * Get an array of tables that relate to the contact entity and will need consideration in a merge.
97 * The list of potential tables is filtered by tables which have data for the relevant contacts.
99 public function getTablesRelatedToTheMergePair() {
100 $relTables = CRM_Dedupe_Merger
::relTables();
101 $activeRelTables = CRM_Dedupe_Merger
::getActiveRelTables($this->toRemoveID
);
102 $activeMainRelTables = CRM_Dedupe_Merger
::getActiveRelTables($this->toKeepID
);
103 foreach ($relTables as $name => $null) {
104 if (!in_array($name, $activeRelTables, TRUE) &&
105 !(($name === 'rel_table_users') && in_array($name, $activeMainRelTables, TRUE))
107 unset($relTables[$name]);