Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Use export disk for zip file.
James Cole08b4c9ea5cf7
diff --git a/app/Export/Exporter/CsvExporter.php b/app/Export/Exporter/CsvExporter.phpindex 9a8d414a06..f0d2675cf8 100644--- a/app/Export/Exporter/CsvExporter.php+++ b/app/Export/Exporter/CsvExporter.php@@ -14,6 +14,7 @@ use FireflyIII\Export\Entry;use FireflyIII\Models\ExportJob;use League\Csv\Writer;use SplFileObject;+use Storage;/*** Class CsvExporter@@ -25,9 +26,6 @@ class CsvExporter extends BasicExporter implements ExporterInterface/** @var string */private $fileName;- /** @var resource */- private $handler;-/*** CsvExporter constructor.*@@ -36,6 +34,7 @@ class CsvExporter extends BasicExporter implements ExporterInterfacepublic function __construct(ExportJob $job){parent::__construct($job);+}/**@@ -54,9 +53,11 @@ class CsvExporter extends BasicExporter implements ExporterInterface// create temporary file:$this->tempFile();+ // necessary for CSV writer:+ $fullPath = storage_path('export') . DIRECTORY_SEPARATOR . $this->fileName;+// create CSV writer:- $writer = Writer::createFromPath(new SplFileObject($this->fileName, 'a+'), 'w');- //the $writer object open mode will be 'w'!!+ $writer = Writer::createFromPath(new SplFileObject($fullPath, 'a+'), 'w');// all rows:$rows = [];@@ -76,8 +77,6 @@ class CsvExporter extends BasicExporter implements ExporterInterfaceprivate function tempFile(){- $fileName = $this->job->key . '-records.csv';- $this->fileName = storage_path('export') . DIRECTORY_SEPARATOR . $fileName;- $this->handler = fopen($this->fileName, 'w');+ $this->fileName = $this->job->key . '-records.csv';}}diff --git a/app/Export/Processor.php b/app/Export/Processor.phpindex 21370039d8..5681a2aca9 100644--- a/app/Export/Processor.php+++ b/app/Export/Processor.php@@ -12,12 +12,12 @@ namespace FireflyIII\Export;use Auth;use Config;-use ErrorException;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Models\ExportJob;use FireflyIII\Models\TransactionJournal;use Illuminate\Support\Collection;use Log;+use Storage;use ZipArchive;/**@@ -130,33 +130,30 @@ class Processorpublic function createZipFile(){$zip = new ZipArchive;- $filename = storage_path('export') . DIRECTORY_SEPARATOR . $this->job->key . '.zip';- Log::debug('Will create zip file at ' . $filename);+ $file = $this->job->key . '.zip';+ $fullPath = storage_path('export') . '/' . $file;+ Log::debug('Will create zip file at ' . $fullPath);- if ($zip->open($filename, ZipArchive::CREATE) !== true) {+ if ($zip->open($fullPath, ZipArchive::CREATE) !== true) {throw new FireflyException('Cannot store zip file.');}// for each file in the collection, add it to the zip file.- $search = storage_path('export') . DIRECTORY_SEPARATOR . $this->job->key . '-';- /** @var string $file */- foreach ($this->getFiles() as $file) {- Log::debug('Will add "' . $file . '" to zip file.');- $zipName = str_replace($search, '', $file);- $result = $zip->addFile($file, $zipName);+ $disk = Storage::disk('export');+ foreach ($this->getFiles() as $entry) {+ // is part of this job?+ $zipFileName = str_replace($this->job->key . '-', '', $entry);+ $result = $zip->addFromString($zipFileName, $disk->get($entry));if (!$result) {- Log::error('Could not add "' . $file . '" into zip file as "' . $zipName . '".');+ Log::error('Could not add "' . $entry . '" into zip file as "' . $zipFileName . '".');}}+$zip->close();// delete the files:foreach ($this->getFiles() as $file) {Log::debug('Will now delete file "' . $file . '".');- try {- unlink($file);- } catch (ErrorException $e) {- Log::error('Cannot unlink file "' . $file . '" because: ' . $e->getMessage());- }+ $disk->delete($file);}Log::debug('Done!');}