Always create temp table at the start.
authoreileen <emcnaughton@wikimedia.org>
Thu, 15 Nov 2018 23:31:39 +0000 (12:31 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 15 Nov 2018 23:41:57 +0000 (12:41 +1300)
The saving of not creating an empty file occassionally doesn't warrant the code complexity

CRM/Export/BAO/Export.php

index 5699194a4ac5970da5c9e2d5fb1f57c9fb866f8b..d7103de352d6699b67af6bb1a2bc7506f1d61724 100644 (file)
@@ -235,8 +235,6 @@ class CRM_Export_BAO_Export {
     $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
     self::$relationshipTypes = $processor->getRelationshipTypes();
 
-    $queryMode = $processor->getQueryMode();
-
     if ($fields) {
       foreach ($fields as $key => $value) {
         $fieldName = CRM_Utils_Array::value(1, $value);
@@ -445,7 +443,6 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
     }
 
     $componentDetails = array();
-    $setHeader = TRUE;
 
     $rowCount = self::EXPORT_ROW_COUNT;
     $offset = 0;
@@ -469,7 +466,9 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
       }
     }
 
+    $exportTempTable = self::createTempTable($sqlColumns);
     $limitReached = FALSE;
+
     while (!$limitReached) {
       $limitQuery = "{$queryString} LIMIT {$offset}, {$rowCount}";
       $iterationDAO = CRM_Core_DAO::executeQuery($limitQuery);
@@ -533,13 +532,6 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
           }
         }
 
-        if ($setHeader) {
-          $exportTempTable = self::createTempTable($sqlColumns);
-        }
-
-        //build header only once
-        $setHeader = FALSE;
-
         // If specific payment fields have been selected for export, payment
         // data will already be in $row. Otherwise, add payment related
         // information, if appropriate.