X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FExport%2FBAO%2FExport.php;h=1541cb9e8eca698f46805ad3cf27aad6134fb435;hb=6b5dfd14377463ae9a2cce380113be72cdbd00e8;hp=d8c1ea0f54d1eb5a5fc2ba6009570a28796791d7;hpb=2dbf8245a4ed9350c6e898c58e237de9f160f4bd;p=civicrm-core.git diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index d8c1ea0f54..1541cb9e8e 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -70,9 +70,6 @@ class CRM_Export_BAO_Export { * @param array $exportParams * @param string $queryOperator * - * @return array|null - * An array can be requested from within a unit test. - * * @throws \CRM_Core_Exception */ public static function exportComponents( @@ -118,6 +115,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c } $processor->setComponentTable($componentTable); $processor->setComponentClause($componentClause); + $processor->setIds($ids); list($query, $queryString) = $processor->runQuery($params, $order); @@ -130,6 +128,9 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c if ($processor->isMergeSameAddress()) { foreach (array_keys($processor->getAdditionalFieldsForSameAddressMerge()) as $field) { + if ($field === 'id') { + $field = 'civicrm_primary_id'; + } $processor->setColumnAsCalculationOnly($field); } } @@ -160,7 +161,6 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c $count = -1; - $headerRows = $processor->getHeaderRows(); $sqlColumns = $processor->getSQLColumns(); $processor->createTempTable(); $limitReached = FALSE; @@ -206,23 +206,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c $processor->mergeSameAddress(); } - // call export hook - $table = $processor->getTemporaryTable(); - CRM_Utils_Hook::export($table, $headerRows, $sqlColumns, $exportMode, $componentTable, $ids); - if ($table !== $processor->getTemporaryTable()) { - CRM_Core_Error::deprecatedFunctionWarning('altering the export table in the hook is deprecated (in some flows the table itself will be)'); - $processor->setTemporaryTable($table); - } - - // In order to be able to write a unit test against this function we need to suppress - // the csv writing. In future hopefully the csv writing & the main processing will be in separate functions. - if (empty($exportParams['suppress_csv_for_testing'])) { - self::writeCSVFromTable($headerRows, $processor); - } - else { - // return tableName sqlColumns headerRows in test context - return [$processor->getTemporaryTable(), $sqlColumns, $headerRows, $processor]; - } + $processor->writeCSVFromTable(); // delete the export temp table and component table $sql = "DROP TABLE IF EXISTS " . $processor->getTemporaryTable(); @@ -373,49 +357,6 @@ VALUES $sqlValueString CRM_Core_DAO::executeQuery($sql); } - /** - * @param $headerRows - * @param \CRM_Export_BAO_ExportProcessor $processor - */ - public static function writeCSVFromTable($headerRows, $processor) { - $exportTempTable = $processor->getTemporaryTable(); - $writeHeader = TRUE; - $offset = 0; - $limit = self::EXPORT_ROW_COUNT; - - $query = "SELECT * FROM $exportTempTable"; - - while (1) { - $limitQuery = $query . " -LIMIT $offset, $limit -"; - $dao = CRM_Core_DAO::executeQuery($limitQuery); - - if ($dao->N <= 0) { - break; - } - - $componentDetails = []; - while ($dao->fetch()) { - $row = []; - - foreach (array_keys($processor->getSQLColumns()) as $column) { - $row[$column] = $dao->$column; - } - $componentDetails[] = $row; - } - CRM_Core_Report_Excel::writeCSVFile($processor->getExportFileName(), - $headerRows, - $componentDetails, - NULL, - $writeHeader - ); - - $writeHeader = FALSE; - $offset += $limit; - } - } - /** * Get the ids that we want to get related contact details for. *