| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 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. | |
| 13 | | | |
| 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. | |
| 18 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2020 |
| 32 | * |
| 33 | * This class exists primarily for the purposes of supporting code clean up in the Merger class. |
| 34 | * |
| 35 | * It is expected to be fast-moving and calling it outside the refactoring work is not advised. |
| 36 | */ |
| 37 | class CRM_Dedupe_MergeHandler { |
| 38 | |
| 39 | /** |
| 40 | * ID of contact to be kept. |
| 41 | * |
| 42 | * @var int |
| 43 | */ |
| 44 | protected $toKeepID; |
| 45 | |
| 46 | /** |
| 47 | * ID of contact to be merged and deleted. |
| 48 | * |
| 49 | * @var int |
| 50 | */ |
| 51 | protected $toRemoveID; |
| 52 | |
| 53 | /** |
| 54 | * @return mixed |
| 55 | */ |
| 56 | public function getToKeepID() { |
| 57 | return $this->toKeepID; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @param mixed $toKeepID |
| 62 | */ |
| 63 | public function setToKeepID($toKeepID) { |
| 64 | $this->toKeepID = $toKeepID; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @return mixed |
| 69 | */ |
| 70 | public function getToRemoveID() { |
| 71 | return $this->toRemoveID; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @param mixed $toRemoveID |
| 76 | */ |
| 77 | public function setToRemoveID($toRemoveID) { |
| 78 | $this->toRemoveID = $toRemoveID; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * CRM_Dedupe_MergeHandler constructor. |
| 83 | * |
| 84 | * @param int $toKeepID |
| 85 | * ID of contact to be kept. |
| 86 | * @param int $toRemoveID |
| 87 | * ID of contact to be removed. |
| 88 | */ |
| 89 | public function __construct(int $toKeepID, int $toRemoveID) { |
| 90 | $this->setToKeepID($toKeepID); |
| 91 | $this->setToRemoveID($toRemoveID); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Get an array of tables that relate to the contact entity and will need consideration in a merge. |
| 96 | * |
| 97 | * The list of potential tables is filtered by tables which have data for the relevant contacts. |
| 98 | */ |
| 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)) |
| 106 | ) { |
| 107 | unset($relTables[$name]); |
| 108 | } |
| 109 | } |
| 110 | return $relTables; |
| 111 | } |
| 112 | |
| 113 | } |