Merge pull request #14987 from civicrm/5.16
[civicrm-core.git] / CRM / Export / BAO / Export.php
index 87aba60b69318f39d528d967ca4e2d6443dad2ed..b7f06d505bcda77850a1fdbaef2ed4e1ab05a46c 100644 (file)
@@ -160,7 +160,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,22 +205,14 @@ 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, $sqlColumns, $processor);
+        $processor->writeCSVFromTable();
       }
       else {
         // return tableName sqlColumns headerRows in test context
-        return [$processor->getTemporaryTable(), $sqlColumns, $headerRows, $processor];
+        return [$processor->getTemporaryTable(), $sqlColumns, $processor->getHeaderRows(), $processor];
       }
 
       // delete the export temp table and component table
@@ -373,50 +364,6 @@ VALUES $sqlValueString
     CRM_Core_DAO::executeQuery($sql);
   }
 
-  /**
-   * @param $headerRows
-   * @param $sqlColumns
-   * @param \CRM_Export_BAO_ExportProcessor $processor
-   */
-  public static function writeCSVFromTable($headerRows, $sqlColumns, $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.
    *