-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REF] refactor on nasty Dedupe function
I found with other pieces of refactoring static functions that creating a class to support the refactor made it much easier as that way I could leverage the fact thatt classes have properties and get away from the crazy param passing that characterizes a nest of static functions. This adds a class for that purpose and moves a small chunk of code handling into the class. The goal is to move the handling is done purely for the form back onto the form....
- Loading branch information
1 parent
33c3ad9
commit 9287a0b
Showing
2 changed files
with
115 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 5 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2020 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM is distributed in the hope that it will be useful, but | | ||
| WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | ||
| See the GNU Affero General Public License for more details. | | ||
| | | ||
| You should have received a copy of the GNU Affero General Public | | ||
| License and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC (c) 2004-2020 | ||
* | ||
* This class exists primarily for the purposes of supporting code clean up in the Merger class. | ||
* | ||
* It is expected to be fast-moving and calling it outside the refactoring work is not advised. | ||
*/ | ||
class CRM_Dedupe_MergeHandler { | ||
|
||
/** | ||
* ID of contact to be kept. | ||
* | ||
* @var int | ||
*/ | ||
protected $toKeepID; | ||
|
||
/** | ||
* ID of contact to be merged and deleted. | ||
* | ||
* @var int | ||
*/ | ||
protected $toRemoveID; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getToKeepID() { | ||
return $this->toKeepID; | ||
} | ||
|
||
/** | ||
* @param mixed $toKeepID | ||
*/ | ||
public function setToKeepID($toKeepID) { | ||
$this->toKeepID = $toKeepID; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getToRemoveID() { | ||
return $this->toRemoveID; | ||
} | ||
|
||
/** | ||
* @param mixed $toRemoveID | ||
*/ | ||
public function setToRemoveID($toRemoveID) { | ||
$this->toRemoveID = $toRemoveID; | ||
} | ||
|
||
/** | ||
* CRM_Dedupe_MergeHandler constructor. | ||
* | ||
* @param int $toKeepID | ||
* ID of contact to be kept. | ||
* @param int $toRemoveID | ||
* ID of contact to be removed. | ||
*/ | ||
public function __construct(int $toKeepID, int $toRemoveID) { | ||
$this->setToKeepID($toKeepID); | ||
$this->setToRemoveID($toRemoveID); | ||
} | ||
|
||
/** | ||
* Get an array of tables that relate to the contact entity and will need consideration in a merge. | ||
* | ||
* The list of potential tables is filtered by tables which have data for the relevant contacts. | ||
*/ | ||
public function getTablesRelatedToTheMergePair() { | ||
$relTables = CRM_Dedupe_Merger::relTables(); | ||
$activeRelTables = CRM_Dedupe_Merger::getActiveRelTables($this->toRemoveID); | ||
$activeMainRelTables = CRM_Dedupe_Merger::getActiveRelTables($this->toKeepID); | ||
foreach ($relTables as $name => $null) { | ||
if (!in_array($name, $activeRelTables, TRUE) && | ||
!(($name === 'rel_table_users') && in_array($name, $activeMainRelTables, TRUE)) | ||
) { | ||
unset($relTables[$name]); | ||
} | ||
} | ||
return $relTables; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters