mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add some debug info.
This commit is contained in:
parent
766a82a983
commit
0bdd48ffec
@ -30,6 +30,7 @@ use FireflyIII\Models\Transaction;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FixAccountTypes
|
* Class FixAccountTypes
|
||||||
@ -66,6 +67,7 @@ class FixAccountTypes extends Command
|
|||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$this->stupidLaravel();
|
$this->stupidLaravel();
|
||||||
|
Log::debug('Now in fix-account-types');
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
$this->factory = app(AccountFactory::class);
|
$this->factory = app(AccountFactory::class);
|
||||||
// some combinations can be fixed by this script:
|
// some combinations can be fixed by this script:
|
||||||
@ -88,13 +90,16 @@ class FixAccountTypes extends Command
|
|||||||
|
|
||||||
$this->expected = config('firefly.source_dests');
|
$this->expected = config('firefly.source_dests');
|
||||||
$journals = TransactionJournal::with(['TransactionType', 'transactions', 'transactions.account', 'transactions.account.accounttype'])->get();
|
$journals = TransactionJournal::with(['TransactionType', 'transactions', 'transactions.account', 'transactions.account.accounttype'])->get();
|
||||||
|
Log::debug(sprintf('Found %d journals to fix.', $journals->count()));
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$this->inspectJournal($journal);
|
$this->inspectJournal($journal);
|
||||||
}
|
}
|
||||||
if (0 === $this->count) {
|
if (0 === $this->count) {
|
||||||
|
Log::debug('No journals had to be fixed.');
|
||||||
$this->info('All account types are OK!');
|
$this->info('All account types are OK!');
|
||||||
}
|
}
|
||||||
if (0 !== $this->count) {
|
if (0 !== $this->count) {
|
||||||
|
Log::debug(sprintf('%d journals had to be fixed.', $this->count));
|
||||||
$this->info(sprintf('Acted on %d transaction(s)!', $this->count));
|
$this->info(sprintf('Acted on %d transaction(s)!', $this->count));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,21 +228,36 @@ class FixAccountTypes extends Command
|
|||||||
*/
|
*/
|
||||||
private function inspectJournal(TransactionJournal $journal): void
|
private function inspectJournal(TransactionJournal $journal): void
|
||||||
{
|
{
|
||||||
|
Log::debug(sprintf('Now trying to fix journal #%d', $journal->id));
|
||||||
$count = $journal->transactions()->count();
|
$count = $journal->transactions()->count();
|
||||||
if (2 !== $count) {
|
if (2 !== $count) {
|
||||||
|
Log::debug(sprintf('Journal has %d transactions, so cant fix.', $count));
|
||||||
$this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $count));
|
$this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $count));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$type = $journal->transactionType->type;
|
$type = $journal->transactionType->type;
|
||||||
$sourceTransaction = $this->getSourceTransaction($journal);
|
$sourceTransaction = $this->getSourceTransaction($journal);
|
||||||
|
$destTransaction = $this->getDestinationTransaction($journal);
|
||||||
|
if (null === $sourceTransaction) {
|
||||||
|
Log::error('Source transaction is unexpectedly NULL. Wont fix this journal.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (null === $destTransaction) {
|
||||||
|
Log::error('Destination transaction is unexpectedly NULL. Wont fix this journal.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$sourceAccount = $sourceTransaction->account;
|
$sourceAccount = $sourceTransaction->account;
|
||||||
$sourceAccountType = $sourceAccount->accountType->type;
|
$sourceAccountType = $sourceAccount->accountType->type;
|
||||||
$destTransaction = $this->getDestinationTransaction($journal);
|
|
||||||
$destAccount = $destTransaction->account;
|
$destAccount = $destTransaction->account;
|
||||||
$destAccountType = $destAccount->accountType->type;
|
$destAccountType = $destAccount->accountType->type;
|
||||||
|
|
||||||
if (!isset($this->expected[$type])) {
|
if (!isset($this->expected[$type])) {
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
|
Log::info(sprintf('No source/destination info for transaction type %s.', $type));
|
||||||
$this->info(sprintf('No source/destination info for transaction type %s.', $type));
|
$this->info(sprintf('No source/destination info for transaction type %s.', $type));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user