From 46f0dec140b2f8397cba6b789e36e4d09bd870c7 Mon Sep 17 00:00:00 2001
From: Dan Chadwick <dan899@gmail.com>
Date: Fri, 31 Oct 2014 17:01:34 -0400
Subject: [PATCH] Issue #2221651 by gdl: Added Make temporary export file path
 configurable.

---
 includes/exporters/webform_exporter_excel_xlsx.inc |    2 +-
 includes/webform.report.inc                        |   11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/includes/exporters/webform_exporter_excel_xlsx.inc b/includes/exporters/webform_exporter_excel_xlsx.inc
index 0ec280f..9a5b676 100644
--- a/includes/exporters/webform_exporter_excel_xlsx.inc
+++ b/includes/exporters/webform_exporter_excel_xlsx.inc
@@ -132,7 +132,7 @@ class webform_exporter_excel_xlsx extends webform_exporter {
     // Our download file is currently a single XML sheet file. We need to add
     // the peripheral XML files to make this into a XLSX directory, then zip it.
     $file_uri = $results['file_name'];
-    $zip_uri = drupal_tempnam('temporary://', 'webform_');
+    $zip_uri = _webform_export_tempname();
 
     // ZipArchive does not support stream wrappers, convert to filesystem path.
     $zip_filepath = drupal_realpath($zip_uri);
diff --git a/includes/webform.report.inc b/includes/webform.report.inc
index 92a8a5d..6d67796 100644
--- a/includes/webform.report.inc
+++ b/includes/webform.report.inc
@@ -700,7 +700,7 @@ function webform_results_download_form_submit(&$form, &$form_state) {
     $options['range']['batch_size'] = $batch_size;
   }
 
-  $options['file_name'] = drupal_tempnam('temporary://', 'webform_');
+  $options['file_name'] = _webform_export_tempname();
 
   // Set up a batch to export the results.
   $batch = webform_results_export_batch($node, $format, $options);
@@ -708,6 +708,13 @@ function webform_results_download_form_submit(&$form, &$form_state) {
 }
 
 /**
+ * Returns a temporary export filename.
+ */
+function _webform_export_tempname() {
+  return drupal_tempnam(variable_get('webform_export_path', 'temporary://'), 'webform_');
+}
+
+/**
  * Generate a Excel-readable CSV file containing all submissions for a Webform.
  *
  * Note that this function is generally no longer utilized. Instead Batch API
@@ -730,7 +737,7 @@ function webform_results_export($node, $format = 'delimited', $options = array()
   // Open a new Webform exporter object.
   $exporter = webform_export_create_handler($format, $options);
 
-  $file_name = drupal_tempnam('temporary://', 'webform_');
+  $file_name = _webform_export_tempname();
   $handle = fopen($file_name, 'w');
   if (!$handle) {
     return;
-- 
1.7.8.msysgit.0

