mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some enhancements to export.
This commit is contained in:
parent
e478238d77
commit
9a1710eb27
@ -10,10 +10,13 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Export\Collector;
|
||||
|
||||
use Amount;
|
||||
use Auth;
|
||||
use Crypt;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\ExportJob;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@ -23,6 +26,9 @@ use Log;
|
||||
*/
|
||||
class AttachmentCollector extends BasicCollector implements CollectorInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $explanationString = '';
|
||||
|
||||
/**
|
||||
* AttachmentCollector constructor.
|
||||
*
|
||||
@ -48,12 +54,39 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface
|
||||
$originalFile = storage_path('upload') . DIRECTORY_SEPARATOR . 'at-' . $attachment->id . '.data';
|
||||
if (file_exists($originalFile)) {
|
||||
Log::debug('Stored 1 attachment');
|
||||
$decrypted = Crypt::decrypt(file_get_contents($originalFile));
|
||||
$newFile = storage_path('export') . DIRECTORY_SEPARATOR . $this->job->key . '-Attachment nr. ' . $attachment->id . ' - '
|
||||
. $attachment->filename;
|
||||
file_put_contents($newFile, $decrypted);
|
||||
$this->getFiles()->push($newFile);
|
||||
try {
|
||||
$decrypted = Crypt::decrypt(file_get_contents($originalFile));
|
||||
$newFile = storage_path('export') . DIRECTORY_SEPARATOR . $this->job->key . '-Attachment nr. ' . $attachment->id . ' - '
|
||||
. $attachment->filename;
|
||||
file_put_contents($newFile, $decrypted);
|
||||
$this->getFiles()->push($newFile);
|
||||
|
||||
// explain:
|
||||
$this->explain($attachment);
|
||||
} catch (DecryptException $e) {
|
||||
Log::error('Catchable error: could not decrypt attachment #' . $attachment->id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// put the explanation string in a file and attach it as well.
|
||||
$explanationFile = storage_path('export') . DIRECTORY_SEPARATOR . $this->job->key . '-Source of all your attachments explained.txt';
|
||||
file_put_contents($explanationFile, $this->explanationString);
|
||||
$this->getFiles()->push($explanationFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*/
|
||||
private function explain(Attachment $attachment)
|
||||
{
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $attachment->attachable;
|
||||
$string = 'Attachment #' . $attachment->id . ' is part of ' . strtolower($journal->transactionType->type) . ' #' . $journal->id
|
||||
. ', with description "' . $journal->description . '". This transaction was for ' . Amount::formatJournal($journal, false) .
|
||||
' and occured on ' . $journal->date->formatLocalized(config('config.month_and_day')) . "\n\n";
|
||||
$this->explanationString .= $string;
|
||||
|
||||
}
|
||||
}
|
@ -13,7 +13,8 @@ namespace FireflyIII\Export\Collector;
|
||||
use Auth;
|
||||
use Crypt;
|
||||
use FireflyIII\Models\ExportJob;
|
||||
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Log;
|
||||
/**
|
||||
* Class UploadCollector
|
||||
*
|
||||
@ -45,19 +46,23 @@ class UploadCollector extends BasicCollector implements CollectorInterface
|
||||
$len = strlen($expected);
|
||||
foreach ($files as $entry) {
|
||||
if (substr($entry, 0, $len) === $expected) {
|
||||
// this is an original upload.
|
||||
$parts = explode('-', str_replace(['.csv.encrypted', $expected], '', $entry));
|
||||
$originalUpload = intval($parts[1]);
|
||||
$date = date('Y-m-d \a\t H-i-s', $originalUpload);
|
||||
$newFileName = 'Old CSV import dated ' . $date . '.csv';
|
||||
$content = Crypt::decrypt(file_get_contents($path . DIRECTORY_SEPARATOR . $entry));
|
||||
$fullPath = storage_path('export') . DIRECTORY_SEPARATOR . $this->job->key . '-' . $newFileName;
|
||||
try {
|
||||
// this is an original upload.
|
||||
$parts = explode('-', str_replace(['.csv.encrypted', $expected], '', $entry));
|
||||
$originalUpload = intval($parts[1]);
|
||||
$date = date('Y-m-d \a\t H-i-s', $originalUpload);
|
||||
$newFileName = 'Old CSV import dated ' . $date . '.csv';
|
||||
$content = Crypt::decrypt(file_get_contents($path . DIRECTORY_SEPARATOR . $entry));
|
||||
$fullPath = storage_path('export') . DIRECTORY_SEPARATOR . $this->job->key . '-' . $newFileName;
|
||||
|
||||
// write to file:
|
||||
file_put_contents($fullPath, $content);
|
||||
// write to file:
|
||||
file_put_contents($fullPath, $content);
|
||||
|
||||
// add entry to set:
|
||||
$this->getFiles()->push($fullPath);
|
||||
// add entry to set:
|
||||
$this->getFiles()->push($fullPath);
|
||||
} catch (DecryptException $e) {
|
||||
Log::error('Could not decrypt old CSV import file ' . $entry . '. Skipped.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class ReportController extends Controller
|
||||
public function index(ARI $repository)
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
$start = session('first');
|
||||
$start = clone session('first');
|
||||
$months = $this->helper->listOfMonths($start);
|
||||
$customFiscalYear = Preferences::get('customFiscalYear', 0)->data;
|
||||
|
||||
|
@ -35,7 +35,9 @@ class ExportFormRequest extends Request
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$first = session('first')->subDay()->format('Y-m-d');
|
||||
$sessionFirst = clone session('first');
|
||||
|
||||
$first = $sessionFirst->subDay()->format('Y-m-d');
|
||||
$today = Carbon::create()->addDay()->format('Y-m-d');
|
||||
$formats = join(',', array_keys(config('firefly.export_formats')));
|
||||
|
||||
|
@ -27,6 +27,7 @@ function startExport() {
|
||||
console.log('Start export...');
|
||||
hideForm();
|
||||
showLoading();
|
||||
hideError();
|
||||
|
||||
// do export
|
||||
callExport();
|
||||
@ -34,6 +35,10 @@ function startExport() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function hideError() {
|
||||
"use strict";
|
||||
$('#export-error').hide();
|
||||
}
|
||||
|
||||
function hideForm() {
|
||||
"use strict";
|
||||
|
@ -73,6 +73,7 @@ return [
|
||||
'export_status_creating_zip_file' => 'Creating a zip file...',
|
||||
'export_status_created_zip_file' => 'Created a zip file!',
|
||||
'export_status_finished' => 'Export has succesfully finished! Yay!',
|
||||
'export_data_please_wait' => 'Please wait...',
|
||||
|
||||
// rules
|
||||
'rules' => 'Rules',
|
||||
|
Loading…
Reference in New Issue
Block a user