mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 20:16:22 +00:00
Refactor temporary account storage and fix a bug in the bunq import. #1607
This commit is contained in:
@@ -84,26 +84,36 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
* @param array $transactions
|
||||
*
|
||||
* @return ImportJob
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function appendTransactions(ImportJob $job, array $transactions): ImportJob
|
||||
{
|
||||
Log::debug(sprintf('Now in appendTransactions(%s)', $job->key));
|
||||
$existingTransactions = $job->transactions;
|
||||
if (!\is_array($existingTransactions)) {
|
||||
$existingTransactions = [];
|
||||
}
|
||||
$new = array_merge($existingTransactions, $transactions);
|
||||
$existingTransactions = $this->getTransactions($job);
|
||||
$new = array_merge($existingTransactions, $transactions);
|
||||
Log::debug(sprintf('Old transaction count: %d', \count($existingTransactions)));
|
||||
Log::debug(sprintf('To be added transaction count: %d', \count($transactions)));
|
||||
Log::debug(sprintf('New count: %d', \count($new)));
|
||||
$job->transactions = $new;
|
||||
|
||||
|
||||
$job->save();
|
||||
$this->setTransactions($job, $new);
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countTransactions(ImportJob $job): int
|
||||
{
|
||||
$info = $job->transactions ?? [];
|
||||
if (isset($info['count'])) {
|
||||
return (int)$info['count'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $importProvider
|
||||
*
|
||||
@@ -201,6 +211,31 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return transactions from attachment.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function getTransactions(ImportJob $job): array
|
||||
{
|
||||
// this will overwrite all transactions currently in the job.
|
||||
$disk = Storage::disk('upload');
|
||||
$filename = sprintf('%s-%s.crypt.json', $job->created_at->format('Ymd'), $job->key);
|
||||
$array = [];
|
||||
if ($disk->exists($filename)) {
|
||||
$json = Crypt::decrypt($disk->get($filename));
|
||||
$array = json_decode($json, true);
|
||||
}
|
||||
if (false === $array) {
|
||||
$array = [];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param array $configuration
|
||||
@@ -272,8 +307,17 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
*/
|
||||
public function setTransactions(ImportJob $job, array $transactions): ImportJob
|
||||
{
|
||||
$job->transactions = $transactions;
|
||||
// this will overwrite all transactions currently in the job.
|
||||
$disk = Storage::disk('upload');
|
||||
$filename = sprintf('%s-%s.crypt.json', $job->created_at->format('Ymd'), $job->key);
|
||||
$json = Crypt::encrypt(json_encode($transactions));
|
||||
|
||||
// set count for easy access
|
||||
$array = ['count' => \count($transactions)];
|
||||
$job->transactions = $array;
|
||||
$job->save();
|
||||
// store file.
|
||||
$disk->put($filename, $json);
|
||||
|
||||
return $job;
|
||||
}
|
||||
@@ -377,7 +421,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
$fileObject->rewind();
|
||||
|
||||
|
||||
if(0 === $file->getSize()) {
|
||||
if (0 === $file->getSize()) {
|
||||
throw new FireflyException('Cannot upload empty or non-existent file.');
|
||||
}
|
||||
|
||||
@@ -390,7 +434,6 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
return new MessageBag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
|
@@ -35,6 +35,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
*/
|
||||
interface ImportJobRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Add message to job.
|
||||
*
|
||||
@@ -55,6 +56,13 @@ interface ImportJobRepositoryInterface
|
||||
*/
|
||||
public function appendTransactions(ImportJob $job, array $transactions): ImportJob;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countTransactions(ImportJob $job): int;
|
||||
|
||||
/**
|
||||
* @param string $importProvider
|
||||
*
|
||||
@@ -96,6 +104,15 @@ interface ImportJobRepositoryInterface
|
||||
*/
|
||||
public function getExtendedStatus(ImportJob $job): array;
|
||||
|
||||
/**
|
||||
* Return transactions from attachment.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactions(ImportJob $job): array;
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param array $configuration
|
||||
|
Reference in New Issue
Block a user