Skip to content
Snippets Groups Projects
Unverified Commit 46876bd3 authored by Seamus Lee's avatar Seamus Lee Committed by GitHub
Browse files

Merge pull request #19268 from seamuslee001/dev_core_2272

#2272 Fix a DB error when merging contacts into the same hous…
parents e999d7be 6137fac4
No related branches found
No related tags found
No related merge requests found
......@@ -438,7 +438,11 @@ VALUES $sqlValueString
$relationshipJoin = $relationshipClause = '';
if (!$selectAll && $componentTable) {
$relationshipJoin = " INNER JOIN {$componentTable} ctTable ON ctTable.contact_id = {$contactA}";
$field = 'contact_id';
if ($componentTable === 'civicrm_contact') {
$field = 'id';
}
$relationshipJoin = " INNER JOIN {$componentTable} ctTable ON ctTable.$field = {$contactA}";
}
elseif (!empty($relIDs)) {
$relID = implode(',', $relIDs);
......
......@@ -664,6 +664,40 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
$this->assertEquals('household sauce', $row['Contact Source']);
}
/**
* Test exporting contacts merged into households
*
* This is to ensure that dev/core#2272 remains fixed.
*
* @dataProvider getBooleanDataProvider
*
* @param bool $includeHouseHold
*
* @throws CRM_Core_Exception
* @throws \League\Csv\Exception
*/
public function testExportMergeToHousehold($includeHouseHold) {
list($householdID, $houseHoldTypeID) = $this->setUpHousehold();
if ($includeHouseHold) {
$this->contactIDs[] = $householdID;
}
$selectedFields = [
['contact_type' => 'Individual', 'name' => 'contact_source', 'location_type_id' => ''],
];
$this->doExportTest([
'ids' => $this->contactIDs,
'fields' => $selectedFields,
'mergeSameHousehold' => TRUE,
'componentTable' => 'civicrm_contact',
'componentClause' => 'contact_a.id IN (' . implode(',', $this->contactIDs) . ')',
]);
$row = $this->csv->fetchOne();
$this->assertCount(1, $this->csv);
$this->assertEquals($householdID, $row['Household ID']);
}
/**
* Test exporting relationships.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment