mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-21 11:48:53 +00:00
Some new stuff that really doesn't belong here. I'm not good at this.
This commit is contained in:
@@ -52,6 +52,30 @@ class Import
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function cleanImportAccount(Job $job, array $payload)
|
||||
{
|
||||
$importAccountType = $this->_accounts->findAccountType('Import account');
|
||||
$importAccounts = $this->_accounts->getByAccountType($importAccountType);
|
||||
if (count($importAccounts) == 0) {
|
||||
$job->delete();
|
||||
} else if (count($importAccounts) == 1) {
|
||||
/** @var \Account $importAccount */
|
||||
$importAccount = $importAccounts[0];
|
||||
$transactions = $importAccount->transactions()->get();
|
||||
/** @var \Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$transaction->account()->associate($importAccount);
|
||||
$transaction->save();
|
||||
}
|
||||
\Log::debug('Updated ' . count($transactions) . ' transactions from Import Account to cash.');
|
||||
}
|
||||
$job->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
@@ -611,8 +635,13 @@ class Import
|
||||
\Queue::push($jobFunction, ['data' => $entry, 'mapID' => $importMap->id]);
|
||||
}
|
||||
|
||||
// queue a job to clean up the "import account", it should properly fall back
|
||||
// to the cash account (which it doesn't always do for some reason).
|
||||
\Queue::push('Firefly\Queue\Import@cleanImportAccount', ['mapID' => $importMap->id]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
\Log::debug('Done with job "start"');
|
||||
// this is it, close the job:
|
||||
$job->delete();
|
||||
|
Reference in New Issue
Block a user