Skip to content

Commit

Permalink
Merge pull request #14851 from eileenmcnaughton/tt
Browse files Browse the repository at this point in the history
[REF] [Export] Move temp table creation function to the processor
  • Loading branch information
colemanw authored Jul 22, 2019
2 parents 1543231 + 3e64443 commit ff49984
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
40 changes: 1 addition & 39 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static function exportComponents(

$headerRows = $processor->getHeaderRows();
$sqlColumns = $processor->getSQLColumns();
$processor->setTemporaryTable(self::createTempTable($sqlColumns));
$processor->createTempTable();
$limitReached = FALSE;

while (!$limitReached) {
Expand Down Expand Up @@ -408,44 +408,6 @@ public static function writeDetailsToTable($processor, $details, $sqlColumns) {
CRM_Core_DAO::executeQuery($sql);
}

/**
* @param $sqlColumns
*
* @return string
*/
public static function createTempTable($sqlColumns) {
//creating a temporary table for the search result that need be exported
$exportTempTable = CRM_Utils_SQL_TempTable::build()->setDurable()->setCategory('export');

// also create the sql table
$exportTempTable->drop();

$sql = " id int unsigned NOT NULL AUTO_INCREMENT, ";
if (!empty($sqlColumns)) {
$sql .= implode(",\n", array_values($sqlColumns)) . ',';
}

$sql .= "\n PRIMARY KEY ( id )";

// add indexes for street_address and household_name if present
$addIndices = [
'street_address',
'household_name',
'civicrm_primary_id',
];

foreach ($addIndices as $index) {
if (isset($sqlColumns[$index])) {
$sql .= ",
INDEX index_{$index}( $index )
";
}
}

$exportTempTable->createWithColumns($sql);
return $exportTempTable->getName();
}

/**
* @param $headerRows
* @param $sqlColumns
Expand Down
36 changes: 36 additions & 0 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2167,4 +2167,40 @@ protected function setGreetingStringsForSameAddressMerge($formValues) {
}
}

/**
* Create the temporary table for output.
*/
public function createTempTable() {
//creating a temporary table for the search result that need be exported
$exportTempTable = CRM_Utils_SQL_TempTable::build()->setDurable()->setCategory('export');
$sqlColumns = $this->getSQLColumns();
// also create the sql table
$exportTempTable->drop();

$sql = " id int unsigned NOT NULL AUTO_INCREMENT, ";
if (!empty($sqlColumns)) {
$sql .= implode(",\n", array_values($sqlColumns)) . ',';
}

$sql .= "\n PRIMARY KEY ( id )";

// add indexes for street_address and household_name if present
$addIndices = [
'street_address',
'household_name',
'civicrm_primary_id',
];

foreach ($addIndices as $index) {
if (isset($sqlColumns[$index])) {
$sql .= ",
INDEX index_{$index}( $index )
";
}
}

$exportTempTable->createWithColumns($sql);
$this->setTemporaryTable($exportTempTable->getName());
}

}

0 comments on commit ff49984

Please sign in to comment.