mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some re-alignment and catches for NULLs
This commit is contained in:
parent
239bbd30c0
commit
824cf71e0b
@ -7,6 +7,7 @@ use Illuminate\Queue\Jobs\Job;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Import
|
* Class Import
|
||||||
|
*
|
||||||
* @package Firefly\Queue
|
* @package Firefly\Queue
|
||||||
*/
|
*/
|
||||||
class Import
|
class Import
|
||||||
@ -79,6 +80,7 @@ class Import
|
|||||||
/**
|
/**
|
||||||
* @param Job $job
|
* @param Job $job
|
||||||
* @param array $payload
|
* @param array $payload
|
||||||
|
*
|
||||||
* @throws \Firefly\Exception\FireflyException
|
* @throws \Firefly\Exception\FireflyException
|
||||||
*/
|
*/
|
||||||
public function importComponent(Job $job, array $payload)
|
public function importComponent(Job $job, array $payload)
|
||||||
@ -281,19 +283,25 @@ class Import
|
|||||||
// budget thing link:
|
// budget thing link:
|
||||||
$budget = $this->_budgets->find($oldComponentMap->new);
|
$budget = $this->_budgets->find($oldComponentMap->new);
|
||||||
|
|
||||||
\Log::debug('Updating transactions Budget.');
|
\Log::debug('Updating transactions budget.');
|
||||||
$journal->budgets()->save($budget);
|
$journal->budgets()->save($budget);
|
||||||
$journal->save();
|
$journal->save();
|
||||||
\Log::debug('Updated transactions Budget.');
|
\Log::debug('Updated transactions budget.');
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'Category':
|
case 'Category':
|
||||||
$category = $this->_categories->find($oldComponentMap->new);
|
$category = $this->_categories->find($oldComponentMap->new);
|
||||||
$journal = $this->_journals->find($oldTransactionMap->new);
|
$journal = $this->_journals->find($oldTransactionMap->new);
|
||||||
\Log::info('Updating transactions Category.');
|
\Log::info('Updating transactions category (old id is #' . $oldComponentMap->old . ').');
|
||||||
|
if (!is_null($category)) {
|
||||||
$journal->categories()->save($category);
|
$journal->categories()->save($category);
|
||||||
$journal->save();
|
$journal->save();
|
||||||
\Log::info('Updated transactions Category.');
|
\Log::info('Updated transactions category.');
|
||||||
|
} else {
|
||||||
|
\Log::error('No category mapping to old id #' . $oldComponentMap->old . ' found. Release for 5m!');
|
||||||
|
$job->release(300);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'Account':
|
case 'Account':
|
||||||
\Log::info('Updating transactions Account.');
|
\Log::info('Updating transactions Account.');
|
||||||
@ -309,7 +317,9 @@ class Import
|
|||||||
if ($transaction->account()->first()->account_type_id == 5) {
|
if ($transaction->account()->first()->account_type_id == 5) {
|
||||||
$transaction->account()->associate($account);
|
$transaction->account()->associate($account);
|
||||||
$transaction->save();
|
$transaction->save();
|
||||||
\Log::debug('Updated transactions (#' . $journal->id . '), #' . $transaction->id . '\'s Account.');
|
\Log::debug(
|
||||||
|
'Updated transactions (#' . $journal->id . '), #' . $transaction->id . '\'s Account.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,13 +349,17 @@ class Import
|
|||||||
|
|
||||||
|
|
||||||
// find the budget this limit is part of:
|
// find the budget this limit is part of:
|
||||||
$importEntry = $this->_repository->findImportEntry($importMap, 'Budget',
|
$importEntry = $this->_repository->findImportEntry(
|
||||||
intval($payload['data']['component_id']));
|
$importMap, 'Budget',
|
||||||
|
intval($payload['data']['component_id'])
|
||||||
|
);
|
||||||
|
|
||||||
// budget is not yet imported:
|
// budget is not yet imported:
|
||||||
if (is_null($importEntry)) {
|
if (is_null($importEntry)) {
|
||||||
\Log::debug('importLimit Cannot import limit #' . $payload['data']['id'] .
|
\Log::debug(
|
||||||
' because the budget is not here yet. #' . $job->attempts());
|
'importLimit Cannot import limit #' . $payload['data']['id'] .
|
||||||
|
' because the budget is not here yet. #' . $job->attempts()
|
||||||
|
);
|
||||||
$job->release(300);
|
$job->release(300);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -366,7 +380,9 @@ class Import
|
|||||||
} else {
|
} else {
|
||||||
// already has!
|
// already has!
|
||||||
$this->_repository->store($importMap, 'Budget', $payload['data']['id'], $current->id);
|
$this->_repository->store($importMap, 'Budget', $payload['data']['id'], $current->id);
|
||||||
\Log::debug('Already had ' . $payload['class'] . ', for ' . $budget->name . ' (' . $current->startdate . ').');
|
\Log::debug(
|
||||||
|
'Already had ' . $payload['class'] . ', for ' . $budget->name . ' (' . $current->startdate . ').'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// cannot import component limit, no longer supported.
|
// cannot import component limit, no longer supported.
|
||||||
@ -519,8 +535,10 @@ class Import
|
|||||||
// if amount is more than zero, move from $importAccount
|
// if amount is more than zero, move from $importAccount
|
||||||
$amount = floatval($payload['data']['amount']);
|
$amount = floatval($payload['data']['amount']);
|
||||||
|
|
||||||
$accountEntry = $this->_repository->findImportEntry($importMap, 'Account',
|
$accountEntry = $this->_repository->findImportEntry(
|
||||||
intval($payload['data']['account_id']));
|
$importMap, 'Account',
|
||||||
|
intval($payload['data']['account_id'])
|
||||||
|
);
|
||||||
$personalAccount = $this->_accounts->find($accountEntry->new);
|
$personalAccount = $this->_accounts->find($accountEntry->new);
|
||||||
|
|
||||||
if ($amount < 0) {
|
if ($amount < 0) {
|
||||||
@ -539,10 +557,15 @@ class Import
|
|||||||
|
|
||||||
|
|
||||||
if (is_null($current)) {
|
if (is_null($current)) {
|
||||||
$journal = $this->_journals->createSimpleJournal($accountFrom, $accountTo,
|
$journal = $this->_journals->createSimpleJournal(
|
||||||
$payload['data']['description'], $amount, $date);
|
$accountFrom, $accountTo,
|
||||||
|
$payload['data']['description'], $amount, $date
|
||||||
|
);
|
||||||
$this->_repository->store($importMap, 'Transaction', $payload['data']['id'], $journal->id);
|
$this->_repository->store($importMap, 'Transaction', $payload['data']['id'], $journal->id);
|
||||||
\Log::debug('Imported transaction "' . $payload['data']['description'] . '" (' . $journal->date->format('Y-m-d') . ').');
|
\Log::debug(
|
||||||
|
'Imported transaction "' . $payload['data']['description'] . '" (' . $journal->date->format('Y-m-d')
|
||||||
|
. ').'
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// do nothing.
|
// do nothing.
|
||||||
\Log::debug('ALREADY imported transaction "' . $payload['data']['description'] . '".');
|
\Log::debug('ALREADY imported transaction "' . $payload['data']['description'] . '".');
|
||||||
@ -577,8 +600,10 @@ class Import
|
|||||||
if (!is_null($accountFrom) && !is_null($accountTo)) {
|
if (!is_null($accountFrom) && !is_null($accountTo)) {
|
||||||
$amount = floatval($payload['data']['amount']);
|
$amount = floatval($payload['data']['amount']);
|
||||||
$date = new Carbon($payload['data']['date']);
|
$date = new Carbon($payload['data']['date']);
|
||||||
$journal = $this->_journals->createSimpleJournal($accountFrom, $accountTo, $payload['data']['description'],
|
$journal = $this->_journals->createSimpleJournal(
|
||||||
$amount, $date);
|
$accountFrom, $accountTo, $payload['data']['description'],
|
||||||
|
$amount, $date
|
||||||
|
);
|
||||||
\Log::debug('Imported transfer "' . $payload['data']['description'] . '".');
|
\Log::debug('Imported transfer "' . $payload['data']['description'] . '".');
|
||||||
$job->delete();
|
$job->delete();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user