Move temp table creation to the processor
authoreileen <emcnaughton@wikimedia.org>
Tue, 16 Jul 2019 23:01:45 +0000 (11:01 +1200)
committereileen <emcnaughton@wikimedia.org>
Sun, 21 Jul 2019 21:21:06 +0000 (09:21 +1200)
CRM/Export/BAO/Export.php
CRM/Export/BAO/ExportProcessor.php

index 6b5fdf29468f8c8217d29de2840ed5338e686718..e0f42e913a62abc30254c32b40b062554a0b5513 100644 (file)
@@ -196,7 +196,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
 
     $headerRows = $processor->getHeaderRows();
     $sqlColumns = $processor->getSQLColumns();
-    $processor->setTemporaryTable(self::createTempTable($sqlColumns));
+    $processor->createTempTable();
     $limitReached = FALSE;
 
     while (!$limitReached) {
@@ -408,44 +408,6 @@ VALUES $sqlValueString
     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
index 50f45f7870f7b03eb8c681bb78b7983abddb2f24..242dc689845c3632eb066b7dca3bdcb7ed6b4b5a 100644 (file)
@@ -2167,4 +2167,40 @@ WHERE  id IN ( $deleteIDString )
     }
   }
 
+  /**
+   * 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());
+  }
+
 }