From 42043de34fcd04277685aec1749d824210b07cbb Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 20 Jun 2023 07:16:56 +0200 Subject: [PATCH] fix: replace console messages with unified command. --- .../Commands/Correction/CorrectAmounts.php | 38 +-- .../Commands/Correction/CorrectDatabase.php | 7 +- .../CorrectOpeningBalanceCurrencies.php | 11 +- .../Correction/CreateAccessTokens.php | 7 +- .../Commands/Correction/CreateLinkTypes.php | 7 +- .../Commands/Correction/DeleteEmptyGroups.php | 7 +- .../Correction/DeleteEmptyJournals.php | 13 +- .../Correction/DeleteOrphanedTransactions.php | 40 +-- .../Commands/Correction/DeleteZeroAmount.php | 7 +- .../Commands/Correction/EnableCurrencies.php | 7 +- .../Commands/Correction/FixAccountOrder.php | 5 +- .../Commands/Correction/FixAccountTypes.php | 23 +- .../Correction/FixFrontpageAccounts.php | 5 +- .../Commands/Correction/FixGroupAccounts.php | 5 +- app/Console/Commands/Correction/FixIbans.php | 9 +- .../Correction/FixLongDescriptions.php | 9 +- .../Commands/Correction/FixPiggies.php | 7 +- .../Correction/FixRecurringTransactions.php | 7 +- .../Correction/FixTransactionTypes.php | 11 +- .../Commands/Correction/FixUnevenAmount.php | 15 +- .../Commands/Correction/RemoveBills.php | 9 +- .../Commands/Correction/RenameMetaFields.php | 7 +- .../Commands/Correction/TransferBudgets.php | 11 +- app/Console/Commands/Export/ExportData.php | 238 +++++++++--------- .../Integrity/CreateGroupMemberships.php | 5 +- .../Commands/Integrity/ReportEmptyObjects.php | 13 +- .../Commands/Integrity/ReportIntegrity.php | 5 +- app/Console/Commands/Integrity/ReportSum.php | 9 +- .../Commands/Integrity/RestoreOAuthKeys.php | 13 +- .../Integrity/UpdateGroupInformation.php | 9 +- .../Commands/ShowsFriendlyMessages.php | 83 ++++++ .../Commands/System/CreateDatabase.php | 15 +- .../Commands/System/CreateFirstUser.php | 11 +- .../Commands/System/ForceDecimalSize.php | 53 ++-- .../Commands/System/ForceMigration.php | 22 +- .../Commands/System/ScanAttachments.php | 5 +- .../Commands/System/SetLatestVersion.php | 7 +- .../Commands/System/VerifySecurityAlerts.php | 21 +- app/Console/Commands/Tools/ApplyRules.php | 174 ++++++------- app/Console/Commands/Tools/Cron.php | 39 +-- .../Commands/Upgrade/AccountCurrencies.php | 17 +- .../Upgrade/AppendBudgetLimitPeriods.php | 7 +- .../Commands/Upgrade/BackToJournals.php | 16 +- .../Commands/Upgrade/BudgetLimitCurrency.php | 9 +- .../Commands/Upgrade/CCLiabilities.php | 25 +- .../Commands/Upgrade/DecryptDatabase.php | 11 +- .../Commands/Upgrade/FixPostgresSequences.php | 16 +- .../Commands/Upgrade/MigrateAttachments.php | 11 +- .../Commands/Upgrade/MigrateJournalNotes.php | 11 +- .../Upgrade/MigrateRecurrenceMeta.php | 9 +- .../Upgrade/MigrateRecurrenceType.php | 17 +- .../Commands/Upgrade/MigrateTagLocations.php | 5 +- .../Commands/Upgrade/MigrateToGroups.php | 21 +- .../Commands/Upgrade/MigrateToRules.php | 13 +- .../Upgrade/OtherCurrenciesCorrections.php | 11 +- .../Commands/Upgrade/RenameAccountMeta.php | 9 +- .../Upgrade/TransactionIdentifier.php | 17 +- .../Upgrade/TransferCurrenciesCorrections.php | 44 ++-- .../Commands/Upgrade/UpgradeDatabase.php | 5 +- .../Commands/Upgrade/UpgradeLiabilities.php | 5 +- .../Upgrade/UpgradeLiabilitiesEight.php | 9 +- .../Commands/Upgrade/UpgradeSkeleton.php.stub | 2 +- 62 files changed, 767 insertions(+), 512 deletions(-) create mode 100644 app/Console/Commands/ShowsFriendlyMessages.php diff --git a/app/Console/Commands/Correction/CorrectAmounts.php b/app/Console/Commands/Correction/CorrectAmounts.php index c2fda9333f..e9199540a6 100644 --- a/app/Console/Commands/Correction/CorrectAmounts.php +++ b/app/Console/Commands/Correction/CorrectAmounts.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\AutoBudget; use FireflyIII\Models\AvailableBudget; use FireflyIII\Models\Bill; @@ -39,6 +40,8 @@ use Illuminate\Console\Command; */ class CorrectAmounts extends Command { + use ShowsFriendlyMessages; + protected $description = 'This command makes sure positive and negative amounts are recorded correctly.'; protected $signature = 'firefly-iii:fix-amount-pos-neg'; @@ -78,7 +81,7 @@ class CorrectAmounts extends Command $set = AutoBudget::where('amount', '<', 0)->get(); $count = $set->count(); if (0 === $count) { - $this->info('Correct: All auto budget amounts are positive.'); + $this->friendlyPositive('All auto budget amounts are positive.'); return; } @@ -87,7 +90,7 @@ class CorrectAmounts extends Command $item->amount = app('steam')->positive((string)$item->amount); $item->save(); } - $this->line(sprintf('Corrected %d auto budget amount(s).', $count)); + $this->friendlyInfo(sprintf('Corrected %d auto budget amount(s).', $count)); } /** @@ -98,7 +101,7 @@ class CorrectAmounts extends Command $set = AvailableBudget::where('amount', '<', 0)->get(); $count = $set->count(); if (0 === $count) { - $this->info('Correct: All available budget amounts are positive.'); + $this->friendlyPositive('All available budget amounts are positive.'); return; } @@ -107,7 +110,7 @@ class CorrectAmounts extends Command $item->amount = app('steam')->positive((string)$item->amount); $item->save(); } - $this->line(sprintf('Corrected %d available budget amount(s).', $count)); + $this->friendlyInfo(sprintf('Corrected %d available budget amount(s).', $count)); } /** @@ -118,7 +121,7 @@ class CorrectAmounts extends Command $set = Bill::where('amount_min', '<', 0)->orWhere('amount_max', '<', 0)->get(); $count = $set->count(); if (0 === $count) { - $this->info('Correct: All bill amounts are positive.'); + $this->friendlyPositive('All bill amounts are positive.'); return; } @@ -128,6 +131,7 @@ class CorrectAmounts extends Command $item->amount_max = app('steam')->positive((string)$item->amount_max); $item->save(); } + $this->friendlyInfo(sprintf('Corrected %d bill amount(s).', $count)); } /** @@ -138,7 +142,7 @@ class CorrectAmounts extends Command $set = BudgetLimit::where('amount', '<', 0)->get(); $count = $set->count(); if (0 === $count) { - $this->info('Correct: All budget limit amounts are positive.'); + $this->friendlyPositive('All budget limit amounts are positive.'); return; } @@ -147,7 +151,7 @@ class CorrectAmounts extends Command $item->amount = app('steam')->positive((string)$item->amount); $item->save(); } - $this->line(sprintf('Corrected %d budget limit amount(s).', $count)); + $this->friendlyInfo(sprintf('Corrected %d budget limit amount(s).', $count)); } /** @@ -158,7 +162,7 @@ class CorrectAmounts extends Command $set = CurrencyExchangeRate::where('rate', '<', 0)->get(); $count = $set->count(); if (0 === $count) { - $this->info('Correct: All currency exchange rates are positive.'); + $this->friendlyPositive('All currency exchange rates are positive.'); return; } @@ -167,7 +171,7 @@ class CorrectAmounts extends Command $item->rate = app('steam')->positive((string)$item->rate); $item->save(); } - $this->line(sprintf('Corrected %d currency exchange rate(s).', $count)); + $this->friendlyInfo(sprintf('Corrected %d currency exchange rate(s).', $count)); } /** @@ -178,7 +182,7 @@ class CorrectAmounts extends Command $set = PiggyBank::where('targetamount', '<', 0)->get(); $count = $set->count(); if (0 === $count) { - $this->info('Correct: All piggy bank amounts are positive.'); + $this->friendlyPositive('All piggy bank amounts are positive.'); return; } @@ -187,7 +191,7 @@ class CorrectAmounts extends Command $item->targetamount = app('steam')->positive((string)$item->targetamount); $item->save(); } - $this->line(sprintf('Corrected %d piggy bank amount(s).', $count)); + $this->friendlyInfo(sprintf('Corrected %d piggy bank amount(s).', $count)); } /** @@ -200,7 +204,7 @@ class CorrectAmounts extends Command ->get(); $count = $set->count(); if (0 === $count) { - $this->info('Correct: All recurring transaction amounts are positive.'); + $this->friendlyPositive('All recurring transaction amounts are positive.'); return; } @@ -210,7 +214,7 @@ class CorrectAmounts extends Command $item->foreign_amount = app('steam')->positive((string)$item->foreign_amount); $item->save(); } - $this->line(sprintf('Corrected %d recurring transaction amount(s).', $count)); + $this->friendlyInfo(sprintf('Corrected %d recurring transaction amount(s).', $count)); } /** @@ -221,7 +225,7 @@ class CorrectAmounts extends Command $set = PiggyBankRepetition::where('currentamount', '<', 0)->get(); $count = $set->count(); if (0 === $count) { - $this->info('Correct: All piggy bank repetition amounts are positive.'); + $this->friendlyPositive('All piggy bank repetition amounts are positive.'); return; } @@ -230,7 +234,7 @@ class CorrectAmounts extends Command $item->currentamount = app('steam')->positive((string)$item->currentamount); $item->save(); } - $this->line(sprintf('Corrected %d piggy bank repetition amount(s).', $count)); + $this->friendlyInfo(sprintf('Corrected %d piggy bank repetition amount(s).', $count)); } /** @@ -250,11 +254,11 @@ class CorrectAmounts extends Command } } if (0 === $fixed) { - $this->info('Correct: All rule trigger amounts are positive.'); + $this->friendlyPositive('All rule trigger amounts are positive.'); return; } - $this->line(sprintf('Corrected %d rule trigger amount(s).', $fixed)); + $this->friendlyInfo(sprintf('Corrected %d rule trigger amount(s).', $fixed)); } } diff --git a/app/Console/Commands/Correction/CorrectDatabase.php b/app/Console/Commands/Correction/CorrectDatabase.php index aed810e830..e7db8d30c5 100644 --- a/app/Console/Commands/Correction/CorrectDatabase.php +++ b/app/Console/Commands/Correction/CorrectDatabase.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; use Artisan; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use Illuminate\Console\Command; use Schema; @@ -34,6 +35,8 @@ use Schema; */ class CorrectDatabase extends Command { + use ShowsFriendlyMessages; + protected $description = 'Will correct the integrity of your database, if necessary.'; protected $signature = 'firefly-iii:correct-database'; @@ -44,7 +47,7 @@ class CorrectDatabase extends Command { // if table does not exist, return false if (!Schema::hasTable('users')) { - $this->error('No "users"-table, will not continue.'); + $this->friendlyError('No "users"-table, will not continue.'); return 1; } @@ -76,7 +79,7 @@ class CorrectDatabase extends Command 'firefly-iii:trigger-credit-recalculation', ]; foreach ($commands as $command) { - $this->line(sprintf('Now executing command "%s"', $command)); + $this->friendlyLine(sprintf('Now executing command "%s"', $command)); $this->call($command); } diff --git a/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php b/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php index 14d6b299a6..f82512adcf 100644 --- a/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php +++ b/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use FireflyIII\Models\Transaction; @@ -39,6 +40,8 @@ use Illuminate\Support\Collection; */ class CorrectOpeningBalanceCurrencies extends Command { + use ShowsFriendlyMessages; + protected $description = 'Will make sure that opening balance transaction currencies match the account they\'re for.'; protected $signature = 'firefly-iii:fix-ob-currencies'; @@ -58,11 +61,11 @@ class CorrectOpeningBalanceCurrencies extends Command if ($count > 0) { $message = sprintf('Corrected %d opening balance transaction(s).', $count); - $this->line($message); + $this->friendlyInfo($message); } if (0 === $count) { - $message = 'Correct: There was nothing to fix in the opening balance transactions.'; - $this->info($message); + $message = 'There was nothing to fix in the opening balance transactions.'; + $this->friendlyPositive($message); } return 0; @@ -80,7 +83,7 @@ class CorrectOpeningBalanceCurrencies extends Command if (null === $account) { $message = sprintf('Transaction journal #%d has no valid account. Can\'t fix this line.', $journal->id); app('log')->warning($message); - $this->warn($message); + $this->friendlyError($message); return 0; } diff --git a/app/Console/Commands/Correction/CreateAccessTokens.php b/app/Console/Commands/Correction/CreateAccessTokens.php index a8a73d1a9b..ab53dc2bcf 100644 --- a/app/Console/Commands/Correction/CreateAccessTokens.php +++ b/app/Console/Commands/Correction/CreateAccessTokens.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; use Exception; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Illuminate\Console\Command; @@ -33,6 +34,8 @@ use Illuminate\Console\Command; */ class CreateAccessTokens extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -66,12 +69,12 @@ class CreateAccessTokens extends Command if (null === $pref) { $token = $user->generateAccessToken(); app('preferences')->setForUser($user, 'access_token', $token); - $this->line(sprintf('Generated access token for user %s', $user->email)); + $this->friendlyInfo(sprintf('Generated access token for user %s', $user->email)); ++$count; } } if (0 === $count) { - $this->info('Correct: Verified access tokens.'); + $this->friendlyPositive('Verified access tokens.'); } return 0; diff --git a/app/Console/Commands/Correction/CreateLinkTypes.php b/app/Console/Commands/Correction/CreateLinkTypes.php index cde1dbbd47..43620515eb 100644 --- a/app/Console/Commands/Correction/CreateLinkTypes.php +++ b/app/Console/Commands/Correction/CreateLinkTypes.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\LinkType; use Illuminate\Console\Command; @@ -31,6 +32,8 @@ use Illuminate\Console\Command; */ class CreateLinkTypes extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -67,13 +70,13 @@ class CreateLinkTypes extends Command $link->inward = $values[1]; $link->outward = $values[0]; ++$count; - $this->line(sprintf('Created missing link type "%s"', $name)); + $this->friendlyInfo(sprintf('Created missing link type "%s"', $name)); } $link->editable = false; $link->save(); } if (0 === $count) { - $this->info('Correct: all link types are OK'); + $this->friendlyPositive('All link types are OK'); } return 0; } diff --git a/app/Console/Commands/Correction/DeleteEmptyGroups.php b/app/Console/Commands/Correction/DeleteEmptyGroups.php index 27eaee4077..6948cfaa8f 100644 --- a/app/Console/Commands/Correction/DeleteEmptyGroups.php +++ b/app/Console/Commands/Correction/DeleteEmptyGroups.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; use Exception; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\TransactionGroup; use Illuminate\Console\Command; @@ -32,6 +33,8 @@ use Illuminate\Console\Command; */ class DeleteEmptyGroups extends Command { + use ShowsFriendlyMessages; + protected $description = 'Delete empty transaction groups.'; protected $signature = 'firefly-iii:delete-empty-groups'; @@ -50,7 +53,7 @@ class DeleteEmptyGroups extends Command $total = count($groupIds); if ($total > 0) { - $this->info(sprintf('Deleted %d empty transaction group(s).', $total)); + $this->friendlyInfo(sprintf('Deleted %d empty transaction group(s).', $total)); // again, chunks for SQLite. $chunks = array_chunk($groupIds, 500); @@ -59,7 +62,7 @@ class DeleteEmptyGroups extends Command } } if (0 === $total) { - $this->info('Correct: verified empty groups.'); + $this->friendlyInfo('Verified there are no empty groups.'); } return 0; diff --git a/app/Console/Commands/Correction/DeleteEmptyJournals.php b/app/Console/Commands/Correction/DeleteEmptyJournals.php index e0a6184881..681c583a67 100644 --- a/app/Console/Commands/Correction/DeleteEmptyJournals.php +++ b/app/Console/Commands/Correction/DeleteEmptyJournals.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; use DB; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use Illuminate\Console\Command; @@ -35,6 +36,8 @@ use Illuminate\Support\Facades\Log; */ class DeleteEmptyJournals extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -77,11 +80,11 @@ class DeleteEmptyJournals extends Command } - $this->info(sprintf('Deleted empty transaction journal #%d', $entry->id)); + $this->friendlyInfo(sprintf('Deleted empty transaction journal #%d', $entry->id)); ++$count; } if (0 === $count) { - $this->info('Correct: no empty transaction journals.'); + $this->friendlyPositive('No empty transaction journals.'); } } @@ -107,12 +110,14 @@ class DeleteEmptyJournals extends Command Transaction::where('transaction_journal_id', (int)$row->transaction_journal_id)->delete(); - $this->info(sprintf('Deleted transaction journal #%d because it had an uneven number of transactions.', $row->transaction_journal_id)); + $this->friendlyWarning( + sprintf('Deleted transaction journal #%d because it had an uneven number of transactions.', $row->transaction_journal_id) + ); $total++; } } if (0 === $total) { - $this->info('Correct: no uneven transaction journals.'); + $this->friendlyPositive('No uneven transaction journals.'); } } } diff --git a/app/Console/Commands/Correction/DeleteOrphanedTransactions.php b/app/Console/Commands/Correction/DeleteOrphanedTransactions.php index 3d2dc9b753..fd5a2469ba 100644 --- a/app/Console/Commands/Correction/DeleteOrphanedTransactions.php +++ b/app/Console/Commands/Correction/DeleteOrphanedTransactions.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; use Exception; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use Illuminate\Console\Command; @@ -34,6 +35,8 @@ use stdClass; */ class DeleteOrphanedTransactions extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -80,7 +83,7 @@ class DeleteOrphanedTransactions extends Command $journal->delete(); } Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete(); - $this->line( + $this->friendlyWarning( sprintf( 'Deleted transaction journal #%d because account #%d was already deleted.', $transaction->transaction_journal_id, @@ -90,7 +93,7 @@ class DeleteOrphanedTransactions extends Command $count++; } if (0 === $count) { - $this->info('Correct: no orphaned accounts.'); + $this->friendlyPositive('No orphaned accounts.'); } } @@ -102,22 +105,21 @@ class DeleteOrphanedTransactions extends Command ->get(['transaction_journals.id', 'transaction_journals.transaction_group_id']); $count = $set->count(); if (0 === $count) { - $this->info('Correct: no orphaned journals.'); + $this->friendlyPositive('No orphaned journals.'); + return; } - if ($count > 0) { - $this->info(sprintf('Found %d orphaned journal(s).', $count)); - foreach ($set as $entry) { - $journal = TransactionJournal::withTrashed()->find((int)$entry->id); - if (null !== $journal) { - $journal->delete(); - $this->info( - sprintf( - 'Journal #%d (part of deleted transaction group #%d) has been deleted as well.', - $entry->id, - $entry->transaction_group_id - ) - ); - } + $this->friendlyInfo(sprintf('Found %d orphaned journal(s).', $count)); + foreach ($set as $entry) { + $journal = TransactionJournal::withTrashed()->find((int)$entry->id); + if (null !== $journal) { + $journal->delete(); + $this->friendlyWarning( + sprintf( + 'Journal #%d (part of deleted transaction group #%d) has been deleted as well.', + $entry->id, + $entry->transaction_group_id + ) + ); } } } @@ -143,7 +145,7 @@ class DeleteOrphanedTransactions extends Command $transaction = Transaction::find((int)$entry->transaction_id); if (null !== $transaction) { $transaction->delete(); - $this->info( + $this->friendlyWarning( sprintf( 'Transaction #%d (part of deleted transaction journal #%d) has been deleted as well.', $entry->transaction_id, @@ -154,7 +156,7 @@ class DeleteOrphanedTransactions extends Command } } if (0 === $count) { - $this->info('Correct: no orphaned transactions.'); + $this->friendlyPositive('No orphaned transactions.'); } } } diff --git a/app/Console/Commands/Correction/DeleteZeroAmount.php b/app/Console/Commands/Correction/DeleteZeroAmount.php index b7bf6e2c8e..f0e52cdccf 100644 --- a/app/Console/Commands/Correction/DeleteZeroAmount.php +++ b/app/Console/Commands/Correction/DeleteZeroAmount.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use Illuminate\Console\Command; @@ -32,6 +33,8 @@ use Illuminate\Console\Command; */ class DeleteZeroAmount extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -57,13 +60,13 @@ class DeleteZeroAmount extends Command $journals = TransactionJournal::whereIn('id', $set)->get(); /** @var TransactionJournal $journal */ foreach ($journals as $journal) { - $this->info(sprintf('Deleted transaction journal #%d because the amount is zero (0.00).', $journal->id)); + $this->friendlyWarning(sprintf('Deleted transaction journal #%d because the amount is zero (0.00).', $journal->id)); $journal->delete(); Transaction::where('transaction_journal_id', $journal->id)->delete(); } if (0 === $journals->count()) { - $this->info('Correct: no zero-amount transaction journals.'); + $this->friendlyPositive('No zero-amount transaction journals.'); } return 0; diff --git a/app/Console/Commands/Correction/EnableCurrencies.php b/app/Console/Commands/Correction/EnableCurrencies.php index 0901c4a565..a47b2957a1 100644 --- a/app/Console/Commands/Correction/EnableCurrencies.php +++ b/app/Console/Commands/Correction/EnableCurrencies.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\AccountMeta; use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\Transaction; @@ -37,6 +38,8 @@ use Illuminate\Support\Facades\Log; */ class EnableCurrencies extends Command { + use ShowsFriendlyMessages; + protected $description = 'Enables all currencies in use.'; protected $signature = 'firefly-iii:enable-currencies'; @@ -85,10 +88,10 @@ class EnableCurrencies extends Command ); $disabled = TransactionCurrency::whereIn('id', $found)->where('enabled', false)->count(); if ($disabled > 0) { - $this->info(sprintf('%d were (was) still disabled. This has been corrected.', $disabled)); + $this->friendlyInfo(sprintf('%d currencies were (was) disabled while in use by transactions. This has been corrected.', $disabled)); } if (0 === $disabled) { - $this->info('Correct: All currencies are correctly enabled or disabled.'); + $this->friendlyPositive('All currencies are correctly enabled or disabled.'); } TransactionCurrency::whereIn('id', $found)->update(['enabled' => true]); diff --git a/app/Console/Commands/Correction/FixAccountOrder.php b/app/Console/Commands/Correction/FixAccountOrder.php index 86f9052fbb..acc0276934 100644 --- a/app/Console/Commands/Correction/FixAccountOrder.php +++ b/app/Console/Commands/Correction/FixAccountOrder.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\User; use Illuminate\Console\Command; @@ -32,6 +33,8 @@ use Illuminate\Console\Command; */ class FixAccountOrder extends Command { + use ShowsFriendlyMessages; + protected $description = 'Make sure account order is correct.'; protected $signature = 'firefly-iii:fix-account-order'; @@ -52,7 +55,7 @@ class FixAccountOrder extends Command $this->repository->resetAccountOrder(); } - $this->info('Correct: All accounts are ordered correctly'); + $this->friendlyPositive('All accounts are ordered correctly'); return 0; } diff --git a/app/Console/Commands/Correction/FixAccountTypes.php b/app/Console/Commands/Correction/FixAccountTypes.php index 53706dbd99..f2b84ebc75 100644 --- a/app/Console/Commands/Correction/FixAccountTypes.php +++ b/app/Console/Commands/Correction/FixAccountTypes.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\AccountFactory; use FireflyIII\Models\AccountType; @@ -38,6 +39,8 @@ use Illuminate\Support\Facades\Log; */ class FixAccountTypes extends Command { + use ShowsFriendlyMessages; + protected $description = 'Make sure all journals have the correct from/to account types.'; protected $signature = 'firefly-iii:fix-account-types'; private int $count; @@ -60,11 +63,11 @@ class FixAccountTypes extends Command $this->inspectJournal($journal); } if (0 === $this->count) { - $this->info('Correct: all account types are OK'); + $this->friendlyPositive('All account types are OK'); } 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->friendlyInfo(sprintf('Acted on %d transaction(s)', $this->count)); } return 0; @@ -94,7 +97,7 @@ class FixAccountTypes extends Command $journal->transactionType()->associate($withdrawal); $journal->save(); $message = sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id); - $this->info($message); + $this->friendlyInfo($message); Log::debug($message); // check it again: $this->inspectJournal($journal); @@ -107,7 +110,7 @@ class FixAccountTypes extends Command $journal->transactionType()->associate($deposit); $journal->save(); $message = sprintf('Converted transaction #%d from a transfer to a deposit.', $journal->id); - $this->info($message); + $this->friendlyInfo($message); Log::debug($message); // check it again: $this->inspectJournal($journal); @@ -128,7 +131,7 @@ class FixAccountTypes extends Command $result->id, $result->name ); - $this->info($message); + $this->friendlyWarning($message); Log::debug($message); $this->inspectJournal($journal); break; @@ -148,17 +151,17 @@ class FixAccountTypes extends Command $result->id, $result->name ); - $this->info($message); + $this->friendlyWarning($message); Log::debug($message); $this->inspectJournal($journal); break; default: $message = sprintf('The source account of %s #%d cannot be of type "%s".', $type, $journal->id, $source->account->accountType->type); - $this->info($message); + $this->friendlyError($message); Log::debug($message); $message = sprintf('The destination account of %s #%d cannot be of type "%s".', $type, $journal->id, $dest->account->accountType->type); - $this->info($message); + $this->friendlyError($message); Log::debug($message); break; @@ -195,7 +198,7 @@ class FixAccountTypes extends Command $transactions = $journal->transactions()->count(); if (2 !== $transactions) { Log::debug(sprintf('Journal has %d transactions, so can\'t fix.', $transactions)); - $this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $transactions)); + $this->friendlyError(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $transactions)); return; } @@ -209,7 +212,7 @@ class FixAccountTypes extends Command if (!array_key_exists($type, $this->expected)) { 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->friendlyError(sprintf('No source/destination info for transaction type %s.', $type)); return; } diff --git a/app/Console/Commands/Correction/FixFrontpageAccounts.php b/app/Console/Commands/Correction/FixFrontpageAccounts.php index 970d570acb..ab336f09d8 100644 --- a/app/Console/Commands/Correction/FixFrontpageAccounts.php +++ b/app/Console/Commands/Correction/FixFrontpageAccounts.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\AccountType; use FireflyIII\Models\Preference; use FireflyIII\Repositories\Account\AccountRepositoryInterface; @@ -36,6 +37,8 @@ use Illuminate\Console\Command; */ class FixFrontpageAccounts extends Command { + use ShowsFriendlyMessages; + protected $description = 'Fixes a preference that may include deleted accounts or accounts of another type.'; protected $signature = 'firefly-iii:fix-frontpage-accounts'; @@ -54,7 +57,7 @@ class FixFrontpageAccounts extends Command $this->fixPreference($preference); } } - $this->info('Correct: account preferences are OK'); + $this->friendlyPositive('Account preferences are OK'); return 0; } diff --git a/app/Console/Commands/Correction/FixGroupAccounts.php b/app/Console/Commands/Correction/FixGroupAccounts.php index d2634990e0..9ddb1cddf6 100644 --- a/app/Console/Commands/Correction/FixGroupAccounts.php +++ b/app/Console/Commands/Correction/FixGroupAccounts.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; use DB; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Events\UpdatedTransactionGroup; use FireflyIII\Handlers\Events\UpdatedGroupEventHandler; use FireflyIII\Models\TransactionGroup; @@ -36,6 +37,8 @@ use Illuminate\Console\Command; */ class FixGroupAccounts extends Command { + use ShowsFriendlyMessages; + protected $description = 'Unify the source / destination accounts of split groups.'; protected $signature = 'firefly-iii:unify-group-accounts'; @@ -62,7 +65,7 @@ class FixGroupAccounts extends Command $handler->unifyAccounts($event); } - $this->info('Correct: updated possible inconsistent transaction groups.'); + $this->friendlyPositive('Updated possible inconsistent transaction groups.'); return 0; } diff --git a/app/Console/Commands/Correction/FixIbans.php b/app/Console/Commands/Correction/FixIbans.php index ea8fb18154..893dcd45be 100644 --- a/app/Console/Commands/Correction/FixIbans.php +++ b/app/Console/Commands/Correction/FixIbans.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use Illuminate\Console\Command; @@ -34,6 +35,8 @@ use Illuminate\Support\Collection; */ class FixIbans extends Command { + use ShowsFriendlyMessages; + protected $description = 'Removes spaces from IBANs'; protected $signature = 'firefly-iii:fix-ibans'; private int $count = 0; @@ -49,7 +52,7 @@ class FixIbans extends Command $this->filterIbans($accounts); $this->countAndCorrectIbans($accounts); if (0 === $this->count) { - $this->info('Correct: All IBANs are valid.'); + $this->friendlyPositive('All IBANs are valid.'); } return 0; @@ -82,7 +85,7 @@ class FixIbans extends Command && // allowed combination !(AccountType::REVENUE === $set[$userId][$iban] && AccountType::EXPENSE === $type) // also allowed combination. ) { - $this->line( + $this->friendlyWarning( sprintf( 'IBAN "%s" is used more than once and will be removed from %s #%d ("%s")', $iban, @@ -118,7 +121,7 @@ class FixIbans extends Command if ('' !== $iban) { $account->iban = $iban; $account->save(); - $this->line(sprintf('Removed spaces from IBAN of account #%d', $account->id)); + $this->friendlyInfo(sprintf('Removed spaces from IBAN of account #%d', $account->id)); $this->count++; } } diff --git a/app/Console/Commands/Correction/FixLongDescriptions.php b/app/Console/Commands/Correction/FixLongDescriptions.php index e08b78531f..d9a2a04144 100644 --- a/app/Console/Commands/Correction/FixLongDescriptions.php +++ b/app/Console/Commands/Correction/FixLongDescriptions.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionJournal; use Illuminate\Console\Command; @@ -33,6 +34,8 @@ use Illuminate\Console\Command; */ class FixLongDescriptions extends Command { + use ShowsFriendlyMessages; + private const MAX_LENGTH = 1000; protected $description = 'Fixes long descriptions in journals and groups.'; protected $signature = 'firefly-iii:fix-long-descriptions'; @@ -51,7 +54,7 @@ class FixLongDescriptions extends Command if (strlen($journal->description) > self::MAX_LENGTH) { $journal->description = substr($journal->description, 0, self::MAX_LENGTH); $journal->save(); - $this->line(sprintf('Truncated description of transaction journal #%d', $journal->id)); + $this->friendlyWarning(sprintf('Truncated description of transaction journal #%d', $journal->id)); $count++; } } @@ -62,12 +65,12 @@ class FixLongDescriptions extends Command if (strlen((string)$group->title) > self::MAX_LENGTH) { $group->title = substr($group->title, 0, self::MAX_LENGTH); $group->save(); - $this->line(sprintf('Truncated description of transaction group #%d', $group->id)); + $this->friendlyWarning(sprintf('Truncated description of transaction group #%d', $group->id)); $count++; } } if (0 === $count) { - $this->info('Correct: all transaction group and journal title lengths are within bounds.'); + $this->friendlyPositive('All transaction group and journal title lengths are within bounds.'); } return 0; diff --git a/app/Console/Commands/Correction/FixPiggies.php b/app/Console/Commands/Correction/FixPiggies.php index d1f871f040..8e15fc700a 100644 --- a/app/Console/Commands/Correction/FixPiggies.php +++ b/app/Console/Commands/Correction/FixPiggies.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\PiggyBankEvent; use FireflyIII\Models\TransactionJournal; use Illuminate\Console\Command; @@ -34,6 +35,8 @@ use Illuminate\Console\Command; */ class FixPiggies extends Command { + use ShowsFriendlyMessages; + protected $description = 'Fixes common issues with piggy banks.'; protected $signature = 'firefly-iii:fix-piggies'; @@ -63,10 +66,10 @@ class FixPiggies extends Command } } if (0 === $count) { - $this->info('Correct: all piggy bank events are OK.'); + $this->friendlyPositive('All piggy bank events are OK.'); } if (0 !== $count) { - $this->line(sprintf('Fixed %d piggy bank event(s).', $count)); + $this->friendlyInfo(sprintf('Fixed %d piggy bank event(s).', $count)); } return 0; diff --git a/app/Console/Commands/Correction/FixRecurringTransactions.php b/app/Console/Commands/Correction/FixRecurringTransactions.php index 07bcabe907..af9ed0b1ce 100644 --- a/app/Console/Commands/Correction/FixRecurringTransactions.php +++ b/app/Console/Commands/Correction/FixRecurringTransactions.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Recurrence; use FireflyIII\Models\RecurrenceTransaction; use FireflyIII\Models\TransactionType; @@ -37,6 +38,8 @@ use Illuminate\Console\Command; */ class FixRecurringTransactions extends Command { + use ShowsFriendlyMessages; + protected $description = 'Fixes recurring transactions with the wrong transaction type.'; protected $signature = 'firefly-iii:fix-recurring-transactions'; private int $count = 0; @@ -53,7 +56,7 @@ class FixRecurringTransactions extends Command $this->stupidLaravel(); $this->correctTransactions(); if (0 === $this->count) { - $this->info('Correct: all recurring transactions are OK.'); + $this->friendlyPositive('All recurring transactions are OK.'); } return 0; @@ -93,7 +96,7 @@ class FixRecurringTransactions extends Command $type = $recurrence->transactionType; $link = config(sprintf('firefly.account_to_transaction.%s.%s', $source->accountType->type, $destination->accountType->type)); if (null !== $link && strtolower($type->type) !== strtolower($link)) { - $this->warn( + $this->friendlyWarning( sprintf('Recurring transaction #%d should be a "%s" but is a "%s" and will be corrected.', $recurrence->id, $link, $type->type) ); $transactionType = TransactionType::whereType($link)->first(); diff --git a/app/Console/Commands/Correction/FixTransactionTypes.php b/app/Console/Commands/Correction/FixTransactionTypes.php index 3fb5fa4f6e..b4b88b18c4 100644 --- a/app/Console/Commands/Correction/FixTransactionTypes.php +++ b/app/Console/Commands/Correction/FixTransactionTypes.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\Transaction; @@ -37,6 +38,8 @@ use Illuminate\Support\Collection; */ class FixTransactionTypes extends Command { + use ShowsFriendlyMessages; + protected $description = 'Make sure all transactions are of the correct type, based on source + dest.'; protected $signature = 'firefly-iii:fix-transaction-types'; @@ -57,11 +60,11 @@ class FixTransactionTypes extends Command } } if ($count > 0) { - $this->info('Corrected transaction type of %d transaction journals.', $count); + $this->friendlyInfo('Corrected transaction type of %d transaction journals.', $count); return 0; } - $this->info('Correct: all transaction journals are of the correct transaction type'); + $this->friendlyPositive('All transaction journals are of the correct transaction type'); return 0; } @@ -102,13 +105,13 @@ class FixTransactionTypes extends Command $source = $this->getSourceAccount($journal); $destination = $this->getDestinationAccount($journal); } catch (FireflyException $e) { - $this->error($e->getMessage()); + $this->friendlyError($e->getMessage()); return false; } $expectedType = (string)config(sprintf('firefly.account_to_transaction.%s.%s', $source->accountType->type, $destination->accountType->type)); if ($expectedType !== $type) { - $this->line( + $this->friendlyWarning( sprintf( 'Transaction journal #%d was of type "%s" but is corrected to "%s" (%s -> %s)', $journal->id, diff --git a/app/Console/Commands/Correction/FixUnevenAmount.php b/app/Console/Commands/Correction/FixUnevenAmount.php index 95215fd5f9..3a94018bdf 100644 --- a/app/Console/Commands/Correction/FixUnevenAmount.php +++ b/app/Console/Commands/Correction/FixUnevenAmount.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; use DB; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use Illuminate\Console\Command; @@ -34,6 +35,8 @@ use stdClass; */ class FixUnevenAmount extends Command { + use ShowsFriendlyMessages; + protected $description = 'Fix journals with uneven amounts.'; protected $signature = 'firefly-iii:fix-uneven-amount'; @@ -54,21 +57,21 @@ class FixUnevenAmount extends Command $sum = (string)$entry->the_sum; if (!is_numeric($sum)) { $message = sprintf('Journal #%d has an invalid sum ("%s"). No sure what to do.', $entry->transaction_journal_id, $entry->the_sum); - $this->warn($message); + $this->friendlyWarning($message); app('log')->warning($message); $count++; continue; } if (0 !== bccomp((string)$entry->the_sum, '0')) { $message = sprintf('Sum of journal #%d is %s instead of zero.', $entry->transaction_journal_id, $entry->the_sum); - $this->warn($message); + $this->friendlyWarning($message); app('log')->warning($message); $this->fixJournal((int)$entry->transaction_journal_id); $count++; } } if (0 === $count) { - $this->info('Correct: Database amount integrity is OK'); + $this->friendlyPositive('Database amount integrity is OK'); } return 0; @@ -88,7 +91,7 @@ class FixUnevenAmount extends Command $source = $journal->transactions()->where('amount', '<', 0)->first(); if (null === $source) { - $this->error( + $this->friendlyError( sprintf( 'Journal #%d ("%s") has no source transaction. It will be deleted to maintain database consistency.', $journal->id ?? 0, @@ -108,7 +111,7 @@ class FixUnevenAmount extends Command $destination = $journal->transactions()->where('amount', '>', 0)->first(); if (null === $destination) { - $this->error( + $this->friendlyError( sprintf( 'Journal #%d ("%s") has no destination transaction. It will be deleted to maintain database consistency.', $journal->id ?? 0, @@ -126,6 +129,6 @@ class FixUnevenAmount extends Command $destination->save(); $message = sprintf('Corrected amount in transaction journal #%d', $param); - $this->line($message); + $this->friendlyInfo($message); } } diff --git a/app/Console/Commands/Correction/RemoveBills.php b/app/Console/Commands/Correction/RemoveBills.php index 227d0367b1..a68ad038b4 100644 --- a/app/Console/Commands/Correction/RemoveBills.php +++ b/app/Console/Commands/Correction/RemoveBills.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; use Illuminate\Console\Command; @@ -32,6 +33,8 @@ use Illuminate\Console\Command; */ class RemoveBills extends Command { + use ShowsFriendlyMessages; + protected $description = 'Remove bills from transactions that shouldn\'t have one.'; protected $signature = 'firefly-iii:remove-bills'; @@ -50,14 +53,14 @@ class RemoveBills extends Command $journals = TransactionJournal::whereNotNull('bill_id')->where('transaction_type_id', '!=', $withdrawal->id)->get(); /** @var TransactionJournal $journal */ foreach ($journals as $journal) { - $this->line(sprintf('Transaction journal #%d should not be linked to bill #%d.', $journal->id, $journal->bill_id)); + $this->friendlyWarning(sprintf('Transaction journal #%d will be unlinked from bill #%d.', $journal->id, $journal->bill_id)); $journal->bill_id = null; $journal->save(); } if ($journals->count() > 0) { - $this->info('Fixed all transaction journals so they have correct bill information.'); + $this->friendlyInfo('Fixed all transaction journals so they have correct bill information.'); } - $this->info('Correct: verified bills / journals in %s seconds'); + $this->friendlyPositive('All bills and journals are OK'); return 0; } diff --git a/app/Console/Commands/Correction/RenameMetaFields.php b/app/Console/Commands/Correction/RenameMetaFields.php index d8d4c09dc6..97da4e8692 100644 --- a/app/Console/Commands/Correction/RenameMetaFields.php +++ b/app/Console/Commands/Correction/RenameMetaFields.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; use DB; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use Illuminate\Console\Command; /** @@ -31,6 +32,8 @@ use Illuminate\Console\Command; */ class RenameMetaFields extends Command { + use ShowsFriendlyMessages; + protected $description = 'Rename changed meta fields.'; protected $signature = 'firefly-iii:rename-meta-fields'; @@ -63,10 +66,10 @@ class RenameMetaFields extends Command $this->rename($original, $update); } if (0 === $this->count) { - $this->info('Correct: all meta fields are correct.'); + $this->friendlyPositive('All meta fields are correct.'); } if (0 !== $this->count) { - $this->info(sprintf('Renamed %d meta field(s).', $this->count)); + $this->friendlyInfo(sprintf('Renamed %d meta field(s).', $this->count)); } return 0; } diff --git a/app/Console/Commands/Correction/TransferBudgets.php b/app/Console/Commands/Correction/TransferBudgets.php index b6ad50ae35..12372a57ef 100644 --- a/app/Console/Commands/Correction/TransferBudgets.php +++ b/app/Console/Commands/Correction/TransferBudgets.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; use Illuminate\Console\Command; @@ -33,6 +34,8 @@ use Illuminate\Support\Facades\Log; */ class TransferBudgets extends Command { + use ShowsFriendlyMessages; + protected $description = 'Removes budgets from transfers.'; protected $signature = 'firefly-iii:fix-transfer-budgets'; @@ -52,19 +55,19 @@ class TransferBudgets extends Command /** @var TransactionJournal $entry */ foreach ($set as $entry) { $message = sprintf('Transaction journal #%d is a %s, so has no longer a budget.', $entry->id, $entry->transactionType->type); - $this->info($message); + $this->friendlyInfo($message); Log::debug($message); $entry->budgets()->sync([]); $count++; } if (0 === $count) { - $message = 'Correct: no invalid budget/journal entries.'; - $this->info($message); + $message = 'No invalid budget/journal entries.'; + $this->friendlyPositive($message); } if (0 !== $count) { $message = sprintf('Corrected %d invalid budget/journal entries (entry).', $count); Log::debug($message); - $this->line($message); + $this->friendlyInfo($message); } return 0; } diff --git a/app/Console/Commands/Export/ExportData.php b/app/Console/Commands/Export/ExportData.php index 262768ae91..9c0ca5b840 100644 --- a/app/Console/Commands/Export/ExportData.php +++ b/app/Console/Commands/Export/ExportData.php @@ -26,6 +26,7 @@ namespace FireflyIII\Console\Commands\Export; use Carbon\Carbon; use Exception; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; @@ -43,6 +44,7 @@ use Illuminate\Support\Facades\Log; */ class ExportData extends Command { + use ShowsFriendlyMessages; use VerifiesAccessToken; /** @@ -86,7 +88,7 @@ class ExportData extends Command { // verify access token if (!$this->verifyAccessToken()) { - $this->error('Invalid access token. Check /profile.'); + $this->friendlyError('Invalid access token. Check /profile.'); return 1; } @@ -99,7 +101,7 @@ class ExportData extends Command try { $options = $this->parseOptions(); } catch (FireflyException $e) { - $this->error(sprintf('Could not work with your options: %s', $e)); + $this->friendlyError(sprintf('Could not work with your options: %s', $e)); return 1; } @@ -122,14 +124,14 @@ class ExportData extends Command $exporter->setExportPiggies($options['export']['piggies']); $data = $exporter->export(); if (0 === count($data)) { - $this->error('You must export *something*. Use --export-transactions or another option. See docs.firefly-iii.org'); + $this->friendlyError('You must export *something*. Use --export-transactions or another option. See docs.firefly-iii.org'); } $returnCode = 0; if (0 !== count($data)) { try { $this->exportData($options, $data); } catch (FireflyException $e) { - $this->error(sprintf('Could not store data: %s', $e->getMessage())); + $this->friendlyError(sprintf('Could not store data: %s', $e->getMessage())); $returnCode = 1; } @@ -139,16 +141,116 @@ class ExportData extends Command } /** - * Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is - * executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should - * be called from the handle method instead of using the constructor to initialize the command. + * @param array $options + * @param array $data * - + * @throws FireflyException */ - private function stupidLaravel(): void + private function exportData(array $options, array $data): void { - $this->journalRepository = app(JournalRepositoryInterface::class); - $this->accountRepository = app(AccountRepositoryInterface::class); + $date = date('Y_m_d'); + foreach ($data as $key => $content) { + $file = sprintf('%s%s_%s.csv', $options['directory'], $date, $key); + if (false === $options['force'] && file_exists($file)) { + throw new FireflyException(sprintf('File "%s" exists already. Use --force to overwrite.', $file)); + } + if (true === $options['force'] && file_exists($file)) { + $this->friendlyWarning(sprintf('File "%s" exists already but will be replaced.', $file)); + } + // continue to write to file. + file_put_contents($file, $content); + $this->friendlyPositive(sprintf('Wrote %s-export to file "%s".', $key, $file)); + } + } + + /** + * @return Collection + * @throws FireflyException + */ + private function getAccountsParameter(): Collection + { + $final = new Collection(); + $accounts = new Collection(); + $accountList = $this->option('accounts'); + $types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; + if (null !== $accountList && '' !== (string)$accountList) { + $accountIds = explode(',', $accountList); + $accounts = $this->accountRepository->getAccountsById($accountIds); + } + if (null === $accountList) { + $accounts = $this->accountRepository->getAccountsByType($types); + } + // filter accounts, + /** @var Account $account */ + foreach ($accounts as $account) { + if (in_array($account->accountType->type, $types, true)) { + $final->push($account); + } + } + if (0 === $final->count()) { + throw new FireflyException('300007: Ended up with zero valid accounts to export from.'); + } + + return $final; + } + + /** + * @param string $field + * + * @return Carbon + * @throws Exception + */ + private function getDateParameter(string $field): Carbon + { + $date = today(config('app.timezone'))->subYear(); + $error = false; + if (null !== $this->option($field)) { + try { + $date = Carbon::createFromFormat('!Y-m-d', $this->option($field)); + } catch (InvalidArgumentException $e) { + Log::error($e->getMessage()); + $this->friendlyError(sprintf('%s date "%s" must be formatted YYYY-MM-DD. Field will be ignored.', $field, $this->option('start'))); + $error = true; + } + } + if (null === $this->option($field)) { + Log::info(sprintf('No date given in field "%s"', $field)); + $error = true; + } + + if (true === $error && 'start' === $field) { + $journal = $this->journalRepository->firstNull(); + $date = null === $journal ? today(config('app.timezone'))->subYear() : $journal->date; + $date->startOfDay(); + } + + if (true === $error && 'end' === $field) { + $date = today(config('app.timezone')); + $date->endOfDay(); + } + if ('end' === $field) { + $date->endOfDay(); + } + + return $date; + } + + /** + * @return string + * @throws FireflyException + * + */ + private function getExportDirectory(): string + { + $directory = (string)$this->option('export_directory'); + if (null === $directory) { + $directory = './'; + } + if (!is_writable($directory)) { + throw new FireflyException(sprintf('Directory "%s" isn\'t writeable.', $directory)); + } + + return $directory; } /** @@ -184,115 +286,15 @@ class ExportData extends Command } /** - * @param string $field + * Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is + * executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should + * be called from the handle method instead of using the constructor to initialize the command. * - * @return Carbon - * @throws Exception + */ - private function getDateParameter(string $field): Carbon + private function stupidLaravel(): void { - $date = today(config('app.timezone'))->subYear(); - $error = false; - if (null !== $this->option($field)) { - try { - $date = Carbon::createFromFormat('!Y-m-d', $this->option($field)); - } catch (InvalidArgumentException $e) { - Log::error($e->getMessage()); - $this->error(sprintf('%s date "%s" must be formatted YYYY-MM-DD. Field will be ignored.', $field, $this->option('start'))); - $error = true; - } - } - if (null === $this->option($field)) { - Log::info(sprintf('No date given in field "%s"', $field)); - $error = true; - } - - if (true === $error && 'start' === $field) { - $journal = $this->journalRepository->firstNull(); - $date = null === $journal ? today(config('app.timezone'))->subYear() : $journal->date; - $date->startOfDay(); - } - - if (true === $error && 'end' === $field) { - $date = today(config('app.timezone')); - $date->endOfDay(); - } - if ('end' === $field) { - $date->endOfDay(); - } - - return $date; - } - - /** - * @return Collection - * @throws FireflyException - */ - private function getAccountsParameter(): Collection - { - $final = new Collection(); - $accounts = new Collection(); - $accountList = $this->option('accounts'); - $types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; - if (null !== $accountList && '' !== (string)$accountList) { - $accountIds = explode(',', $accountList); - $accounts = $this->accountRepository->getAccountsById($accountIds); - } - if (null === $accountList) { - $accounts = $this->accountRepository->getAccountsByType($types); - } - // filter accounts, - /** @var Account $account */ - foreach ($accounts as $account) { - if (in_array($account->accountType->type, $types, true)) { - $final->push($account); - } - } - if (0 === $final->count()) { - throw new FireflyException('300007: Ended up with zero valid accounts to export from.'); - } - - return $final; - } - - /** - * @return string - * @throws FireflyException - * - */ - private function getExportDirectory(): string - { - $directory = (string)$this->option('export_directory'); - if (null === $directory) { - $directory = './'; - } - if (!is_writable($directory)) { - throw new FireflyException(sprintf('Directory "%s" isn\'t writeable.', $directory)); - } - - return $directory; - } - - /** - * @param array $options - * @param array $data - * - * @throws FireflyException - */ - private function exportData(array $options, array $data): void - { - $date = date('Y_m_d'); - foreach ($data as $key => $content) { - $file = sprintf('%s%s_%s.csv', $options['directory'], $date, $key); - if (false === $options['force'] && file_exists($file)) { - throw new FireflyException(sprintf('File "%s" exists already. Use --force to overwrite.', $file)); - } - if (true === $options['force'] && file_exists($file)) { - $this->warn(sprintf('File "%s" exists already but will be replaced.', $file)); - } - // continue to write to file. - file_put_contents($file, $content); - $this->info(sprintf('Wrote %s-export to file "%s".', $key, $file)); - } + $this->journalRepository = app(JournalRepositoryInterface::class); + $this->accountRepository = app(AccountRepositoryInterface::class); } } diff --git a/app/Console/Commands/Integrity/CreateGroupMemberships.php b/app/Console/Commands/Integrity/CreateGroupMemberships.php index 9850e37d3f..4a621000b2 100644 --- a/app/Console/Commands/Integrity/CreateGroupMemberships.php +++ b/app/Console/Commands/Integrity/CreateGroupMemberships.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Integrity; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\GroupMembership; use FireflyIII\Models\UserGroup; @@ -37,6 +38,8 @@ use Illuminate\Support\Facades\Log; */ class CreateGroupMemberships extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '560_create_group_memberships'; protected $description = 'Update group memberships'; protected $signature = 'firefly-iii:create-group-memberships'; @@ -88,7 +91,7 @@ class CreateGroupMemberships extends Command public function handle(): int { $this->createGroupMemberships(); - $this->info('Correct: validated group memberships'); + $this->friendlyPositive('Validated group memberships'); return 0; } diff --git a/app/Console/Commands/Integrity/ReportEmptyObjects.php b/app/Console/Commands/Integrity/ReportEmptyObjects.php index 18424eb281..85762f45c9 100644 --- a/app/Console/Commands/Integrity/ReportEmptyObjects.php +++ b/app/Console/Commands/Integrity/ReportEmptyObjects.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Integrity; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Account; use FireflyIII\Models\Budget; use FireflyIII\Models\Category; @@ -35,6 +36,8 @@ use stdClass; */ class ReportEmptyObjects extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -81,7 +84,7 @@ class ReportEmptyObjects extends Command foreach ($set as $entry) { $line = 'User #%d (%s) has account #%d ("%s") which has no transactions.'; $line = sprintf($line, $entry->user_id, $entry->email, $entry->id, $entry->name); - $this->line($line); + $this->friendlyWarning($line); } } @@ -105,7 +108,7 @@ class ReportEmptyObjects extends Command $entry->id, $entry->name ); - $this->line($line); + $this->friendlyWarning($line); } } @@ -130,7 +133,7 @@ class ReportEmptyObjects extends Command $entry->id, $entry->name ); - $this->line($line); + $this->friendlyWarning($line); } } @@ -155,7 +158,7 @@ class ReportEmptyObjects extends Command $entry->id, $entry->name ); - $this->line($line); + $this->friendlyWarning($line); } } @@ -180,7 +183,7 @@ class ReportEmptyObjects extends Command $entry->id, $entry->tag ); - $this->line($line); + $this->friendlyWarning($line); } } } diff --git a/app/Console/Commands/Integrity/ReportIntegrity.php b/app/Console/Commands/Integrity/ReportIntegrity.php index 7a7cf86ce3..5075e69ea9 100644 --- a/app/Console/Commands/Integrity/ReportIntegrity.php +++ b/app/Console/Commands/Integrity/ReportIntegrity.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Integrity; use Artisan; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use Illuminate\Console\Command; use Schema; @@ -34,6 +35,8 @@ use Schema; */ class ReportIntegrity extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -63,7 +66,7 @@ class ReportIntegrity extends Command 'firefly-iii:upgrade-group-information', ]; foreach ($commands as $command) { - $this->line(sprintf('Now executing %s', $command)); + $this->friendlyLine(sprintf('Now executing %s', $command)); $this->call($command); } diff --git a/app/Console/Commands/Integrity/ReportSum.php b/app/Console/Commands/Integrity/ReportSum.php index 2e245218cd..9dc5192edf 100644 --- a/app/Console/Commands/Integrity/ReportSum.php +++ b/app/Console/Commands/Integrity/ReportSum.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Integrity; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Illuminate\Console\Command; @@ -32,6 +33,8 @@ use Illuminate\Console\Command; */ class ReportSum extends Command { + use ShowsFriendlyMessages; + protected $description = 'Report on the total sum of transactions. Must be 0.'; protected $signature = 'firefly-iii:report-sum'; @@ -60,15 +63,15 @@ class ReportSum extends Command $sum = (string)$user->transactions()->sum('amount'); if (!is_numeric($sum)) { $message = sprintf('Error: Transactions for user #%d (%s) have an invalid sum ("%s").', $user->id, $user->email, $sum); - $this->error($message); + $this->friendlyError($message); continue; } if (0 !== bccomp($sum, '0')) { $message = sprintf('Error: Transactions for user #%d (%s) are off by %s!', $user->id, $user->email, $sum); - $this->error($message); + $this->friendlyError($message); } if (0 === bccomp($sum, '0')) { - $this->info(sprintf('Correct: Amount integrity OK for user #%d', $user->id)); + $this->friendlyPositive(sprintf('Amount integrity OK for user #%d', $user->id)); } } } diff --git a/app/Console/Commands/Integrity/RestoreOAuthKeys.php b/app/Console/Commands/Integrity/RestoreOAuthKeys.php index 49f0f915d7..d9c3ecd859 100644 --- a/app/Console/Commands/Integrity/RestoreOAuthKeys.php +++ b/app/Console/Commands/Integrity/RestoreOAuthKeys.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Integrity; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Support\System\OAuthKeys; use Illuminate\Console\Command; @@ -32,6 +33,8 @@ use Illuminate\Console\Command; */ class RestoreOAuthKeys extends Command { + use ShowsFriendlyMessages; + protected $description = 'Will restore the OAuth keys generated for the system.'; protected $signature = 'firefly-iii:restore-oauth-keys'; @@ -87,30 +90,30 @@ class RestoreOAuthKeys extends Command if (!$this->keysInDatabase() && !$this->keysOnDrive()) { $this->generateKeys(); $this->storeKeysInDB(); - $this->line('Correct: generated and stored new keys.'); + $this->friendlyInfo('Generated and stored new keys.'); return; } if ($this->keysInDatabase() && !$this->keysOnDrive()) { $result = $this->restoreKeysFromDB(); if (true === $result) { - $this->line('Correct: restored OAuth keys from database.'); + $this->friendlyInfo('Restored OAuth keys from database.'); return; } $this->generateKeys(); $this->storeKeysInDB(); - $this->line('Correct: generated and stored new keys.'); + $this->friendlyInfo('Generated and stored new keys.'); return; } if (!$this->keysInDatabase() && $this->keysOnDrive()) { $this->storeKeysInDB(); - $this->line('Correct: stored OAuth keys in database.'); + $this->friendlyInfo('Stored OAuth keys in database.'); return; } - $this->line('Correct: OAuth keys are OK'); + $this->friendlyPositive('OAuth keys are OK'); } /** diff --git a/app/Console/Commands/Integrity/UpdateGroupInformation.php b/app/Console/Commands/Integrity/UpdateGroupInformation.php index f2ad93f02c..75b8c1b6a1 100644 --- a/app/Console/Commands/Integrity/UpdateGroupInformation.php +++ b/app/Console/Commands/Integrity/UpdateGroupInformation.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Integrity; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Account; use FireflyIII\Models\Attachment; use FireflyIII\Models\AvailableBudget; @@ -48,6 +49,8 @@ use Illuminate\Database\QueryException; */ class UpdateGroupInformation extends Command { + use ShowsFriendlyMessages; + protected $description = 'Makes sure that every object is linked to a group'; protected $signature = 'firefly-iii:upgrade-group-information'; @@ -74,7 +77,7 @@ class UpdateGroupInformation extends Command { $group = $user->userGroup; if (null === $group) { - $this->warn(sprintf('User "%s" has no group.', $user->email)); + $this->friendlyWarning(sprintf('User "%s" has no group.', $user->email)); return; } @@ -111,12 +114,12 @@ class UpdateGroupInformation extends Command try { $result = $className::where('user_id', $user->id)->where('user_group_id', null)->update(['user_group_id' => $group->id]); } catch (QueryException $e) { - $this->error(sprintf('Could not update group information for "%s" because of error "%s"', $className, $e->getMessage())); + $this->friendlyError(sprintf('Could not update group information for "%s" because of error "%s"', $className, $e->getMessage())); return; } if (0 !== $result) { - $this->info(sprintf('Correct: Moved %d %s objects to the correct group.', $result, str_replace('FireflyIII\\Models\\', '', $className))); + $this->friendlyPositive(sprintf('Moved %d %s objects to the correct group.', $result, str_replace('FireflyIII\\Models\\', '', $className))); } } } diff --git a/app/Console/Commands/ShowsFriendlyMessages.php b/app/Console/Commands/ShowsFriendlyMessages.php new file mode 100644 index 0000000000..06383336b1 --- /dev/null +++ b/app/Console/Commands/ShowsFriendlyMessages.php @@ -0,0 +1,83 @@ +. + */ + +namespace FireflyIII\Console\Commands; + +/** + * Trait ShowsFriendlyMessages + */ +trait ShowsFriendlyMessages +{ + /** + * @param string $message + * @return void + */ + public function friendlyError(string $message): void + { + $this->error(sprintf(' [x] %s', trim($message))); + } + + /** + * @param string $message + * @return void + */ + public function friendlyInfo(string $message): void + { + $this->friendlyNeutral($message); + } + + /** + * @param string $message + * @return void + */ + public function friendlyLine(string $message): void + { + $this->line(sprintf(' %s', trim($message))); + } + + /** + * @param string $message + * @return void + */ + public function friendlyNeutral(string $message): void + { + $this->line(sprintf(' [i] %s', trim($message))); + } + + /** + * @param string $message + * @return void + */ + public function friendlyPositive(string $message): void + { + $this->info(sprintf(' [✓] %s', trim($message))); + } + + /** + * @param string $message + * @return void + */ + public function friendlyWarning(string $message): void + { + $this->warn(sprintf(' [!] %s', trim($message))); + } + +} diff --git a/app/Console/Commands/System/CreateDatabase.php b/app/Console/Commands/System/CreateDatabase.php index 0022e02a4e..b34914e310 100644 --- a/app/Console/Commands/System/CreateDatabase.php +++ b/app/Console/Commands/System/CreateDatabase.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\System; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use Illuminate\Console\Command; use PDO; use PDOException; @@ -33,6 +34,8 @@ use PDOException; */ class CreateDatabase extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -54,7 +57,7 @@ class CreateDatabase extends Command public function handle(): int { if ('mysql' !== env('DB_CONNECTION', 'mysql')) { - $this->info(sprintf('CreateDB does not apply to "%s", skipped.', env('DB_CONNECTION'))); + $this->friendlyInfo(sprintf('CreateDB does not apply to "%s", skipped.', env('DB_CONNECTION'))); return 0; } @@ -67,7 +70,7 @@ class CreateDatabase extends Command if ('' !== env('DB_SOCKET', '')) { $dsn = sprintf('mysql:unix_socket=%s;charset=utf8mb4', env('DB_SOCKET', '')); } - $this->info(sprintf('DSN is %s', $dsn)); + $this->friendlyLine(sprintf('DSN is %s', $dsn)); $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, @@ -79,7 +82,7 @@ class CreateDatabase extends Command try { $pdo = new PDO($dsn, env('DB_USERNAME'), env('DB_PASSWORD'), $options); } catch (PDOException $e) { - $this->error(sprintf('Error when connecting to DB: %s', $e->getMessage())); + $this->friendlyError(sprintf('Error when connecting to DB: %s', $e->getMessage())); } // only continue when no error. @@ -96,14 +99,14 @@ class CreateDatabase extends Command } } if (false === $exists && true === $checked) { - $this->error(sprintf('Database "%s" does not exist.', env('DB_DATABASE'))); + $this->friendlyError(sprintf('Database "%s" does not exist.', env('DB_DATABASE'))); // try to create it. $pdo->exec(sprintf('CREATE DATABASE `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;', env('DB_DATABASE'))); - $this->info(sprintf('Created database "%s"', env('DB_DATABASE'))); + $this->friendlyInfo(sprintf('Created database "%s"', env('DB_DATABASE'))); } if (true === $exists && true === $checked) { - $this->info(sprintf('Database "%s" exists.', env('DB_DATABASE'))); + $this->friendlyInfo(sprintf('Database "%s" exists.', env('DB_DATABASE'))); } return 0; diff --git a/app/Console/Commands/System/CreateFirstUser.php b/app/Console/Commands/System/CreateFirstUser.php index 96a48da85f..a547a3e47a 100644 --- a/app/Console/Commands/System/CreateFirstUser.php +++ b/app/Console/Commands/System/CreateFirstUser.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\System; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Repositories\User\UserRepositoryInterface; use Illuminate\Console\Command; use Illuminate\Support\Facades\Hash; @@ -36,6 +37,8 @@ use Str; */ class CreateFirstUser extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -58,14 +61,14 @@ class CreateFirstUser extends Command public function handle(): int { if ('testing' !== env('APP_ENV', 'local')) { - $this->error('This command only works in the testing environment.'); + $this->friendlyError('This command only works in the testing environment.'); return 1; } $this->stupidLaravel(); $count = $this->repository->count(); if ($count > 0) { - $this->error('Already have more than zero users in DB.'); + $this->friendlyError('Already have more than zero users in DB.'); return 1; } @@ -81,8 +84,8 @@ class CreateFirstUser extends Command $user->save(); $user->setRememberToken(Str::random(60)); - $this->info(sprintf('Created new admin user (ID #%d) with email address "%s" and password "%s".', $user->id, $user->email, $password)); - $this->error('Change this password.'); + $this->friendlyInfo(sprintf('Created new admin user (ID #%d) with email address "%s" and password "%s".', $user->id, $user->email, $password)); + $this->friendlyWarning('Change this password.'); return 0; } diff --git a/app/Console/Commands/System/ForceDecimalSize.php b/app/Console/Commands/System/ForceDecimalSize.php index 211251c743..d38c1405b9 100644 --- a/app/Console/Commands/System/ForceDecimalSize.php +++ b/app/Console/Commands/System/ForceDecimalSize.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\System; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\AutoBudget; @@ -51,6 +52,8 @@ use Illuminate\Support\Facades\Log; */ class ForceDecimalSize extends Command { + use ShowsFriendlyMessages; + protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).'; protected $signature = 'firefly-iii:force-decimal-size'; private string $cast; @@ -96,8 +99,8 @@ class ForceDecimalSize extends Command Log::debug('Now in ForceDecimalSize::handle()'); $this->determineDatabaseType(); - $this->error('Running this command is dangerous and can cause data loss.'); - $this->error('Please do not continue.'); + $this->friendlyError('Running this command is dangerous and can cause data loss.'); + $this->friendlyError('Please do not continue.'); $question = $this->confirm('Do you want to continue?'); if (true === $question) { $this->correctAmounts(); @@ -136,7 +139,7 @@ class ForceDecimalSize extends Command }); $result = $query->get(['accounts.*']); if (0 === $result->count()) { - $this->line(sprintf('Correct: All accounts in %s', $currency->code)); + $this->friendlyPositive(sprintf('All accounts in %s are OK', $currency->code)); return; } @@ -150,7 +153,7 @@ class ForceDecimalSize extends Command // fix $field by rounding it down correctly. $pow = pow(10, (int)$currency->decimal_places); $correct = bcdiv((string)round($value * $pow), (string)$pow, 12); - $this->line(sprintf('Account #%d has %s with value "%s", this has been corrected to "%s".', $account->id, $field, $value, $correct)); + $this->friendlyInfo(sprintf('Account #%d has %s with value "%s", this has been corrected to "%s".', $account->id, $field, $value, $correct)); Account::find($account->id)->update([$field => $correct]); } } @@ -174,7 +177,7 @@ class ForceDecimalSize extends Command } if (!in_array((string)config('database.default'), ['mysql', 'pgsql', 'sqlite'], true)) { - $this->line(sprintf('Skip correcting amounts, does not support "%s"...', (string)config('database.default'))); + $this->friendlyWarning(sprintf('Skip correcting amounts, does not support "%s"...', (string)config('database.default'))); return; } @@ -188,7 +191,6 @@ class ForceDecimalSize extends Command */ private function correctAmountsByCurrency(): void { - $this->line('Going to correct amounts.'); /** @var Collection $enabled */ $enabled = TransactionCurrency::whereEnabled(1)->get(); /** @var TransactionCurrency $currency */ @@ -207,7 +209,6 @@ class ForceDecimalSize extends Command */ private function correctByCurrency(TransactionCurrency $currency): void { - $this->line(sprintf('Going to correct amounts in currency %s ("%s").', $currency->code, $currency->name)); /** * @var string $name * @var array $fields @@ -216,7 +217,7 @@ class ForceDecimalSize extends Command switch ($name) { default: $message = sprintf('Cannot handle table "%s"', $name); - $this->line($message); + $this->friendlyError($message); throw new FireflyException($message); case 'accounts': $this->correctAccountAmounts($currency, $fields); @@ -279,7 +280,7 @@ class ForceDecimalSize extends Command $result = $query->get(['*']); if (0 === $result->count()) { - $this->line(sprintf('Correct: All %s in %s', $table, $currency->code)); + $this->friendlyPositive(sprintf('All %s in %s are OK', $table, $currency->code)); return; } @@ -293,7 +294,7 @@ class ForceDecimalSize extends Command // fix $field by rounding it down correctly. $pow = pow(10, (int)$currency->decimal_places); $correct = bcdiv((string)round($value * $pow), (string)$pow, 12); - $this->line(sprintf('%s #%d has %s with value "%s", this has been corrected to "%s".', $table, $item->id, $field, $value, $correct)); + $this->friendlyWarning(sprintf('%s #%d has %s with value "%s", this has been corrected to "%s".', $table, $item->id, $field, $value, $correct)); $class::find($item->id)->update([$field => $correct]); } } @@ -330,7 +331,7 @@ class ForceDecimalSize extends Command $result = $query->get(['piggy_banks.*']); if (0 === $result->count()) { - $this->line(sprintf('Correct: All piggy banks in %s', $currency->code)); + $this->friendlyPositive(sprintf('All piggy banks in %s are OK', $currency->code)); return; } @@ -344,7 +345,7 @@ class ForceDecimalSize extends Command // fix $field by rounding it down correctly. $pow = pow(10, (int)$currency->decimal_places); $correct = bcdiv((string)round($value * $pow), (string)$pow, 12); - $this->line(sprintf('Piggy bank #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)); + $this->friendlyWarning(sprintf('Piggy bank #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)); PiggyBank::find($item->id)->update([$field => $correct]); } } @@ -382,7 +383,7 @@ class ForceDecimalSize extends Command $result = $query->get(['piggy_bank_events.*']); if (0 === $result->count()) { - $this->line(sprintf('Correct: All piggy bank events in %s', $currency->code)); + $this->friendlyPositive(sprintf('All piggy bank events in %s are OK', $currency->code)); return; } @@ -396,7 +397,9 @@ class ForceDecimalSize extends Command // fix $field by rounding it down correctly. $pow = pow(10, (int)$currency->decimal_places); $correct = bcdiv((string)round($value * $pow), (string)$pow, 12); - $this->line(sprintf('Piggy bank event #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)); + $this->friendlyWarning( + sprintf('Piggy bank event #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct) + ); PiggyBankEvent::find($item->id)->update([$field => $correct]); } } @@ -434,7 +437,7 @@ class ForceDecimalSize extends Command $result = $query->get(['piggy_bank_repetitions.*']); if (0 === $result->count()) { - $this->line(sprintf('Correct: All piggy bank repetitions in %s', $currency->code)); + $this->friendlyPositive(sprintf('All piggy bank repetitions in %s', $currency->code)); return; } @@ -448,7 +451,9 @@ class ForceDecimalSize extends Command // fix $field by rounding it down correctly. $pow = pow(10, (int)$currency->decimal_places); $correct = bcdiv((string)round($value * $pow), (string)$pow, 12); - $this->line(sprintf('Piggy bank repetition #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)); + $this->friendlyWarning( + sprintf('Piggy bank repetition #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct) + ); PiggyBankRepetition::find($item->id)->update([$field => $correct]); } } @@ -473,7 +478,7 @@ class ForceDecimalSize extends Command $result = $query->get(['transactions.*']); if (0 === $result->count()) { - $this->line(sprintf('Correct: All transactions in %s', $currency->code)); + $this->friendlyPositive(sprintf('All transactions in %s are OK', $currency->code)); } /** @var Transaction $item */ @@ -485,7 +490,7 @@ class ForceDecimalSize extends Command // fix $field by rounding it down correctly. $pow = pow(10, (int)$currency->decimal_places); $correct = bcdiv((string)round($value * $pow), (string)$pow, 12); - $this->line(sprintf('Transaction #%d has amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)); + $this->friendlyWarning(sprintf('Transaction #%d has amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)); Transaction::find($item->id)->update(['amount' => $correct]); } @@ -499,7 +504,7 @@ class ForceDecimalSize extends Command $result = $query->get(['*']); if (0 === $result->count()) { - $this->line(sprintf('Correct: All transactions in foreign currency %s', $currency->code)); + $this->friendlyPositive(sprintf('All transactions in foreign currency %s are OK', $currency->code)); return; } @@ -512,7 +517,9 @@ class ForceDecimalSize extends Command // fix $field by rounding it down correctly. $pow = pow(10, (int)$currency->decimal_places); $correct = bcdiv((string)round($value * $pow), (string)$pow, 12); - $this->line(sprintf('Transaction #%d has foreign amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)); + $this->friendlyWarning( + sprintf('Transaction #%d has foreign amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct) + ); Transaction::find($item->id)->update(['foreign_amount' => $correct]); } } @@ -538,7 +545,7 @@ class ForceDecimalSize extends Command */ private function updateDecimals(): void { - $this->info('Going to force the size of DECIMAL columns. Please hold.'); + $this->friendlyInfo('Going to force the size of DECIMAL columns. Please hold.'); $type = (string)config('database.default'); /** @@ -548,11 +555,11 @@ class ForceDecimalSize extends Command foreach ($this->tables as $name => $fields) { /** @var string $field */ foreach ($fields as $field) { - $this->line(sprintf('Updating table "%s", field "%s"...', $name, $field)); + $this->friendlyLine(sprintf('Updating table "%s", field "%s"...', $name, $field)); switch ($type) { default: - $this->error(sprintf('Cannot handle database type "%s".', $type)); + $this->friendlyError(sprintf('Cannot handle database type "%s".', $type)); return; case 'pgsql': diff --git a/app/Console/Commands/System/ForceMigration.php b/app/Console/Commands/System/ForceMigration.php index 4677996c7c..2125bf178e 100644 --- a/app/Console/Commands/System/ForceMigration.php +++ b/app/Console/Commands/System/ForceMigration.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\System; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Exceptions\FireflyException; use Illuminate\Console\Command; @@ -33,6 +34,7 @@ use Illuminate\Support\Facades\Schema; class ForceMigration extends Command { + use ShowsFriendlyMessages; use VerifiesAccessToken; /** @@ -58,13 +60,13 @@ class ForceMigration extends Command public function handle(): int { if (!$this->verifyAccessToken()) { - $this->error('Invalid access token.'); + $this->friendlyError('Invalid access token.'); return 1; } - $this->error('Running this command is dangerous and can cause data loss.'); - $this->error('Please do not continue.'); + $this->friendlyError('Running this command is dangerous and can cause data loss.'); + $this->friendlyError('Please do not continue.'); $question = $this->confirm('Do you want to continue?'); if (true === $question) { $user = $this->getUser(); @@ -80,16 +82,16 @@ class ForceMigration extends Command private function forceMigration(): void { DB::commit(); - $this->line('Dropping "migrations" table...'); + $this->friendlyLine('Dropping "migrations" table...'); sleep(2); Schema::dropIfExists('migrations'); - $this->line('Re-run all migrations...'); + $this->friendlyLine('Re-run all migrations...'); Artisan::call('migrate', ['--seed' => true]); sleep(2); - $this->line(''); - $this->line('There is a good chance you just saw a lot of error messages.'); - $this->line('No need to panic yet. First try to access Firefly III (again).'); - $this->line('The issue, whatever it was, may have been solved now.'); - $this->line(''); + $this->friendlyLine(''); + $this->friendlyWarning('There is a good chance you just saw a lot of error messages.'); + $this->friendlyWarning('No need to panic yet. First try to access Firefly III (again).'); + $this->friendlyWarning('The issue, whatever it was, may have been solved now.'); + $this->friendlyLine(''); } } diff --git a/app/Console/Commands/System/ScanAttachments.php b/app/Console/Commands/System/ScanAttachments.php index 231ee3ea9e..7e2ab68231 100644 --- a/app/Console/Commands/System/ScanAttachments.php +++ b/app/Console/Commands/System/ScanAttachments.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\System; use Crypt; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Attachment; use Illuminate\Console\Command; use Illuminate\Contracts\Encryption\DecryptException; @@ -37,6 +38,8 @@ use Storage; */ class ScanAttachments extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -79,7 +82,7 @@ class ScanAttachments extends Command $attachment->md5 = $md5; $attachment->mime = $mime; $attachment->save(); - $this->line(sprintf('Fixed attachment #%d', $attachment->id)); + $this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id)); } return 0; diff --git a/app/Console/Commands/System/SetLatestVersion.php b/app/Console/Commands/System/SetLatestVersion.php index 3e880957c7..ab510eb394 100644 --- a/app/Console/Commands/System/SetLatestVersion.php +++ b/app/Console/Commands/System/SetLatestVersion.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\System; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use Illuminate\Console\Command; /** @@ -31,6 +32,8 @@ use Illuminate\Console\Command; */ class SetLatestVersion extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -52,13 +55,13 @@ class SetLatestVersion extends Command public function handle(): int { if (!$this->option('james-is-cool')) { - $this->error('Am too!'); + $this->friendlyError('Am too!'); return 0; } app('fireflyconfig')->set('db_version', config('firefly.db_version')); app('fireflyconfig')->set('ff3_version', config('firefly.version')); - $this->line('Updated version.'); + $this->friendlyInfo('Updated version.'); return 0; } diff --git a/app/Console/Commands/System/VerifySecurityAlerts.php b/app/Console/Commands/System/VerifySecurityAlerts.php index 8ea6b7f4b7..54d37c5b87 100644 --- a/app/Console/Commands/System/VerifySecurityAlerts.php +++ b/app/Console/Commands/System/VerifySecurityAlerts.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\System; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use Illuminate\Console\Command; use Illuminate\Database\QueryException; use Illuminate\Support\Facades\Log; @@ -35,6 +36,8 @@ use Storage; */ class VerifySecurityAlerts extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -80,23 +83,23 @@ class VerifySecurityAlerts extends Command // depends on level if ('info' === $array['level']) { Log::debug('INFO level alert'); - $this->info($array['message']); + $this->friendlyInfo($array['message']); return 0; } if ('warning' === $array['level']) { Log::debug('WARNING level alert'); - $this->warn('------------------------ :o'); - $this->warn($array['message']); - $this->warn('------------------------ :o'); + $this->friendlyWarning('------------------------ :o'); + $this->friendlyWarning($array['message']); + $this->friendlyWarning('------------------------ :o'); return 0; } if ('danger' === $array['level']) { Log::debug('DANGER level alert'); - $this->error('------------------------ :-('); - $this->error($array['message']); - $this->error('------------------------ :-('); + $this->friendlyError('------------------------ :-('); + $this->friendlyError($array['message']); + $this->friendlyError('------------------------ :-('); return 0; } @@ -104,8 +107,8 @@ class VerifySecurityAlerts extends Command return 0; } } - Log::debug('This version is not mentioned.'); - + Log::debug(sprintf('No security alerts for version %s', $version)); + $this->friendlyPositive(sprintf('No security alerts for version %s', $version)); return 0; } diff --git a/app/Console/Commands/Tools/ApplyRules.php b/app/Console/Commands/Tools/ApplyRules.php index fc1ef53f2b..9ee2545e0a 100644 --- a/app/Console/Commands/Tools/ApplyRules.php +++ b/app/Console/Commands/Tools/ApplyRules.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Tools; use Carbon\Carbon; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\AccountType; @@ -43,6 +44,7 @@ use Illuminate\Support\Facades\Log; */ class ApplyRules extends Command { + use ShowsFriendlyMessages; use VerifiesAccessToken; /** @@ -88,7 +90,7 @@ class ApplyRules extends Command $start = microtime(true); $this->stupidLaravel(); if (!$this->verifyAccessToken()) { - $this->error('Invalid access token.'); + $this->friendlyError('Invalid access token.'); return 1; } @@ -111,11 +113,11 @@ class ApplyRules extends Command $rulesToApply = $this->getRulesToApply(); $count = $rulesToApply->count(); if (0 === $count) { - $this->error('No rules or rule groups have been included.'); - $this->warn('Make a selection using:'); - $this->warn(' --rules=1,2,...'); - $this->warn(' --rule_groups=1,2,...'); - $this->warn(' --all_rules'); + $this->friendlyError('No rules or rule groups have been included.'); + $this->friendlyWarning('Make a selection using:'); + $this->friendlyWarning(' --rules=1,2,...'); + $this->friendlyWarning(' --rule_groups=1,2,...'); + $this->friendlyWarning(' --all_rules'); return 1; } @@ -139,18 +141,61 @@ class ApplyRules extends Command $ruleEngine->addOperator(['type' => 'date_before', 'value' => $this->endDate->format('Y-m-d')]); // start running rules. - $this->line(sprintf('Will apply %d rule(s) to your transaction(s).', $count)); + $this->friendlyLine(sprintf('Will apply %d rule(s) to your transaction(s).', $count)); // file the rule(s) $ruleEngine->fire(); - $this->line(''); + $this->friendlyLine(''); $end = round(microtime(true) - $start, 2); - $this->line(sprintf('Done in %s seconds!', $end)); + $this->friendlyPositive(sprintf('Done in %s seconds!', $end)); return 0; } + /** + * @return Collection + */ + private function getRulesToApply(): Collection + { + $rulesToApply = new Collection(); + /** @var RuleGroup $group */ + foreach ($this->groups as $group) { + $rules = $this->ruleGroupRepository->getActiveStoreRules($group); + /** @var Rule $rule */ + foreach ($rules as $rule) { + // if in rule selection, or group in selection or all rules, it's included. + $test = $this->includeRule($rule, $group); + if (true === $test) { + Log::debug(sprintf('Will include rule #%d "%s"', $rule->id, $rule->title)); + $rulesToApply->push($rule); + } + } + } + + return $rulesToApply; + } + + /** + */ + private function grabAllRules(): void + { + $this->groups = $this->ruleGroupRepository->getActiveGroups(); + } + + /** + * @param Rule $rule + * @param RuleGroup $group + * + * @return bool + */ + private function includeRule(Rule $rule, RuleGroup $group): bool + { + return in_array($group->id, $this->ruleGroupSelection, true) + || in_array($rule->id, $this->ruleSelection, true) + || $this->allRules; + } + /** * Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is * executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should @@ -201,7 +246,7 @@ class ApplyRules extends Command { $accountString = $this->option('accounts'); if (null === $accountString || '' === $accountString) { - $this->error('Please use the --accounts option to indicate the accounts to apply rules to.'); + $this->friendlyError('Please use the --accounts option to indicate the accounts to apply rules to.'); return false; } @@ -220,7 +265,7 @@ class ApplyRules extends Command } if (0 === $finalList->count()) { - $this->error('Please make sure all accounts in --accounts are asset accounts or liabilities.'); + $this->friendlyError('Please make sure all accounts in --accounts are asset accounts or liabilities.'); return false; } @@ -229,53 +274,6 @@ class ApplyRules extends Command return true; } - /** - * @return bool - */ - private function verifyInputRuleGroups(): bool - { - $ruleGroupString = $this->option('rule_groups'); - if (null === $ruleGroupString || '' === $ruleGroupString) { - // can be empty. - return true; - } - $ruleGroupList = explode(',', $ruleGroupString); - - foreach ($ruleGroupList as $ruleGroupId) { - $ruleGroup = $this->ruleGroupRepository->find((int)$ruleGroupId); - if ($ruleGroup->active) { - $this->ruleGroupSelection[] = $ruleGroup->id; - } - if (false === $ruleGroup->active) { - $this->warn(sprintf('Will ignore inactive rule group #%d ("%s")', $ruleGroup->id, $ruleGroup->title)); - } - } - - return true; - } - - /** - * @return bool - */ - private function verifyInputRules(): bool - { - $ruleString = $this->option('rules'); - if (null === $ruleString || '' === $ruleString) { - // can be empty. - return true; - } - $ruleList = explode(',', $ruleString); - - foreach ($ruleList as $ruleId) { - $rule = $this->ruleRepository->find((int)$ruleId); - if (null !== $rule && $rule->active) { - $this->ruleSelection[] = $rule->id; - } - } - - return true; - } - /** * @throws FireflyException */ @@ -313,45 +311,49 @@ class ApplyRules extends Command } /** + * @return bool */ - private function grabAllRules(): void + private function verifyInputRuleGroups(): bool { - $this->groups = $this->ruleGroupRepository->getActiveGroups(); - } + $ruleGroupString = $this->option('rule_groups'); + if (null === $ruleGroupString || '' === $ruleGroupString) { + // can be empty. + return true; + } + $ruleGroupList = explode(',', $ruleGroupString); - /** - * @return Collection - */ - private function getRulesToApply(): Collection - { - $rulesToApply = new Collection(); - /** @var RuleGroup $group */ - foreach ($this->groups as $group) { - $rules = $this->ruleGroupRepository->getActiveStoreRules($group); - /** @var Rule $rule */ - foreach ($rules as $rule) { - // if in rule selection, or group in selection or all rules, it's included. - $test = $this->includeRule($rule, $group); - if (true === $test) { - Log::debug(sprintf('Will include rule #%d "%s"', $rule->id, $rule->title)); - $rulesToApply->push($rule); - } + foreach ($ruleGroupList as $ruleGroupId) { + $ruleGroup = $this->ruleGroupRepository->find((int)$ruleGroupId); + if ($ruleGroup->active) { + $this->ruleGroupSelection[] = $ruleGroup->id; + } + if (false === $ruleGroup->active) { + $this->friendlyWarning(sprintf('Will ignore inactive rule group #%d ("%s")', $ruleGroup->id, $ruleGroup->title)); } } - return $rulesToApply; + return true; } /** - * @param Rule $rule - * @param RuleGroup $group - * * @return bool */ - private function includeRule(Rule $rule, RuleGroup $group): bool + private function verifyInputRules(): bool { - return in_array($group->id, $this->ruleGroupSelection, true) - || in_array($rule->id, $this->ruleSelection, true) - || $this->allRules; + $ruleString = $this->option('rules'); + if (null === $ruleString || '' === $ruleString) { + // can be empty. + return true; + } + $ruleList = explode(',', $ruleString); + + foreach ($ruleList as $ruleId) { + $rule = $this->ruleRepository->find((int)$ruleId); + if (null !== $rule && $rule->active) { + $this->ruleSelection[] = $rule->id; + } + } + + return true; } } diff --git a/app/Console/Commands/Tools/Cron.php b/app/Console/Commands/Tools/Cron.php index 559034fcd5..ce211b4191 100644 --- a/app/Console/Commands/Tools/Cron.php +++ b/app/Console/Commands/Tools/Cron.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Tools; use Carbon\Carbon; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Support\Cronjobs\AutoBudgetCronjob; use FireflyIII\Support\Cronjobs\BillWarningCronjob; @@ -43,6 +44,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class Cron extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -68,7 +71,7 @@ class Cron extends Command try { $date = new Carbon($this->option('date')); } catch (InvalidArgumentException $e) { - $this->error(sprintf('"%s" is not a valid date', $this->option('date'))); + $this->friendlyError(sprintf('"%s" is not a valid date', $this->option('date'))); } $force = (bool)$this->option('force'); @@ -81,7 +84,7 @@ class Cron extends Command } catch (FireflyException $e) { Log::error($e->getMessage()); Log::error($e->getTraceAsString()); - $this->error($e->getMessage()); + $this->friendlyError($e->getMessage()); } } @@ -93,7 +96,7 @@ class Cron extends Command } catch (FireflyException $e) { Log::error($e->getMessage()); Log::error($e->getTraceAsString()); - $this->error($e->getMessage()); + $this->friendlyError($e->getMessage()); } /* @@ -104,7 +107,7 @@ class Cron extends Command } catch (FireflyException $e) { Log::error($e->getMessage()); Log::error($e->getTraceAsString()); - $this->error($e->getMessage()); + $this->friendlyError($e->getMessage()); } /* @@ -115,10 +118,10 @@ class Cron extends Command } catch (FireflyException $e) { Log::error($e->getMessage()); Log::error($e->getTraceAsString()); - $this->error($e->getMessage()); + $this->friendlyError($e->getMessage()); } - $this->info('More feedback on the cron jobs can be found in the log files.'); + $this->friendlyInfo('More feedback on the cron jobs can be found in the log files.'); return 0; } @@ -140,13 +143,13 @@ class Cron extends Command $autoBudget->fire(); if ($autoBudget->jobErrored) { - $this->error(sprintf('Error in "create auto budgets" cron: %s', $autoBudget->message)); + $this->friendlyError(sprintf('Error in "create auto budgets" cron: %s', $autoBudget->message)); } if ($autoBudget->jobFired) { - $this->line(sprintf('"Create auto budgets" cron fired: %s', $autoBudget->message)); + $this->friendlyInfo(sprintf('"Create auto budgets" cron fired: %s', $autoBudget->message)); } if ($autoBudget->jobSucceeded) { - $this->info(sprintf('"Create auto budgets" cron ran with success: %s', $autoBudget->message)); + $this->friendlyPositive(sprintf('"Create auto budgets" cron ran with success: %s', $autoBudget->message)); } } @@ -170,13 +173,13 @@ class Cron extends Command $autoBudget->fire(); if ($autoBudget->jobErrored) { - $this->error(sprintf('Error in "bill warnings" cron: %s', $autoBudget->message)); + $this->friendlyError(sprintf('Error in "bill warnings" cron: %s', $autoBudget->message)); } if ($autoBudget->jobFired) { - $this->line(sprintf('"Send bill warnings" cron fired: %s', $autoBudget->message)); + $this->friendlyInfo(sprintf('"Send bill warnings" cron fired: %s', $autoBudget->message)); } if ($autoBudget->jobSucceeded) { - $this->info(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message)); + $this->friendlyPositive(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message)); } } @@ -196,13 +199,13 @@ class Cron extends Command $exchangeRates->fire(); if ($exchangeRates->jobErrored) { - $this->error(sprintf('Error in "exchange rates" cron: %s', $exchangeRates->message)); + $this->friendlyError(sprintf('Error in "exchange rates" cron: %s', $exchangeRates->message)); } if ($exchangeRates->jobFired) { - $this->line(sprintf('"Exchange rates" cron fired: %s', $exchangeRates->message)); + $this->friendlyInfo(sprintf('"Exchange rates" cron fired: %s', $exchangeRates->message)); } if ($exchangeRates->jobSucceeded) { - $this->info(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message)); + $this->friendlyPositive(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message)); } } @@ -226,13 +229,13 @@ class Cron extends Command $recurring->fire(); if ($recurring->jobErrored) { - $this->error(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message)); + $this->friendlyError(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message)); } if ($recurring->jobFired) { - $this->line(sprintf('"Create recurring transactions" cron fired: %s', $recurring->message)); + $this->friendlyInfo(sprintf('"Create recurring transactions" cron fired: %s', $recurring->message)); } if ($recurring->jobSucceeded) { - $this->info(sprintf('"Create recurring transactions" cron ran with success: %s', $recurring->message)); + $this->friendlyPositive(sprintf('"Create recurring transactions" cron ran with success: %s', $recurring->message)); } } } diff --git a/app/Console/Commands/Upgrade/AccountCurrencies.php b/app/Console/Commands/Upgrade/AccountCurrencies.php index 33fbbda983..d72c26f3f0 100644 --- a/app/Console/Commands/Upgrade/AccountCurrencies.php +++ b/app/Console/Commands/Upgrade/AccountCurrencies.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\AccountMeta; @@ -42,6 +43,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class AccountCurrencies extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_account_currencies'; protected $description = 'Give all accounts proper currency info.'; @@ -59,17 +62,17 @@ class AccountCurrencies extends Command { $this->stupidLaravel(); if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } $this->updateAccountCurrencies(); if (0 === $this->count) { - $this->info('Correct: all account currencies are OK.'); + $this->friendlyPositive('All account currencies are OK.'); } if (0 !== $this->count) { - $this->line(sprintf('Corrected %d account(s).', $this->count)); + $this->friendlyInfo(sprintf('Corrected %d account(s).', $this->count)); } $this->markAsExecuted(); @@ -122,7 +125,7 @@ class AccountCurrencies extends Command if (0 === $accountCurrency && 0 === $obCurrency) { AccountMeta::where('account_id', $account->id)->where('name', 'currency_id')->forceDelete(); AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $currency->id]); - $this->line(sprintf('Account #%d ("%s") now has a currency setting (%s).', $account->id, $account->name, $currency->code)); + $this->friendlyInfo(sprintf('Account #%d ("%s") now has a currency setting (%s).', $account->id, $account->name, $currency->code)); $this->count++; return; @@ -131,7 +134,7 @@ class AccountCurrencies extends Command // account is set to 0, opening balance is not? if (0 === $accountCurrency && $obCurrency > 0) { AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $obCurrency]); - $this->line(sprintf('Account #%d ("%s") now has a currency setting (#%d).', $account->id, $account->name, $obCurrency)); + $this->friendlyInfo(sprintf('Account #%d ("%s") now has a currency setting (#%d).', $account->id, $account->name, $obCurrency)); $this->count++; return; @@ -147,7 +150,7 @@ class AccountCurrencies extends Command $transaction->save(); } ); - $this->line(sprintf('Account #%d ("%s") now has a correct currency for opening balance.', $account->id, $account->name)); + $this->friendlyInfo(sprintf('Account #%d ("%s") now has a correct currency for opening balance.', $account->id, $account->name)); $this->count++; } } @@ -186,7 +189,7 @@ class AccountCurrencies extends Command if (null === $defaultCurrency) { Log::error(sprintf('Users currency pref "%s" does not exist!', $defaultCurrencyCode)); - $this->error(sprintf('User has a preference for "%s", but this currency does not exist.', $defaultCurrencyCode)); + $this->friendlyError(sprintf('User has a preference for "%s", but this currency does not exist.', $defaultCurrencyCode)); return; } diff --git a/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php b/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php index 3fbea226cf..aa9ac93630 100644 --- a/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php +++ b/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\BudgetLimit; use Illuminate\Console\Command; @@ -32,6 +33,8 @@ use Psr\Container\NotFoundExceptionInterface; class AppendBudgetLimitPeriods extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '550_budget_limit_periods'; /** * The console command description. @@ -57,7 +60,7 @@ class AppendBudgetLimitPeriods extends Command public function handle(): int { if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -82,7 +85,7 @@ class AppendBudgetLimitPeriods extends Command $limit->start_date->format('Y-m-d'), $limit->end_date->format('Y-m-d') ); - $this->warn($message); + $this->friendlyWarning($message); app('log')->warning($message); return; diff --git a/app/Console/Commands/Upgrade/BackToJournals.php b/app/Console/Commands/Upgrade/BackToJournals.php index d00f691c0c..869cc449d0 100644 --- a/app/Console/Commands/Upgrade/BackToJournals.php +++ b/app/Console/Commands/Upgrade/BackToJournals.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; use DB; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Budget; use FireflyIII\Models\Category; @@ -40,6 +41,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class BackToJournals extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_back_to_journals'; /** * The console command description. @@ -65,20 +68,20 @@ class BackToJournals extends Command public function handle(): int { if (!$this->isMigrated()) { - $this->error('Please run firefly-iii:migrate-to-groups first.'); + $this->friendlyError('Please run firefly-iii:migrate-to-groups first.'); } if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } if (true === $this->option('force')) { - $this->warn('Forcing the command.'); + $this->friendlyWarning('Forcing the command.'); } $this->migrateAll(); - $this->info('Correct: updated category and budget info for all transaction journals'); + $this->friendlyInfo('Updated category and budget info for all transaction journals'); $this->markAsExecuted(); return 0; @@ -177,7 +180,6 @@ class BackToJournals extends Command $collected = TransactionJournal::whereIn('id', $journalIds)->with(['transactions', 'budgets', 'transactions.budgets'])->get(); $journals = $journals->merge($collected); } - $this->line(sprintf('Check %d transaction journal(s) for budget info.', count($journals))); /** @var TransactionJournal $journal */ foreach ($journals as $journal) { $this->migrateBudgetsForJournal($journal); @@ -193,7 +195,7 @@ class BackToJournals extends Command /** @var Transaction|null $transaction */ $transaction = $journal->transactions->first(); if (null === $transaction) { - $this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id)); + $this->friendlyInfo(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id)); return; } @@ -246,7 +248,7 @@ class BackToJournals extends Command /** @var Transaction|null $transaction */ $transaction = $journal->transactions->first(); if (null === $transaction) { - $this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id)); + $this->friendlyInfo(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id)); return; } diff --git a/app/Console/Commands/Upgrade/BudgetLimitCurrency.php b/app/Console/Commands/Upgrade/BudgetLimitCurrency.php index b286643953..7cbd97aba6 100644 --- a/app/Console/Commands/Upgrade/BudgetLimitCurrency.php +++ b/app/Console/Commands/Upgrade/BudgetLimitCurrency.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\BudgetLimit; use Illuminate\Console\Command; @@ -34,6 +35,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class BudgetLimitCurrency extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_bl_currency'; /** * The console command description. @@ -59,7 +62,7 @@ class BudgetLimitCurrency extends Command public function handle(): int { if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -77,7 +80,7 @@ class BudgetLimitCurrency extends Command $currency = app('amount')->getDefaultCurrencyByUser($user); $budgetLimit->transaction_currency_id = $currency->id; $budgetLimit->save(); - $this->line( + $this->friendlyInfo( sprintf('Budget limit #%d (part of budget "%s") now has a currency setting (%s).', $budgetLimit->id, $budget->name, $currency->name) ); $count++; @@ -86,7 +89,7 @@ class BudgetLimitCurrency extends Command } } if (0 === $count) { - $this->info('Correct: all budget limits are OK.'); + $this->friendlyPositive('All budget limits are OK.'); } $this->markAsExecuted(); diff --git a/app/Console/Commands/Upgrade/CCLiabilities.php b/app/Console/Commands/Upgrade/CCLiabilities.php index 4e6a6d55bc..b41f41c9a5 100644 --- a/app/Console/Commands/Upgrade/CCLiabilities.php +++ b/app/Console/Commands/Upgrade/CCLiabilities.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; @@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class CCLiabilities extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_cc_liabilities'; protected $description = 'Convert old credit card liabilities.'; protected $signature = 'firefly-iii:cc-liabilities {--F|force : Force the execution of this command.}'; @@ -50,10 +53,8 @@ class CCLiabilities extends Command */ public function handle(): int { - $start = microtime(true); - if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -62,7 +63,7 @@ class CCLiabilities extends Command $ccType = AccountType::where('type', AccountType::CREDITCARD)->first(); $debtType = AccountType::where('type', AccountType::DEBT)->first(); if (null === $ccType || null === $debtType) { - $this->info('Correct: no incorrectly stored credit card liabilities.'); + $this->friendlyPositive('No incorrectly stored credit card liabilities.'); $this->markAsExecuted(); return 0; @@ -72,16 +73,16 @@ class CCLiabilities extends Command foreach ($accounts as $account) { $account->account_type_id = $debtType->id; $account->save(); - $this->line(sprintf('Converted credit card liability account "%s" (#%d) to generic debt liability.', $account->name, $account->id)); + $this->friendlyInfo(sprintf('Converted credit card liability account "%s" (#%d) to generic debt liability.', $account->name, $account->id)); } if ($accounts->count() > 0) { - $this->info('Credit card liability types are no longer supported and have been converted to generic debts. See: https://bit.ly/FF3-credit-cards'); + $this->friendlyWarning( + 'Credit card liability types are no longer supported and have been converted to generic debts. See: https://bit.ly/FF3-credit-cards' + ); } if (0 === $accounts->count()) { - $this->info('Correct: no incorrectly stored credit card liabilities.'); + $this->friendlyPositive('No incorrectly stored credit card liabilities.'); } - $end = round(microtime(true) - $start, 2); - $this->info(sprintf('Verified credit card liabilities in %s seconds', $end)); $this->markAsExecuted(); return 0; @@ -95,11 +96,7 @@ class CCLiabilities extends Command private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); - if (null !== $configVar) { - return (bool)$configVar->data; - } - - return false; + return (bool)$configVar?->data; } /** diff --git a/app/Console/Commands/Upgrade/DecryptDatabase.php b/app/Console/Commands/Upgrade/DecryptDatabase.php index 831b1d6576..54ab4f91cf 100644 --- a/app/Console/Commands/Upgrade/DecryptDatabase.php +++ b/app/Console/Commands/Upgrade/DecryptDatabase.php @@ -26,6 +26,7 @@ namespace FireflyIII\Console\Commands\Upgrade; use Crypt; use DB; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Preference; use Illuminate\Console\Command; @@ -41,6 +42,8 @@ use stdClass; */ class DecryptDatabase extends Command { + use ShowsFriendlyMessages; + protected $description = 'Decrypts the database.'; protected $signature = 'firefly-iii:decrypt-all'; @@ -98,7 +101,7 @@ class DecryptDatabase extends Command $newValue = json_decode($value, true, 512, JSON_THROW_ON_ERROR) ?? $value; } catch (JsonException $e) { $message = sprintf('Could not JSON decode preference row #%d: %s. This does not have to be a problem.', $id, $e->getMessage()); - $this->error($message); + $this->friendlyError($message); app('log')->warning($message); app('log')->warning($value); app('log')->warning($e->getTraceAsString()); @@ -132,7 +135,7 @@ class DecryptDatabase extends Command $value = $this->tryDecrypt($original); } catch (FireflyException $e) { $message = sprintf('Could not decrypt field "%s" in row #%d of table "%s": %s', $field, $id, $table, $e->getMessage()); - $this->error($message); + $this->friendlyError($message); Log::error($message); Log::error($e->getTraceAsString()); } @@ -159,14 +162,14 @@ class DecryptDatabase extends Command private function decryptTable(string $table, array $fields): void { if ($this->isDecrypted($table)) { - $this->info(sprintf('Correct: no decryption required for table "%s".', $table)); + $this->friendlyInfo(sprintf('No decryption required for table "%s".', $table)); return; } foreach ($fields as $field) { $this->decryptField($table, $field); } - $this->line(sprintf('Correct: decrypted the data in table "%s".', $table)); + $this->friendlyPositive(sprintf('Decrypted the data in table "%s".', $table)); // mark as decrypted: $configName = sprintf('is_decrypted_%s', $table); app('fireflyconfig')->set($configName, true); diff --git a/app/Console/Commands/Upgrade/FixPostgresSequences.php b/app/Console/Commands/Upgrade/FixPostgresSequences.php index b3f0fe08a4..40f52ee89e 100644 --- a/app/Console/Commands/Upgrade/FixPostgresSequences.php +++ b/app/Console/Commands/Upgrade/FixPostgresSequences.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; use DB; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use Illuminate\Console\Command; /** @@ -32,6 +33,8 @@ use Illuminate\Console\Command; */ class FixPostgresSequences extends Command { + use ShowsFriendlyMessages; + /** * The console command description. * @@ -55,7 +58,7 @@ class FixPostgresSequences extends Command if (DB::connection()->getName() !== 'pgsql') { return 0; } - $this->line('Going to verify PostgreSQL table sequences.'); + $this->friendlyLine('Going to verify PostgreSQL table sequences.'); $tablesToCheck = [ '2fa_tokens', 'account_meta', @@ -116,12 +119,13 @@ class FixPostgresSequences extends Command ]; foreach ($tablesToCheck as $tableToCheck) { - $this->info(sprintf('Checking the next id sequence for table "%s".', $tableToCheck)); + $this->friendlyLine(sprintf('Checking the next id sequence for table "%s".', $tableToCheck)); $highestId = DB::table($tableToCheck)->select(DB::raw('MAX(id)'))->first(); $nextId = DB::table($tableToCheck)->select(DB::raw(sprintf('nextval(\'%s_id_seq\')', $tableToCheck)))->first(); if (null === $nextId) { - $this->line(sprintf('nextval is NULL for table "%s", go to next table.', $tableToCheck)); + $this->friendlyInfo(); + e(sprintf('nextval is NULL for table "%s", go to next table.', $tableToCheck)); continue; } @@ -130,14 +134,14 @@ class FixPostgresSequences extends Command $highestId = DB::table($tableToCheck)->select(DB::raw('MAX(id)'))->first(); $nextId = DB::table($tableToCheck)->select(DB::raw(sprintf('nextval(\'%s_id_seq\')', $tableToCheck)))->first(); if ($nextId->nextval > $highestId->max) { - $this->info(sprintf('Table "%s" autoincrement corrected.', $tableToCheck)); + $this->friendlyInfo(sprintf('Table "%s" autoincrement corrected.', $tableToCheck)); } if ($nextId->nextval <= $highestId->max) { - $this->warn(sprintf('Arff! The nextval sequence is still all screwed up on table "%s".', $tableToCheck)); + $this->friendlyWarning(sprintf('Arff! The nextval sequence is still all screwed up on table "%s".', $tableToCheck)); } } if ($nextId->nextval >= $highestId->max) { - $this->info(sprintf('Table "%s" autoincrement is correct.', $tableToCheck)); + $this->friendlyPositive(sprintf('Table "%s" autoincrement is correct.', $tableToCheck)); } } diff --git a/app/Console/Commands/Upgrade/MigrateAttachments.php b/app/Console/Commands/Upgrade/MigrateAttachments.php index 9d22dad7bc..db0e4dedb0 100644 --- a/app/Console/Commands/Upgrade/MigrateAttachments.php +++ b/app/Console/Commands/Upgrade/MigrateAttachments.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Attachment; use FireflyIII\Models\Note; @@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class MigrateAttachments extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_migrate_attachments'; /** * The console command description. @@ -62,7 +65,7 @@ class MigrateAttachments extends Command { $start = microtime(true); if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -94,13 +97,13 @@ class MigrateAttachments extends Command } } if (0 === $count) { - $this->info('Correct: all attachments are OK.'); + $this->friendlyPositive('All attachments are OK.'); } if (0 !== $count) { - $this->line(sprintf('Updated %d attachment(s).', $count)); + $this->friendlyInfo(sprintf('Updated %d attachment(s).', $count)); } $end = round(microtime(true) - $start, 2); - $this->info(sprintf('Migrated attachment notes in %s seconds.', $end)); + $this->friendlyInfo(sprintf('Migrated attachment notes in %s seconds.', $end)); $this->markAsExecuted(); return 0; diff --git a/app/Console/Commands/Upgrade/MigrateJournalNotes.php b/app/Console/Commands/Upgrade/MigrateJournalNotes.php index b878c6cfdb..c56c52341a 100644 --- a/app/Console/Commands/Upgrade/MigrateJournalNotes.php +++ b/app/Console/Commands/Upgrade/MigrateJournalNotes.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Note; use FireflyIII\Models\TransactionJournalMeta; @@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class MigrateJournalNotes extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_migrate_notes'; /** * The console command description. @@ -63,7 +66,7 @@ class MigrateJournalNotes extends Command $start = microtime(true); if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -88,14 +91,14 @@ class MigrateJournalNotes extends Command } if (0 === $count) { - $this->info('Correct: No notes to migrate.'); + $this->friendlyPositive('No notes to migrate.'); } if (0 !== $count) { - $this->line(sprintf('Migrated %d note(s).', $count)); + $this->friendlyInfo(sprintf('Migrated %d note(s).', $count)); } $end = round(microtime(true) - $start, 2); - $this->info(sprintf('Migrated notes in %s seconds.', $end)); + $this->friendlyInfo(sprintf('Migrated notes in %s seconds.', $end)); $this->markAsExecuted(); return 0; diff --git a/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php b/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php index 342157aad0..7ed84eec42 100644 --- a/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php +++ b/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Recurrence; use FireflyIII\Models\RecurrenceMeta; @@ -38,6 +39,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class MigrateRecurrenceMeta extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '481_migrate_recurrence_meta'; /** * The console command description. @@ -64,17 +67,17 @@ class MigrateRecurrenceMeta extends Command public function handle(): int { if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } $count = $this->migrateMetaData(); if (0 === $count) { - $this->info('Correct: no recurrence meta data migrated.'); + $this->friendlyPositive('No recurrence meta data migrated.'); } if ($count > 0) { - $this->line(sprintf('Migrated %d meta data entries', $count)); + $this->friendlyInfo(sprintf('Migrated %d meta data entries', $count)); } $this->markAsExecuted(); diff --git a/app/Console/Commands/Upgrade/MigrateRecurrenceType.php b/app/Console/Commands/Upgrade/MigrateRecurrenceType.php index 58d7b74df0..11e3424c8d 100644 --- a/app/Console/Commands/Upgrade/MigrateRecurrenceType.php +++ b/app/Console/Commands/Upgrade/MigrateRecurrenceType.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Recurrence; use FireflyIII\Models\RecurrenceTransaction; @@ -37,6 +38,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class MigrateRecurrenceType extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '550_migrate_recurrence_type'; /** * The console command description. @@ -62,7 +65,7 @@ class MigrateRecurrenceType extends Command public function handle(): int { if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -90,11 +93,7 @@ class MigrateRecurrenceType extends Command private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); - if (null !== $configVar) { - return (bool)$configVar->data; - } - - return false; + return (bool)$configVar?->data; } /** @@ -105,6 +104,10 @@ class MigrateRecurrenceType extends Command app('fireflyconfig')->set(self::CONFIG_NAME, true); } + /** + * @param Recurrence $recurrence + * @return void + */ private function migrateRecurrence(Recurrence $recurrence): void { $originalType = (int)$recurrence->transaction_type_id; @@ -116,7 +119,7 @@ class MigrateRecurrenceType extends Command $transaction->transaction_type_id = $originalType; $transaction->save(); } - $this->line(sprintf('Updated recurrence #%d to new transaction type model.', $recurrence->id)); + $this->friendlyInfo(sprintf('Updated recurrence #%d to new transaction type model.', $recurrence->id)); } /** diff --git a/app/Console/Commands/Upgrade/MigrateTagLocations.php b/app/Console/Commands/Upgrade/MigrateTagLocations.php index 845c562acf..18dc8cc7ae 100644 --- a/app/Console/Commands/Upgrade/MigrateTagLocations.php +++ b/app/Console/Commands/Upgrade/MigrateTagLocations.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Location; use FireflyIII\Models\Tag; @@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class MigrateTagLocations extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '500_migrate_tag_locations'; /** * The console command description. @@ -61,7 +64,7 @@ class MigrateTagLocations extends Command public function handle(): int { if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } diff --git a/app/Console/Commands/Upgrade/MigrateToGroups.php b/app/Console/Commands/Upgrade/MigrateToGroups.php index 437a28ac81..a6d12e5fa2 100644 --- a/app/Console/Commands/Upgrade/MigrateToGroups.php +++ b/app/Console/Commands/Upgrade/MigrateToGroups.php @@ -25,6 +25,7 @@ namespace FireflyIII\Console\Commands\Upgrade; use DB; use Exception; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\TransactionGroupFactory; use FireflyIII\Models\Budget; @@ -49,6 +50,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class MigrateToGroups extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_migrated_to_groups'; protected $description = 'Migrates a pre-4.7.8 transaction structure to the 4.7.8+ transaction structure.'; protected $signature = 'firefly-iii:migrate-to-groups {--F|force : Force the migration, even if it fired before.}'; @@ -68,13 +71,13 @@ class MigrateToGroups extends Command $this->stupidLaravel(); if ($this->isMigrated() && true !== $this->option('force')) { - $this->info('Correct: database is already migrated.'); + $this->friendlyInfo('Database is already migrated.'); return 0; } if (true === $this->option('force')) { - $this->warn('Forcing the migration.'); + $this->friendlyWarning('Forcing the migration.'); } @@ -82,10 +85,10 @@ class MigrateToGroups extends Command $this->makeGroupsFromAll(); if (0 !== $this->count) { - $this->line(sprintf('Migrated %d transaction journal(s).', $this->count)); + $this->friendlyInfo(sprintf('Migrated %d transaction journal(s).', $this->count)); } if (0 === $this->count) { - $this->info('Correct: no journals to migrate to groups.'); + $this->friendlyPositive('No journals to migrate to groups.'); } $this->markAsMigrated(); @@ -235,14 +238,14 @@ class MigrateToGroups extends Command $total = count($orphanedJournals); if ($total > 0) { Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $total)); - $this->line(sprintf('Going to convert %d transaction journals. Please hold..', $total)); + $this->friendlyInfo(sprintf('Going to convert %d transaction journals. Please hold..', $total)); /** @var array $array */ foreach ($orphanedJournals as $array) { $this->giveGroup($array); } } if (0 === $total) { - $this->info('Correct: no need to convert transaction journals.'); + $this->friendlyPositive('No need to convert transaction journals.'); } } @@ -253,7 +256,7 @@ class MigrateToGroups extends Command { $splitJournals = $this->cliRepository->getSplitJournals(); if ($splitJournals->count() > 0) { - $this->info(sprintf('Going to convert %d split transaction(s). Please hold..', $splitJournals->count())); + $this->friendlyLine(sprintf('Going to convert %d split transaction(s). Please hold..', $splitJournals->count())); /** @var TransactionJournal $journal */ foreach ($splitJournals as $journal) { $this->makeMultiGroup($journal); @@ -320,7 +323,7 @@ class MigrateToGroups extends Command $opposingTr = $this->findOpposingTransaction($journal, $transaction); if (null === $opposingTr) { - $this->error( + $this->friendlyError( sprintf( 'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.', $journal->id, @@ -393,7 +396,7 @@ class MigrateToGroups extends Command implode(', #', $group->transactionJournals->pluck('id')->toArray()) ) ); - $this->line( + $this->friendlyInfo( sprintf( 'Migrated journal #%d into group #%d with these journals: #%s', $journal->id, diff --git a/app/Console/Commands/Upgrade/MigrateToRules.php b/app/Console/Commands/Upgrade/MigrateToRules.php index f89fedcabe..96a3b2575f 100644 --- a/app/Console/Commands/Upgrade/MigrateToRules.php +++ b/app/Console/Commands/Upgrade/MigrateToRules.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Bill; use FireflyIII\Models\Preference; @@ -41,6 +42,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class MigrateToRules extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_bills_to_rules'; /** * The console command description. @@ -75,11 +78,9 @@ class MigrateToRules extends Command public function handle(): int { $this->stupidLaravel(); - $start = microtime(true); - if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -92,14 +93,12 @@ class MigrateToRules extends Command } if (0 === $this->count) { - $this->info('Correct: all bills are OK.'); + $this->friendlyPositive('All bills are OK.'); } if (0 !== $this->count) { - $this->line(sprintf('Verified and fixed %d bill(s).', $this->count)); + $this->friendlyInfo(sprintf('Verified and fixed %d bill(s).', $this->count)); } - $end = round(microtime(true) - $start, 2); - $this->info(sprintf('Verified and fixed bills in %s seconds.', $end)); $this->markAsExecuted(); return 0; diff --git a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php index 9b55610038..a9ea6e4aee 100644 --- a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php +++ b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; @@ -43,6 +44,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class OtherCurrenciesCorrections extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_other_currencies'; protected $description = 'Update all journal currency information.'; protected $signature = 'firefly-iii:other-currencies {--F|force : Force the execution of this command.}'; @@ -66,7 +69,7 @@ class OtherCurrenciesCorrections extends Command $this->stupidLaravel(); if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -75,7 +78,7 @@ class OtherCurrenciesCorrections extends Command $this->updateOtherJournalsCurrencies(); $this->markAsExecuted(); - $this->info('Correct: verified and fixed transaction currencies.'); + $this->friendlyPositive('Verified and fixed transaction currencies.'); return 0; } @@ -202,7 +205,7 @@ class OtherCurrenciesCorrections extends Command $leadTransaction = $this->getLeadTransaction($journal); if (null === $leadTransaction) { - $this->error(sprintf('Could not reliably determine which transaction is in the lead for transaction journal #%d.', $journal->id)); + $this->friendlyError(sprintf('Could not reliably determine which transaction is in the lead for transaction journal #%d.', $journal->id)); return; } @@ -210,7 +213,7 @@ class OtherCurrenciesCorrections extends Command $account = $leadTransaction->account; $currency = $this->getCurrency($account); if (null === $currency) { - $this->error( + $this->friendlyError( sprintf( 'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', $account->id, diff --git a/app/Console/Commands/Upgrade/RenameAccountMeta.php b/app/Console/Commands/Upgrade/RenameAccountMeta.php index a5a1d2622e..8451c88f0c 100644 --- a/app/Console/Commands/Upgrade/RenameAccountMeta.php +++ b/app/Console/Commands/Upgrade/RenameAccountMeta.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\AccountMeta; use Illuminate\Console\Command; @@ -34,6 +35,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class RenameAccountMeta extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_rename_account_meta'; /** * The console command description. @@ -59,7 +62,7 @@ class RenameAccountMeta extends Command public function handle(): int { if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -86,10 +89,10 @@ class RenameAccountMeta extends Command $this->markAsExecuted(); if (0 === $count) { - $this->info('Correct: all account meta is OK.'); + $this->friendlyPositive('All account meta is OK.'); } if (0 !== $count) { - $this->line(sprintf('Renamed %d account meta entries (entry).', $count)); + $this->friendlyInfo(sprintf('Renamed %d account meta entries (entry).', $count)); } return 0; diff --git a/app/Console/Commands/Upgrade/TransactionIdentifier.php b/app/Console/Commands/Upgrade/TransactionIdentifier.php index 1c0fe0c4be..f8260370fa 100644 --- a/app/Console/Commands/Upgrade/TransactionIdentifier.php +++ b/app/Console/Commands/Upgrade/TransactionIdentifier.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; @@ -39,6 +40,8 @@ use Schema; */ class TransactionIdentifier extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_transaction_identifier'; protected $description = 'Fixes transaction identifiers.'; protected $signature = 'firefly-iii:transaction-identifiers {--F|force : Force the execution of this command.}'; @@ -64,7 +67,7 @@ class TransactionIdentifier extends Command $this->stupidLaravel(); if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -81,10 +84,10 @@ class TransactionIdentifier extends Command } if (0 === $this->count) { - $this->line('Correct: all split journal transaction identifiers are OK.'); + $this->friendlyPositive('All split journal transaction identifiers are OK.'); } if (0 !== $this->count) { - $this->line(sprintf('Correct: fixed %d split journal transaction identifier(s).', $this->count)); + $this->friendlyInfo(sprintf('Fixed %d split journal transaction identifier(s).', $this->count)); } $this->markAsExecuted(); @@ -111,10 +114,10 @@ class TransactionIdentifier extends Command ->first(); } catch (QueryException $e) { Log::error($e->getMessage()); - $this->error('Firefly III could not find the "identifier" field in the "transactions" table.'); - $this->error(sprintf('This field is required for Firefly III version %s to run.', config('firefly.version'))); - $this->error('Please run "php artisan migrate" to add this field to the table.'); - $this->info('Then, run "php artisan firefly:upgrade-database" to try again.'); + $this->friendlyError('Firefly III could not find the "identifier" field in the "transactions" table.'); + $this->friendlyError(sprintf('This field is required for Firefly III version %s to run.', config('firefly.version'))); + $this->friendlyError('Please run "php artisan migrate" to add this field to the table.'); + $this->friendlyError('Then, run "php artisan firefly:upgrade-database" to try again.'); return null; } diff --git a/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php b/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php index 8a02a157a4..f97a5b3183 100644 --- a/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php +++ b/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; -use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Account; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionCurrency; @@ -41,6 +41,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class TransferCurrenciesCorrections extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '480_transfer_currencies'; protected $description = 'Updates transfer currency information.'; protected $signature = 'firefly-iii:transfer-currencies {--F|force : Force the execution of this command.}'; @@ -66,7 +68,7 @@ class TransferCurrenciesCorrections extends Command $this->stupidLaravel(); if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -76,13 +78,11 @@ class TransferCurrenciesCorrections extends Command $this->markAsExecuted(); if (0 === $this->count) { - $message = 'Correct: all transfers have correct currency information.'; - $this->info($message); - } - if (0 !== $this->count) { - $message = sprintf('Verified currency information of %d transfer(s).', $this->count); - $this->line($message); + $this->friendlyPositive('All transfers have correct currency information.'); + return 0; } + + $this->friendlyInfo(sprintf('Verified currency information of %d transfer(s).', $this->count)); return 0; } @@ -101,7 +101,7 @@ class TransferCurrenciesCorrections extends Command $this->destinationTransaction->id, $this->destinationCurrency->code ); - $this->line($message); + $this->friendlyInfo($message); $this->count++; $this->destinationTransaction->save(); } @@ -117,7 +117,7 @@ class TransferCurrenciesCorrections extends Command $this->destinationTransaction->foreign_amount = bcmul((string)$this->sourceTransaction->foreign_amount, '-1'); $this->destinationTransaction->save(); $this->count++; - $this->line( + $this->friendlyInfo( sprintf( 'Restored foreign amount of destination transaction #%d to %s', $this->destinationTransaction->id, @@ -144,7 +144,7 @@ class TransferCurrenciesCorrections extends Command $this->destinationAccount->id, $this->destinationTransaction->amount ); - $this->line($message); + $this->friendlyWarning($message); $this->count++; $this->destinationTransaction->transaction_currency_id = (int)$this->destinationCurrency->id; $this->destinationTransaction->save(); @@ -187,7 +187,9 @@ class TransferCurrenciesCorrections extends Command $this->sourceTransaction->save(); $this->destinationTransaction->save(); $this->count++; - $this->line(sprintf('Verified foreign currency ID of transaction #%d and #%d', $this->sourceTransaction->id, $this->destinationTransaction->id)); + $this->friendlyInfo( + sprintf('Verified foreign currency ID of transaction #%d and #%d', $this->sourceTransaction->id, $this->destinationTransaction->id) + ); } } @@ -206,7 +208,7 @@ class TransferCurrenciesCorrections extends Command $this->sourceTransaction->id, $this->sourceCurrency->code ); - $this->line($message); + $this->friendlyInfo($message); $this->count++; $this->sourceTransaction->save(); } @@ -222,7 +224,7 @@ class TransferCurrenciesCorrections extends Command $this->sourceTransaction->foreign_amount = bcmul((string)$this->destinationTransaction->foreign_amount, '-1'); $this->sourceTransaction->save(); $this->count++; - $this->line( + $this->friendlyInfo( sprintf( 'Restored foreign amount of source transaction #%d to %s', $this->sourceTransaction->id, @@ -249,7 +251,7 @@ class TransferCurrenciesCorrections extends Command $this->sourceAccount->id, $this->sourceTransaction->amount ); - $this->line($message); + $this->friendlyWarning($message); $this->count++; $this->sourceTransaction->transaction_currency_id = (int)$this->sourceCurrency->id; $this->sourceTransaction->save(); @@ -274,7 +276,7 @@ class TransferCurrenciesCorrections extends Command $oldCurrencyCode ); $this->count++; - $this->line($message); + $this->friendlyInfo($message); $journal->save(); } } @@ -388,7 +390,7 @@ class TransferCurrenciesCorrections extends Command if (null === $this->sourceCurrency) { $message = sprintf('Account #%d ("%s") must have currency preference but has none.', $this->sourceAccount->id, $this->sourceAccount->name); Log::error($message); - $this->error($message); + $this->friendlyError($message); return true; } @@ -401,7 +403,7 @@ class TransferCurrenciesCorrections extends Command $this->destinationAccount->name ); Log::error($message); - $this->error($message); + $this->friendlyError($message); return true; } @@ -486,7 +488,7 @@ class TransferCurrenciesCorrections extends Command if ($this->isSplitJournal($transfer)) { - $this->line(sprintf('Transaction journal #%d is a split journal. Cannot continue.', $transfer->id)); + $this->friendlyWarning(sprintf('Transaction journal #%d is a split journal. Cannot continue.', $transfer->id)); return; } @@ -498,7 +500,7 @@ class TransferCurrenciesCorrections extends Command // unexpectedly, either one is null: if ($this->isEmptyTransactions()) { - $this->error(sprintf('Source or destination information for transaction journal #%d is null. Cannot fix this one.', $transfer->id)); + $this->friendlyError(sprintf('Source or destination information for transaction journal #%d is null. Cannot fix this one.', $transfer->id)); return; } @@ -506,7 +508,7 @@ class TransferCurrenciesCorrections extends Command // both accounts must have currency preference: if ($this->isNoCurrencyPresent()) { - $this->error( + $this->friendlyError( sprintf('Source or destination accounts for transaction journal #%d have no currency information. Cannot fix this one.', $transfer->id) ); diff --git a/app/Console/Commands/Upgrade/UpgradeDatabase.php b/app/Console/Commands/Upgrade/UpgradeDatabase.php index 07cc803bf3..ad9bd3faa7 100644 --- a/app/Console/Commands/Upgrade/UpgradeDatabase.php +++ b/app/Console/Commands/Upgrade/UpgradeDatabase.php @@ -26,6 +26,7 @@ namespace FireflyIII\Console\Commands\Upgrade; set_time_limit(0); use Artisan; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use Illuminate\Console\Command; /** @@ -35,6 +36,8 @@ use Illuminate\Console\Command; */ class UpgradeDatabase extends Command { + use ShowsFriendlyMessages; + protected $description = 'Upgrades the database to the latest version.'; protected $signature = 'firefly-iii:upgrade-database {--F|force : Force all upgrades.}'; @@ -72,7 +75,7 @@ class UpgradeDatabase extends Command $args = ['--force' => true]; } foreach ($commands as $command) { - $this->line(sprintf('Now executing %s', $command)); + $this->friendlyLine(sprintf('Now executing %s', $command)); $this->call($command, $args); } // set new DB version. diff --git a/app/Console/Commands/Upgrade/UpgradeLiabilities.php b/app/Console/Commands/Upgrade/UpgradeLiabilities.php index de6101b552..213a300b3e 100644 --- a/app/Console/Commands/Upgrade/UpgradeLiabilities.php +++ b/app/Console/Commands/Upgrade/UpgradeLiabilities.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\AccountMetaFactory; use FireflyIII\Models\Account; @@ -42,6 +43,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class UpgradeLiabilities extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '560_upgrade_liabilities'; protected $description = 'Upgrade liabilities to new 5.6.0 structure.'; protected $signature = 'firefly-iii:upgrade-liabilities {--F|force : Force the execution of this command.}'; @@ -57,7 +60,7 @@ class UpgradeLiabilities extends Command public function handle(): int { if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } diff --git a/app/Console/Commands/Upgrade/UpgradeLiabilitiesEight.php b/app/Console/Commands/Upgrade/UpgradeLiabilitiesEight.php index a878f1809b..c177fb9a59 100644 --- a/app/Console/Commands/Upgrade/UpgradeLiabilitiesEight.php +++ b/app/Console/Commands/Upgrade/UpgradeLiabilitiesEight.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Upgrade; +use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; @@ -44,6 +45,8 @@ use Psr\Container\NotFoundExceptionInterface; */ class UpgradeLiabilitiesEight extends Command { + use ShowsFriendlyMessages; + public const CONFIG_NAME = '600_upgrade_liabilities'; protected $description = 'Upgrade liabilities to new 6.0.0 structure.'; protected $signature = 'firefly-iii:liabilities-600 {--F|force : Force the execution of this command.}'; @@ -59,7 +62,7 @@ class UpgradeLiabilitiesEight extends Command public function handle(): int { if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->friendlyInfo('This command has already been executed.'); return 0; } @@ -257,12 +260,12 @@ class UpgradeLiabilitiesEight extends Command if ('credit' === $direction && $this->hasBadOpening($account)) { $this->deleteCreditTransaction($account); $this->reverseOpeningBalance($account); - $this->line(sprintf('Corrected opening balance for liability #%d ("%s")', $account->id, $account->name)); + $this->friendlyInfo(sprintf('Corrected opening balance for liability #%d ("%s")', $account->id, $account->name)); } if ('credit' === $direction) { $count = $this->deleteTransactions($account); if ($count > 0) { - $this->line(sprintf('Removed %d old format transaction(s) for liability #%d ("%s")', $count, $account->id, $account->name)); + $this->friendlyInfo(sprintf('Removed %d old format transaction(s) for liability #%d ("%s")', $count, $account->id, $account->name)); } } } diff --git a/app/Console/Commands/Upgrade/UpgradeSkeleton.php.stub b/app/Console/Commands/Upgrade/UpgradeSkeleton.php.stub index e454950502..4ba6803d78 100644 --- a/app/Console/Commands/Upgrade/UpgradeSkeleton.php.stub +++ b/app/Console/Commands/Upgrade/UpgradeSkeleton.php.stub @@ -33,7 +33,7 @@ class UpgradeSkeleton extends Command { $start = microtime(true); if ($this->isExecuted() && true !== $this->option('force')) { - $this->info('Correct: this command has already been executed.'); + $this->info('FRIENDLY This command has already been executed.'); return 0; }