mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Merge pull request #1782 from hamuz/develop
fix local references in upload/export disk. first step for #1727.
This commit is contained in:
commit
7cce6504e3
@ -33,7 +33,7 @@ use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CreateExport.
|
* Class CreateExport.
|
||||||
@ -136,10 +136,14 @@ class CreateExport extends Command
|
|||||||
$processor->createZipFile();
|
$processor->createZipFile();
|
||||||
$disk = Storage::disk('export');
|
$disk = Storage::disk('export');
|
||||||
$fileName = sprintf('export-%s.zip', date('Y-m-d_H-i-s'));
|
$fileName = sprintf('export-%s.zip', date('Y-m-d_H-i-s'));
|
||||||
$disk->move($job->key . '.zip', $fileName);
|
$localPath = storage_path('export') . '/' . $job->key . '.zip';
|
||||||
|
|
||||||
$this->line('The export has finished! You can find the ZIP file in this location:');
|
// "move" from local to export disk
|
||||||
$this->line(storage_path(sprintf('export/%s', $fileName)));
|
$disk->put($fileName, file_get_contents($localPath));
|
||||||
|
unlink($localPath);
|
||||||
|
|
||||||
|
$this->line('The export has finished! You can find the ZIP file in export disk with file name:');
|
||||||
|
$this->line($fileName);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ class EncryptFile extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Encrypts a file and places it in the storage/upload directory.';
|
protected $description = 'Encrypts a file and places it in the upload disk.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
|
@ -42,7 +42,7 @@ use FireflyIII\Models\TransactionJournal;
|
|||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
use Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use ZipArchive;
|
use ZipArchive;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,7 +184,7 @@ class ExpandedProcessor implements ProcessorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a ZIP file.
|
* Create a ZIP file locally (!) in storage_path('export').
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
@ -195,9 +195,9 @@ class ExpandedProcessor implements ProcessorInterface
|
|||||||
{
|
{
|
||||||
$zip = new ZipArchive;
|
$zip = new ZipArchive;
|
||||||
$file = $this->job->key . '.zip';
|
$file = $this->job->key . '.zip';
|
||||||
$fullPath = storage_path('export') . '/' . $file;
|
$localPath = storage_path('export') . '/' . $file;
|
||||||
|
|
||||||
if (true !== $zip->open($fullPath, ZipArchive::CREATE)) {
|
if (true !== $zip->open($localPath, ZipArchive::CREATE)) {
|
||||||
throw new FireflyException('Cannot store zip file.');
|
throw new FireflyException('Cannot store zip file.');
|
||||||
}
|
}
|
||||||
// for each file in the collection, add it to the zip file.
|
// for each file in the collection, add it to the zip file.
|
||||||
|
@ -26,7 +26,7 @@ namespace FireflyIII\Export\Exporter;
|
|||||||
|
|
||||||
use FireflyIII\Export\Entry\Entry;
|
use FireflyIII\Export\Entry\Entry;
|
||||||
use League\Csv\Writer;
|
use League\Csv\Writer;
|
||||||
use Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CsvExporter.
|
* Class CsvExporter.
|
||||||
@ -57,15 +57,11 @@ class CsvExporter extends BasicExporter implements ExporterInterface
|
|||||||
*/
|
*/
|
||||||
public function run(): bool
|
public function run(): bool
|
||||||
{
|
{
|
||||||
// create temporary file:
|
// choose file name:
|
||||||
$this->tempFile();
|
$this->fileName = $this->job->key . '-records.csv';
|
||||||
|
|
||||||
// necessary for CSV writer:
|
|
||||||
$fullPath = storage_path('export') . DIRECTORY_SEPARATOR . $this->fileName;
|
|
||||||
|
|
||||||
|
|
||||||
//we create the CSV into memory
|
//we create the CSV into memory
|
||||||
$writer = Writer::createFromPath($fullPath);
|
$writer = Writer::createFromString('');
|
||||||
$rows = [];
|
$rows = [];
|
||||||
|
|
||||||
// get field names for header row:
|
// get field names for header row:
|
||||||
@ -86,18 +82,9 @@ class CsvExporter extends BasicExporter implements ExporterInterface
|
|||||||
$rows[] = $line;
|
$rows[] = $line;
|
||||||
}
|
}
|
||||||
$writer->insertAll($rows);
|
$writer->insertAll($rows);
|
||||||
|
$disk = Storage::disk('export');
|
||||||
|
$disk->put($this->fileName, $writer->getContent());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Make a temp file.
|
|
||||||
*/
|
|
||||||
private function tempFile()
|
|
||||||
{
|
|
||||||
$this->fileName = $this->job->key . '-records.csv';
|
|
||||||
// touch file in export directory:
|
|
||||||
$disk = Storage::disk('export');
|
|
||||||
$disk->put($this->fileName, '');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
use Log;
|
use Log;
|
||||||
use Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,7 +94,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the file location for an attachment,
|
* Returns the file path relative to upload disk for an attachment,
|
||||||
*
|
*
|
||||||
* @param Attachment $attachment
|
* @param Attachment $attachment
|
||||||
*
|
*
|
||||||
@ -102,8 +102,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
*/
|
*/
|
||||||
public function getAttachmentLocation(Attachment $attachment): string
|
public function getAttachmentLocation(Attachment $attachment): string
|
||||||
{
|
{
|
||||||
$path = sprintf('%s%sat-%d.data', storage_path('upload'), DIRECTORY_SEPARATOR, (int)$attachment->id);
|
$path = sprintf('%sat-%d.data', DIRECTORY_SEPARATOR, (int)$attachment->id);
|
||||||
|
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ use FireflyIII\User;
|
|||||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
use Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AttachmentRepository.
|
* Class AttachmentRepository.
|
||||||
@ -66,9 +66,9 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
|||||||
/** @var AttachmentHelperInterface $helper */
|
/** @var AttachmentHelperInterface $helper */
|
||||||
$helper = app(AttachmentHelperInterface::class);
|
$helper = app(AttachmentHelperInterface::class);
|
||||||
|
|
||||||
$file = $helper->getAttachmentLocation($attachment);
|
$path = $helper->getAttachmentLocation($attachment);
|
||||||
try {
|
try {
|
||||||
unlink($file);
|
Storage::disk('upload')->delete($path);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error(sprintf('Could not delete file for attachment %d: %s', $attachment->id, $e->getMessage()));
|
Log::error(sprintf('Could not delete file for attachment %d: %s', $attachment->id, $e->getMessage()));
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@ use FireflyIII\Models\ExportJob;
|
|||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Log;
|
use Log;
|
||||||
use Storage;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ExportJobRepository.
|
* Class ExportJobRepository.
|
||||||
@ -74,15 +74,17 @@ class ExportJobRepository implements ExportJobRepositoryInterface
|
|||||||
->whereIn('status', ['never_started', 'export_status_finished', 'export_downloaded'])
|
->whereIn('status', ['never_started', 'export_status_finished', 'export_downloaded'])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
$disk = Storage::disk('export');
|
||||||
|
$files = $disk->files();
|
||||||
|
|
||||||
// loop set:
|
// loop set:
|
||||||
/** @var ExportJob $entry */
|
/** @var ExportJob $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$key = $entry->key;
|
$key = $entry->key;
|
||||||
$files = scandir(storage_path('export'), SCANDIR_SORT_NONE);
|
/** @var array $file */
|
||||||
/** @var string $file */
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if (0 === strpos($file, $key)) {
|
if (0 === strpos($file['basename'], $key)) {
|
||||||
unlink(storage_path('export') . DIRECTORY_SEPARATOR . $file);
|
$disk->delete($file['path']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -26,6 +26,7 @@ namespace FireflyIII\Services\Internal\File;
|
|||||||
use Crypt;
|
use Crypt;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use Illuminate\Contracts\Encryption\EncryptException;
|
use Illuminate\Contracts\Encryption\EncryptException;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,9 +64,8 @@ class EncryptService
|
|||||||
throw new FireflyException($message);
|
throw new FireflyException($message);
|
||||||
}
|
}
|
||||||
$newName = sprintf('%s.upload', $key);
|
$newName = sprintf('%s.upload', $key);
|
||||||
$path = storage_path('upload') . '/' . $newName;
|
$disk = Storage::disk('upload');
|
||||||
|
$disk->put($newName, $content);
|
||||||
file_put_contents($path, $content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class AttachmentHelperTest extends TestCase
|
|||||||
{
|
{
|
||||||
$attachment = Attachment::first();
|
$attachment = Attachment::first();
|
||||||
$helper = new AttachmentHelper;
|
$helper = new AttachmentHelper;
|
||||||
$path = $path = sprintf('%s%sat-%d.data', storage_path('upload'), DIRECTORY_SEPARATOR, (int)$attachment->id);
|
$path = $path = sprintf('%sat-%d.data', DIRECTORY_SEPARATOR, (int)$attachment->id);
|
||||||
$this->assertEquals($helper->getAttachmentLocation($attachment), $path);
|
$this->assertEquals($helper->getAttachmentLocation($attachment), $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user