diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 6b5fdf29468f..e0f42e913a62 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -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) { @@ -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 diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 50f45f7870f7..242dc689845c 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -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()); + } + }