Skip to content

Commit

Permalink
Merge pull request #11527 from lemacarl/CRM-21524
Browse files Browse the repository at this point in the history
CRM-21524 - Fix merge contacts when one is deceased
  • Loading branch information
eileenmcnaughton authored Jan 25, 2018
2 parents bba18c7 + 6382c24 commit 56d3977
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 8 deletions.
16 changes: 8 additions & 8 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,14 @@ public static function exportComponents(
if ($exportTempTable) {
self::writeDetailsToTable($exportTempTable, $componentDetails, $sqlColumns);

// if postalMailing option is checked, exclude contacts who are deceased, have
// "Do not mail" privacy setting, or have no street address
if (isset($exportParams['postal_mailing_export']['postal_mailing_export']) &&
$exportParams['postal_mailing_export']['postal_mailing_export'] == 1
) {
self::postalMailingFormat($exportTempTable, $headerRows, $sqlColumns, $exportMode);
}

// do merge same address and merge same household processing
if ($mergeSameAddress) {
self::mergeSameAddress($exportTempTable, $headerRows, $sqlColumns, $exportParams);
Expand All @@ -1091,14 +1099,6 @@ public static function exportComponents(
self::mergeSameHousehold($exportTempTable, $headerRows, $sqlColumns, $relationKeyHOH);
}

// if postalMailing option is checked, exclude contacts who are deceased, have
// "Do not mail" privacy setting, or have no street address
if (isset($exportParams['postal_mailing_export']['postal_mailing_export']) &&
$exportParams['postal_mailing_export']['postal_mailing_export'] == 1
) {
self::postalMailingFormat($exportTempTable, $headerRows, $sqlColumns, $exportMode);
}

// call export hook
CRM_Utils_Hook::export($exportTempTable, $headerRows, $sqlColumns, $exportMode);

Expand Down
72 changes: 72 additions & 0 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,76 @@ public function testExportMasterAddress() {
CRM_Core_DAO::executeQuery($sql);
}

/**
* Test that deceased and do not mail contacts are removed from contacts before
*/
public function testExportDeceasedDoNotMail() {
$contactA = $this->callAPISuccess('contact', 'create', array(
'first_name' => 'John',
'last_name' => 'Doe',
'contact_type' => 'Individual',
));

$contactB = $this->callAPISuccess('contact', 'create', array(
'first_name' => 'Jane',
'last_name' => 'Doe',
'contact_type' => 'Individual',
'is_deceased' => 1,
));

//create address for contact A
$result = $this->callAPISuccess('address', 'create', array(
'contact_id' => $contactA['id'],
'location_type_id' => 'Home',
'street_address' => 'ABC 12',
'postal_code' => '123 AB',
'country_id' => '1152',
'city' => 'ABC',
'is_primary' => 1,
));

//create address for contact B
$result = $this->callAPISuccess('address', 'create', array(
'contact_id' => $contactB['id'],
'location_type_id' => 'Home',
'street_address' => 'ABC 12',
'postal_code' => '123 AB',
'country_id' => '1152',
'city' => 'ABC',
'is_primary' => 1,
));

//export and merge contacts with same address
list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
TRUE,
array($contactA['id'], $contactB['id']),
array(),
NULL,
NULL,
NULL,
CRM_Export_Form_Select::CONTACT_EXPORT,
"contact_a.id IN ({$contactA['id']}, {$contactB['id']})",
NULL,
TRUE,
FALSE,
array(
'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT,
'mergeOption' => TRUE,
'suppress_csv_for_testing' => TRUE,
'postal_mailing_export' => array(
'postal_mailing_export' => TRUE,
),
)
);

$greeting = CRM_Core_DAO::singleValueQuery("SELECT email_greeting FROM {$tableName}");

//Assert email_greeting is not merged
$this->assertNotContains(',', (string) $greeting);

// delete the export temp table and component table
$sql = "DROP TABLE IF EXISTS {$tableName}";
CRM_Core_DAO::executeQuery($sql);
}

}

0 comments on commit 56d3977

Please sign in to comment.