Skip to content

Commit

Permalink
further dedupe works and bugifixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chastell committed Jun 14, 2007
1 parent f83b967 commit b74e4bb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
16 changes: 14 additions & 2 deletions CRM/Admin/Form/DedupeFind.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ class CRM_Admin_Form_DedupeFind extends CRM_Admin_Form
*/
function preProcess()
{
// FIXME: move this to CRM_Dedupe_BAO_RuleGroup::getCriteriaArray()
// FIXME: move the civicrm_dedupe_rule* operations
// to CRM_Dedupe_BAO_RuleGroup::getCriteriaArray()
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, false, 0);
$gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, false, 0);
$rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, false, 0);
$rgDao =& new CRM_Dedupe_DAO_RuleGroup();
$rgDao->id = $rgid;
Expand All @@ -73,7 +75,11 @@ function preProcess()
);
}

$foundDupes = CRM_Dedupe_Finder::findDupes($search, $rgDao->threshold, $rgDao->contact_type);
if ($gid) {
$foundDupes = CRM_Dedupe_Finder::findDupesInGroup($gid, $search, $rgDao->threshold, $rgDao->contact_type);
} else {
$foundDupes = CRM_Dedupe_Finder::findDupes($search, $rgDao->threshold, $rgDao->contact_type);
}
if (!$foundDupes) {
$this->assign('no_dupes', true);
return;
Expand Down Expand Up @@ -107,6 +113,7 @@ function preProcess()
$dupeContacts[$mainId] = $localDupes;
}
if ($cid) $this->_cid = $cid;
if ($gid) $this->_gid = $gid;
$this->_rgid = $rgid;
$this->_mainContacts = $mainContacts;
$this->_dupeContacts = $dupeContacts;
Expand All @@ -123,11 +130,16 @@ public function buildQuickForm()
$this->assign('main_contacts', $this->_mainContacts);
$this->assign('dupe_contacts', $this->_dupeContacts);
if ($this->_cid) $this->assign('cid', $this->_cid);
if ($this->_gid) $this->assign('gid', $this->_gid);
$this->assign('rgid', $this->_rgid);
}

function setDefaultValues()
{
if ($this->_cid) {
$session =& CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/dedupefind', "reset=1&action=update&rgid={$this->_rgid}&gid={$this->_gid}&cid={$this->_cid}"));
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static function memberCount( $id, $status = 'Added' ) {
* @static
*/
static function getMember ($lngGroupId) {
require_once 'CRM/Contact/DAO/GroupContact.php';
$groupContact =& new CRM_Contact_DAO_GroupContact( );

$strSql = "SELECT civicrm_contact.id as contact_id, civicrm_contact.sort_name as name
Expand All @@ -162,6 +163,7 @@ static function getMember ($lngGroupId) {

$groupContact->query($strSql);

$aMembers = array();
while ($groupContact->fetch()) {
$aMembers[$groupContact->contact_id] = $groupContact->name;
}
Expand Down
1 change: 1 addition & 0 deletions CRM/Contact/Form/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ function addRules()

public function buildQuickForm()
{
CRM_Utils_System::setTitle(ts('Merge Contacts'));
$this->addButtons(array(
array('type' => 'next', 'name' => ts('Merge'), 'isDefault' => true),
array('type' => 'cancel', 'name' => ts('Cancel')),
Expand Down
8 changes: 2 additions & 6 deletions CRM/Dedupe/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ function findDupesInGroup($gid, $params, $threshold, $contactType = null)
// for each contact_id find its dupes, but
// intersect the result with this group's contacts
foreach ($members as $cid) {
if (!$contactType or $dao->contact_type == $contactType) {
$dupes[$cid] = array_intersect(self::findDupesOfContact($cid, $params, $threshold, $contactType), $members);
}
$dupes[$cid] = array_intersect(self::findDupesOfContact($cid, $params, $threshold, $contactType), $members);
}
// return dropping empty matches
return array_filter($dupes);
Expand All @@ -118,9 +116,7 @@ function findDupes($params, $threshold, $contactType = null)
$dao->domain_id = CRM_Core_Config::domainID();
$dao->find();
while ($dao->fetch()) {
if (!$contactType or $dao->contact_type == $contactType) {
$dupes[$dao->id] = self::findDupesOfContact($dao->id, $params, $threshold, $contactType);
}
$dupes[$dao->id] = self::findDupesOfContact($dao->id, $params, $threshold, $contactType);
}
// return dropping empty matches
return array_filter($dupes);
Expand Down
8 changes: 6 additions & 2 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,19 @@ function moveContactBelongings($mainId, $otherId, $tables = false)
$mainId = (int) $mainId;
$otherId = (int) $otherId;

// use UPDATE IGNORE + DELETE query pair to skip on situations when
// there's a UNIQUE restriction on ($field, some_other_field) pair
foreach ($affected as $table) {
if (isset($cidRefs[$table])) {
foreach ($cidRefs[$table] as $field) {
$sqls[] = "UPDATE $table SET $field = $mainId WHERE $field = $otherId";
$sqls[] = "UPDATE IGNORE $table SET $field = $mainId WHERE $field = $otherId";
$sqls[] = "DELETE FROM $table WHERE $field = $otherId";
}
}
if (isset($eidRefs[$table])) {
foreach ($eidRefs[$table] as $entityTable => $entityId) {
$sqls[] = "UPDATE $table SET $entityId = $mainId WHERE $entityId = $otherId AND $entityTable = 'civicrm_contact'";
$sqls[] = "UPDATE IGNORE $table SET $entityId = $mainId WHERE $entityId = $otherId AND $entityTable = 'civicrm_contact'";
$sqls[] = "DELETE FROM $table WHERE $entityId = $otherId AND $entityTable = 'civicrm_contact'";
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions templates/CRM/Admin/Form/DedupeFind.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<table style="width: 45%; float: left; margin: 10px;">
<tr class="columnheader"><th colspan="2">{ts}Potentially Duplicate Contacts{/ts}</th></tr>
{foreach from=$main_contacts item=main_name key=main_id}
{capture assign=link}<a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=$main_id"}">{$main_name}</a>{/capture}
{capture assign=select}<a href="{crmURL p='civicrm/admin/dedupefind' q="reset=1&action=update&rgid=$rgid&cid=$main_id"}">{ts}select{/ts}</a>{/capture}
{capture assign=link}<a href="{crmURL p='civicrm/contact/view' q="reset=1&gid=$gid&cid=$main_id"}">{$main_name}</a>{/capture}
{capture assign=select}<a href="{crmURL p='civicrm/admin/dedupefind' q="reset=1&action=update&rgid=$rgid&gid=$gid&cid=$main_id"}">{ts}select{/ts}</a>{/capture}
{if $cid and $cid == $main_id}
<tr class="columnheader"><td>{$main_name}</td><td style="text-align: right;">→</td></tr>
{else}
Expand Down

0 comments on commit b74e4bb

Please sign in to comment.