fix: replace console messages with unified command.

This commit is contained in:
James Cole
2023-06-20 07:16:56 +02:00
parent f2b2c2109f
commit 42043de34f
62 changed files with 767 additions and 512 deletions

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\AutoBudget; use FireflyIII\Models\AutoBudget;
use FireflyIII\Models\AvailableBudget; use FireflyIII\Models\AvailableBudget;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
@@ -39,6 +40,8 @@ use Illuminate\Console\Command;
*/ */
class CorrectAmounts extends Command class CorrectAmounts extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'This command makes sure positive and negative amounts are recorded correctly.'; protected $description = 'This command makes sure positive and negative amounts are recorded correctly.';
protected $signature = 'firefly-iii:fix-amount-pos-neg'; protected $signature = 'firefly-iii:fix-amount-pos-neg';
@@ -78,7 +81,7 @@ class CorrectAmounts extends Command
$set = AutoBudget::where('amount', '<', 0)->get(); $set = AutoBudget::where('amount', '<', 0)->get();
$count = $set->count(); $count = $set->count();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: All auto budget amounts are positive.'); $this->friendlyPositive('All auto budget amounts are positive.');
return; return;
} }
@@ -87,7 +90,7 @@ class CorrectAmounts extends Command
$item->amount = app('steam')->positive((string)$item->amount); $item->amount = app('steam')->positive((string)$item->amount);
$item->save(); $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(); $set = AvailableBudget::where('amount', '<', 0)->get();
$count = $set->count(); $count = $set->count();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: All available budget amounts are positive.'); $this->friendlyPositive('All available budget amounts are positive.');
return; return;
} }
@@ -107,7 +110,7 @@ class CorrectAmounts extends Command
$item->amount = app('steam')->positive((string)$item->amount); $item->amount = app('steam')->positive((string)$item->amount);
$item->save(); $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(); $set = Bill::where('amount_min', '<', 0)->orWhere('amount_max', '<', 0)->get();
$count = $set->count(); $count = $set->count();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: All bill amounts are positive.'); $this->friendlyPositive('All bill amounts are positive.');
return; return;
} }
@@ -128,6 +131,7 @@ class CorrectAmounts extends Command
$item->amount_max = app('steam')->positive((string)$item->amount_max); $item->amount_max = app('steam')->positive((string)$item->amount_max);
$item->save(); $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(); $set = BudgetLimit::where('amount', '<', 0)->get();
$count = $set->count(); $count = $set->count();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: All budget limit amounts are positive.'); $this->friendlyPositive('All budget limit amounts are positive.');
return; return;
} }
@@ -147,7 +151,7 @@ class CorrectAmounts extends Command
$item->amount = app('steam')->positive((string)$item->amount); $item->amount = app('steam')->positive((string)$item->amount);
$item->save(); $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(); $set = CurrencyExchangeRate::where('rate', '<', 0)->get();
$count = $set->count(); $count = $set->count();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: All currency exchange rates are positive.'); $this->friendlyPositive('All currency exchange rates are positive.');
return; return;
} }
@@ -167,7 +171,7 @@ class CorrectAmounts extends Command
$item->rate = app('steam')->positive((string)$item->rate); $item->rate = app('steam')->positive((string)$item->rate);
$item->save(); $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(); $set = PiggyBank::where('targetamount', '<', 0)->get();
$count = $set->count(); $count = $set->count();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: All piggy bank amounts are positive.'); $this->friendlyPositive('All piggy bank amounts are positive.');
return; return;
} }
@@ -187,7 +191,7 @@ class CorrectAmounts extends Command
$item->targetamount = app('steam')->positive((string)$item->targetamount); $item->targetamount = app('steam')->positive((string)$item->targetamount);
$item->save(); $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(); ->get();
$count = $set->count(); $count = $set->count();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: All recurring transaction amounts are positive.'); $this->friendlyPositive('All recurring transaction amounts are positive.');
return; return;
} }
@@ -210,7 +214,7 @@ class CorrectAmounts extends Command
$item->foreign_amount = app('steam')->positive((string)$item->foreign_amount); $item->foreign_amount = app('steam')->positive((string)$item->foreign_amount);
$item->save(); $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(); $set = PiggyBankRepetition::where('currentamount', '<', 0)->get();
$count = $set->count(); $count = $set->count();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: All piggy bank repetition amounts are positive.'); $this->friendlyPositive('All piggy bank repetition amounts are positive.');
return; return;
} }
@@ -230,7 +234,7 @@ class CorrectAmounts extends Command
$item->currentamount = app('steam')->positive((string)$item->currentamount); $item->currentamount = app('steam')->positive((string)$item->currentamount);
$item->save(); $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) { if (0 === $fixed) {
$this->info('Correct: All rule trigger amounts are positive.'); $this->friendlyPositive('All rule trigger amounts are positive.');
return; return;
} }
$this->line(sprintf('Corrected %d rule trigger amount(s).', $fixed)); $this->friendlyInfo(sprintf('Corrected %d rule trigger amount(s).', $fixed));
} }
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use Artisan; use Artisan;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Schema; use Schema;
@@ -34,6 +35,8 @@ use Schema;
*/ */
class CorrectDatabase extends Command class CorrectDatabase extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Will correct the integrity of your database, if necessary.'; protected $description = 'Will correct the integrity of your database, if necessary.';
protected $signature = 'firefly-iii:correct-database'; protected $signature = 'firefly-iii:correct-database';
@@ -44,7 +47,7 @@ class CorrectDatabase extends Command
{ {
// if table does not exist, return false // if table does not exist, return false
if (!Schema::hasTable('users')) { if (!Schema::hasTable('users')) {
$this->error('No "users"-table, will not continue.'); $this->friendlyError('No "users"-table, will not continue.');
return 1; return 1;
} }
@@ -76,7 +79,7 @@ class CorrectDatabase extends Command
'firefly-iii:trigger-credit-recalculation', 'firefly-iii:trigger-credit-recalculation',
]; ];
foreach ($commands as $command) { foreach ($commands as $command) {
$this->line(sprintf('Now executing command "%s"', $command)); $this->friendlyLine(sprintf('Now executing command "%s"', $command));
$this->call($command); $this->call($command);
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
@@ -39,6 +40,8 @@ use Illuminate\Support\Collection;
*/ */
class CorrectOpeningBalanceCurrencies extends Command class CorrectOpeningBalanceCurrencies extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Will make sure that opening balance transaction currencies match the account they\'re for.'; protected $description = 'Will make sure that opening balance transaction currencies match the account they\'re for.';
protected $signature = 'firefly-iii:fix-ob-currencies'; protected $signature = 'firefly-iii:fix-ob-currencies';
@@ -58,11 +61,11 @@ class CorrectOpeningBalanceCurrencies extends Command
if ($count > 0) { if ($count > 0) {
$message = sprintf('Corrected %d opening balance transaction(s).', $count); $message = sprintf('Corrected %d opening balance transaction(s).', $count);
$this->line($message); $this->friendlyInfo($message);
} }
if (0 === $count) { if (0 === $count) {
$message = 'Correct: There was nothing to fix in the opening balance transactions.'; $message = 'There was nothing to fix in the opening balance transactions.';
$this->info($message); $this->friendlyPositive($message);
} }
return 0; return 0;
@@ -80,7 +83,7 @@ class CorrectOpeningBalanceCurrencies extends Command
if (null === $account) { if (null === $account) {
$message = sprintf('Transaction journal #%d has no valid account. Can\'t fix this line.', $journal->id); $message = sprintf('Transaction journal #%d has no valid account. Can\'t fix this line.', $journal->id);
app('log')->warning($message); app('log')->warning($message);
$this->warn($message); $this->friendlyError($message);
return 0; return 0;
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use Exception; use Exception;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -33,6 +34,8 @@ use Illuminate\Console\Command;
*/ */
class CreateAccessTokens extends Command class CreateAccessTokens extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -66,12 +69,12 @@ class CreateAccessTokens extends Command
if (null === $pref) { if (null === $pref) {
$token = $user->generateAccessToken(); $token = $user->generateAccessToken();
app('preferences')->setForUser($user, 'access_token', $token); 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; ++$count;
} }
} }
if (0 === $count) { if (0 === $count) {
$this->info('Correct: Verified access tokens.'); $this->friendlyPositive('Verified access tokens.');
} }
return 0; return 0;

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\LinkType; use FireflyIII\Models\LinkType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -31,6 +32,8 @@ use Illuminate\Console\Command;
*/ */
class CreateLinkTypes extends Command class CreateLinkTypes extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -67,13 +70,13 @@ class CreateLinkTypes extends Command
$link->inward = $values[1]; $link->inward = $values[1];
$link->outward = $values[0]; $link->outward = $values[0];
++$count; ++$count;
$this->line(sprintf('Created missing link type "%s"', $name)); $this->friendlyInfo(sprintf('Created missing link type "%s"', $name));
} }
$link->editable = false; $link->editable = false;
$link->save(); $link->save();
} }
if (0 === $count) { if (0 === $count) {
$this->info('Correct: all link types are OK'); $this->friendlyPositive('All link types are OK');
} }
return 0; return 0;
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use Exception; use Exception;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -32,6 +33,8 @@ use Illuminate\Console\Command;
*/ */
class DeleteEmptyGroups extends Command class DeleteEmptyGroups extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Delete empty transaction groups.'; protected $description = 'Delete empty transaction groups.';
protected $signature = 'firefly-iii:delete-empty-groups'; protected $signature = 'firefly-iii:delete-empty-groups';
@@ -50,7 +53,7 @@ class DeleteEmptyGroups extends Command
$total = count($groupIds); $total = count($groupIds);
if ($total > 0) { 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. // again, chunks for SQLite.
$chunks = array_chunk($groupIds, 500); $chunks = array_chunk($groupIds, 500);
@@ -59,7 +62,7 @@ class DeleteEmptyGroups extends Command
} }
} }
if (0 === $total) { if (0 === $total) {
$this->info('Correct: verified empty groups.'); $this->friendlyInfo('Verified there are no empty groups.');
} }
return 0; return 0;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use DB; use DB;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -35,6 +36,8 @@ use Illuminate\Support\Facades\Log;
*/ */
class DeleteEmptyJournals extends Command class DeleteEmptyJournals extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * 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; ++$count;
} }
if (0 === $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(); 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++; $total++;
} }
} }
if (0 === $total) { if (0 === $total) {
$this->info('Correct: no uneven transaction journals.'); $this->friendlyPositive('No uneven transaction journals.');
} }
} }
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use Exception; use Exception;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -34,6 +35,8 @@ use stdClass;
*/ */
class DeleteOrphanedTransactions extends Command class DeleteOrphanedTransactions extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -80,7 +83,7 @@ class DeleteOrphanedTransactions extends Command
$journal->delete(); $journal->delete();
} }
Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete(); Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete();
$this->line( $this->friendlyWarning(
sprintf( sprintf(
'Deleted transaction journal #%d because account #%d was already deleted.', 'Deleted transaction journal #%d because account #%d was already deleted.',
$transaction->transaction_journal_id, $transaction->transaction_journal_id,
@@ -90,7 +93,7 @@ class DeleteOrphanedTransactions extends Command
$count++; $count++;
} }
if (0 === $count) { if (0 === $count) {
$this->info('Correct: no orphaned accounts.'); $this->friendlyPositive('No orphaned accounts.');
} }
} }
@@ -102,15 +105,15 @@ class DeleteOrphanedTransactions extends Command
->get(['transaction_journals.id', 'transaction_journals.transaction_group_id']); ->get(['transaction_journals.id', 'transaction_journals.transaction_group_id']);
$count = $set->count(); $count = $set->count();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: no orphaned journals.'); $this->friendlyPositive('No orphaned journals.');
return;
} }
if ($count > 0) { $this->friendlyInfo(sprintf('Found %d orphaned journal(s).', $count));
$this->info(sprintf('Found %d orphaned journal(s).', $count));
foreach ($set as $entry) { foreach ($set as $entry) {
$journal = TransactionJournal::withTrashed()->find((int)$entry->id); $journal = TransactionJournal::withTrashed()->find((int)$entry->id);
if (null !== $journal) { if (null !== $journal) {
$journal->delete(); $journal->delete();
$this->info( $this->friendlyWarning(
sprintf( sprintf(
'Journal #%d (part of deleted transaction group #%d) has been deleted as well.', 'Journal #%d (part of deleted transaction group #%d) has been deleted as well.',
$entry->id, $entry->id,
@@ -120,7 +123,6 @@ class DeleteOrphanedTransactions extends Command
} }
} }
} }
}
/** /**
* @throws Exception * @throws Exception
@@ -143,7 +145,7 @@ class DeleteOrphanedTransactions extends Command
$transaction = Transaction::find((int)$entry->transaction_id); $transaction = Transaction::find((int)$entry->transaction_id);
if (null !== $transaction) { if (null !== $transaction) {
$transaction->delete(); $transaction->delete();
$this->info( $this->friendlyWarning(
sprintf( sprintf(
'Transaction #%d (part of deleted transaction journal #%d) has been deleted as well.', 'Transaction #%d (part of deleted transaction journal #%d) has been deleted as well.',
$entry->transaction_id, $entry->transaction_id,
@@ -154,7 +156,7 @@ class DeleteOrphanedTransactions extends Command
} }
} }
if (0 === $count) { if (0 === $count) {
$this->info('Correct: no orphaned transactions.'); $this->friendlyPositive('No orphaned transactions.');
} }
} }
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -32,6 +33,8 @@ use Illuminate\Console\Command;
*/ */
class DeleteZeroAmount extends Command class DeleteZeroAmount extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -57,13 +60,13 @@ class DeleteZeroAmount extends Command
$journals = TransactionJournal::whereIn('id', $set)->get(); $journals = TransactionJournal::whereIn('id', $set)->get();
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($journals as $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(); $journal->delete();
Transaction::where('transaction_journal_id', $journal->id)->delete(); Transaction::where('transaction_journal_id', $journal->id)->delete();
} }
if (0 === $journals->count()) { if (0 === $journals->count()) {
$this->info('Correct: no zero-amount transaction journals.'); $this->friendlyPositive('No zero-amount transaction journals.');
} }
return 0; return 0;

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
@@ -37,6 +38,8 @@ use Illuminate\Support\Facades\Log;
*/ */
class EnableCurrencies extends Command class EnableCurrencies extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Enables all currencies in use.'; protected $description = 'Enables all currencies in use.';
protected $signature = 'firefly-iii:enable-currencies'; protected $signature = 'firefly-iii:enable-currencies';
@@ -85,10 +88,10 @@ class EnableCurrencies extends Command
); );
$disabled = TransactionCurrency::whereIn('id', $found)->where('enabled', false)->count(); $disabled = TransactionCurrency::whereIn('id', $found)->where('enabled', false)->count();
if ($disabled > 0) { 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) { 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]); TransactionCurrency::whereIn('id', $found)->update(['enabled' => true]);

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -32,6 +33,8 @@ use Illuminate\Console\Command;
*/ */
class FixAccountOrder extends Command class FixAccountOrder extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Make sure account order is correct.'; protected $description = 'Make sure account order is correct.';
protected $signature = 'firefly-iii:fix-account-order'; protected $signature = 'firefly-iii:fix-account-order';
@@ -52,7 +55,7 @@ class FixAccountOrder extends Command
$this->repository->resetAccountOrder(); $this->repository->resetAccountOrder();
} }
$this->info('Correct: All accounts are ordered correctly'); $this->friendlyPositive('All accounts are ordered correctly');
return 0; return 0;
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory; use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@@ -38,6 +39,8 @@ use Illuminate\Support\Facades\Log;
*/ */
class FixAccountTypes extends Command class FixAccountTypes extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Make sure all journals have the correct from/to account types.'; protected $description = 'Make sure all journals have the correct from/to account types.';
protected $signature = 'firefly-iii:fix-account-types'; protected $signature = 'firefly-iii:fix-account-types';
private int $count; private int $count;
@@ -60,11 +63,11 @@ class FixAccountTypes extends Command
$this->inspectJournal($journal); $this->inspectJournal($journal);
} }
if (0 === $this->count) { if (0 === $this->count) {
$this->info('Correct: all account types are OK'); $this->friendlyPositive('All account types are OK');
} }
if (0 !== $this->count) { if (0 !== $this->count) {
Log::debug(sprintf('%d journals had to be fixed.', $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; return 0;
@@ -94,7 +97,7 @@ class FixAccountTypes extends Command
$journal->transactionType()->associate($withdrawal); $journal->transactionType()->associate($withdrawal);
$journal->save(); $journal->save();
$message = sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id); $message = sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id);
$this->info($message); $this->friendlyInfo($message);
Log::debug($message); Log::debug($message);
// check it again: // check it again:
$this->inspectJournal($journal); $this->inspectJournal($journal);
@@ -107,7 +110,7 @@ class FixAccountTypes extends Command
$journal->transactionType()->associate($deposit); $journal->transactionType()->associate($deposit);
$journal->save(); $journal->save();
$message = sprintf('Converted transaction #%d from a transfer to a deposit.', $journal->id); $message = sprintf('Converted transaction #%d from a transfer to a deposit.', $journal->id);
$this->info($message); $this->friendlyInfo($message);
Log::debug($message); Log::debug($message);
// check it again: // check it again:
$this->inspectJournal($journal); $this->inspectJournal($journal);
@@ -128,7 +131,7 @@ class FixAccountTypes extends Command
$result->id, $result->id,
$result->name $result->name
); );
$this->info($message); $this->friendlyWarning($message);
Log::debug($message); Log::debug($message);
$this->inspectJournal($journal); $this->inspectJournal($journal);
break; break;
@@ -148,17 +151,17 @@ class FixAccountTypes extends Command
$result->id, $result->id,
$result->name $result->name
); );
$this->info($message); $this->friendlyWarning($message);
Log::debug($message); Log::debug($message);
$this->inspectJournal($journal); $this->inspectJournal($journal);
break; break;
default: default:
$message = sprintf('The source account of %s #%d cannot be of type "%s".', $type, $journal->id, $source->account->accountType->type); $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); Log::debug($message);
$message = sprintf('The destination account of %s #%d cannot be of type "%s".', $type, $journal->id, $dest->account->accountType->type); $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); Log::debug($message);
break; break;
@@ -195,7 +198,7 @@ class FixAccountTypes extends Command
$transactions = $journal->transactions()->count(); $transactions = $journal->transactions()->count();
if (2 !== $transactions) { if (2 !== $transactions) {
Log::debug(sprintf('Journal has %d transactions, so can\'t fix.', $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; return;
} }
@@ -209,7 +212,7 @@ class FixAccountTypes extends Command
if (!array_key_exists($type, $this->expected)) { if (!array_key_exists($type, $this->expected)) {
Log::info(sprintf('No source/destination info for transaction type %s.', $type)); 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; return;
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Preference; use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -36,6 +37,8 @@ use Illuminate\Console\Command;
*/ */
class FixFrontpageAccounts extends Command class FixFrontpageAccounts extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Fixes a preference that may include deleted accounts or accounts of another type.'; protected $description = 'Fixes a preference that may include deleted accounts or accounts of another type.';
protected $signature = 'firefly-iii:fix-frontpage-accounts'; protected $signature = 'firefly-iii:fix-frontpage-accounts';
@@ -54,7 +57,7 @@ class FixFrontpageAccounts extends Command
$this->fixPreference($preference); $this->fixPreference($preference);
} }
} }
$this->info('Correct: account preferences are OK'); $this->friendlyPositive('Account preferences are OK');
return 0; return 0;
} }

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use DB; use DB;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Events\UpdatedTransactionGroup; use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Handlers\Events\UpdatedGroupEventHandler; use FireflyIII\Handlers\Events\UpdatedGroupEventHandler;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
@@ -36,6 +37,8 @@ use Illuminate\Console\Command;
*/ */
class FixGroupAccounts extends Command class FixGroupAccounts extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Unify the source / destination accounts of split groups.'; protected $description = 'Unify the source / destination accounts of split groups.';
protected $signature = 'firefly-iii:unify-group-accounts'; protected $signature = 'firefly-iii:unify-group-accounts';
@@ -62,7 +65,7 @@ class FixGroupAccounts extends Command
$handler->unifyAccounts($event); $handler->unifyAccounts($event);
} }
$this->info('Correct: updated possible inconsistent transaction groups.'); $this->friendlyPositive('Updated possible inconsistent transaction groups.');
return 0; return 0;
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -34,6 +35,8 @@ use Illuminate\Support\Collection;
*/ */
class FixIbans extends Command class FixIbans extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Removes spaces from IBANs'; protected $description = 'Removes spaces from IBANs';
protected $signature = 'firefly-iii:fix-ibans'; protected $signature = 'firefly-iii:fix-ibans';
private int $count = 0; private int $count = 0;
@@ -49,7 +52,7 @@ class FixIbans extends Command
$this->filterIbans($accounts); $this->filterIbans($accounts);
$this->countAndCorrectIbans($accounts); $this->countAndCorrectIbans($accounts);
if (0 === $this->count) { if (0 === $this->count) {
$this->info('Correct: All IBANs are valid.'); $this->friendlyPositive('All IBANs are valid.');
} }
return 0; return 0;
@@ -82,7 +85,7 @@ class FixIbans extends Command
&& // allowed combination && // allowed combination
!(AccountType::REVENUE === $set[$userId][$iban] && AccountType::EXPENSE === $type) // also allowed combination. !(AccountType::REVENUE === $set[$userId][$iban] && AccountType::EXPENSE === $type) // also allowed combination.
) { ) {
$this->line( $this->friendlyWarning(
sprintf( sprintf(
'IBAN "%s" is used more than once and will be removed from %s #%d ("%s")', 'IBAN "%s" is used more than once and will be removed from %s #%d ("%s")',
$iban, $iban,
@@ -118,7 +121,7 @@ class FixIbans extends Command
if ('' !== $iban) { if ('' !== $iban) {
$account->iban = $iban; $account->iban = $iban;
$account->save(); $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++; $this->count++;
} }
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -33,6 +34,8 @@ use Illuminate\Console\Command;
*/ */
class FixLongDescriptions extends Command class FixLongDescriptions extends Command
{ {
use ShowsFriendlyMessages;
private const MAX_LENGTH = 1000; private const MAX_LENGTH = 1000;
protected $description = 'Fixes long descriptions in journals and groups.'; protected $description = 'Fixes long descriptions in journals and groups.';
protected $signature = 'firefly-iii:fix-long-descriptions'; protected $signature = 'firefly-iii:fix-long-descriptions';
@@ -51,7 +54,7 @@ class FixLongDescriptions extends Command
if (strlen($journal->description) > self::MAX_LENGTH) { if (strlen($journal->description) > self::MAX_LENGTH) {
$journal->description = substr($journal->description, 0, self::MAX_LENGTH); $journal->description = substr($journal->description, 0, self::MAX_LENGTH);
$journal->save(); $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++; $count++;
} }
} }
@@ -62,12 +65,12 @@ class FixLongDescriptions extends Command
if (strlen((string)$group->title) > self::MAX_LENGTH) { if (strlen((string)$group->title) > self::MAX_LENGTH) {
$group->title = substr($group->title, 0, self::MAX_LENGTH); $group->title = substr($group->title, 0, self::MAX_LENGTH);
$group->save(); $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++; $count++;
} }
} }
if (0 === $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; return 0;

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\PiggyBankEvent; use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -34,6 +35,8 @@ use Illuminate\Console\Command;
*/ */
class FixPiggies extends Command class FixPiggies extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Fixes common issues with piggy banks.'; protected $description = 'Fixes common issues with piggy banks.';
protected $signature = 'firefly-iii:fix-piggies'; protected $signature = 'firefly-iii:fix-piggies';
@@ -63,10 +66,10 @@ class FixPiggies extends Command
} }
} }
if (0 === $count) { if (0 === $count) {
$this->info('Correct: all piggy bank events are OK.'); $this->friendlyPositive('All piggy bank events are OK.');
} }
if (0 !== $count) { 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; return 0;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Recurrence; use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceTransaction; use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
@@ -37,6 +38,8 @@ use Illuminate\Console\Command;
*/ */
class FixRecurringTransactions extends Command class FixRecurringTransactions extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Fixes recurring transactions with the wrong transaction type.'; protected $description = 'Fixes recurring transactions with the wrong transaction type.';
protected $signature = 'firefly-iii:fix-recurring-transactions'; protected $signature = 'firefly-iii:fix-recurring-transactions';
private int $count = 0; private int $count = 0;
@@ -53,7 +56,7 @@ class FixRecurringTransactions extends Command
$this->stupidLaravel(); $this->stupidLaravel();
$this->correctTransactions(); $this->correctTransactions();
if (0 === $this->count) { if (0 === $this->count) {
$this->info('Correct: all recurring transactions are OK.'); $this->friendlyPositive('All recurring transactions are OK.');
} }
return 0; return 0;
@@ -93,7 +96,7 @@ class FixRecurringTransactions extends Command
$type = $recurrence->transactionType; $type = $recurrence->transactionType;
$link = config(sprintf('firefly.account_to_transaction.%s.%s', $source->accountType->type, $destination->accountType->type)); $link = config(sprintf('firefly.account_to_transaction.%s.%s', $source->accountType->type, $destination->accountType->type));
if (null !== $link && strtolower($type->type) !== strtolower($link)) { 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) 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(); $transactionType = TransactionType::whereType($link)->first();

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
@@ -37,6 +38,8 @@ use Illuminate\Support\Collection;
*/ */
class FixTransactionTypes extends Command class FixTransactionTypes extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Make sure all transactions are of the correct type, based on source + dest.'; protected $description = 'Make sure all transactions are of the correct type, based on source + dest.';
protected $signature = 'firefly-iii:fix-transaction-types'; protected $signature = 'firefly-iii:fix-transaction-types';
@@ -57,11 +60,11 @@ class FixTransactionTypes extends Command
} }
} }
if ($count > 0) { 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; 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; return 0;
} }
@@ -102,13 +105,13 @@ class FixTransactionTypes extends Command
$source = $this->getSourceAccount($journal); $source = $this->getSourceAccount($journal);
$destination = $this->getDestinationAccount($journal); $destination = $this->getDestinationAccount($journal);
} catch (FireflyException $e) { } catch (FireflyException $e) {
$this->error($e->getMessage()); $this->friendlyError($e->getMessage());
return false; return false;
} }
$expectedType = (string)config(sprintf('firefly.account_to_transaction.%s.%s', $source->accountType->type, $destination->accountType->type)); $expectedType = (string)config(sprintf('firefly.account_to_transaction.%s.%s', $source->accountType->type, $destination->accountType->type));
if ($expectedType !== $type) { if ($expectedType !== $type) {
$this->line( $this->friendlyWarning(
sprintf( sprintf(
'Transaction journal #%d was of type "%s" but is corrected to "%s" (%s -> %s)', 'Transaction journal #%d was of type "%s" but is corrected to "%s" (%s -> %s)',
$journal->id, $journal->id,

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use DB; use DB;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -34,6 +35,8 @@ use stdClass;
*/ */
class FixUnevenAmount extends Command class FixUnevenAmount extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Fix journals with uneven amounts.'; protected $description = 'Fix journals with uneven amounts.';
protected $signature = 'firefly-iii:fix-uneven-amount'; protected $signature = 'firefly-iii:fix-uneven-amount';
@@ -54,21 +57,21 @@ class FixUnevenAmount extends Command
$sum = (string)$entry->the_sum; $sum = (string)$entry->the_sum;
if (!is_numeric($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); $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); app('log')->warning($message);
$count++; $count++;
continue; continue;
} }
if (0 !== bccomp((string)$entry->the_sum, '0')) { 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); $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); app('log')->warning($message);
$this->fixJournal((int)$entry->transaction_journal_id); $this->fixJournal((int)$entry->transaction_journal_id);
$count++; $count++;
} }
} }
if (0 === $count) { if (0 === $count) {
$this->info('Correct: Database amount integrity is OK'); $this->friendlyPositive('Database amount integrity is OK');
} }
return 0; return 0;
@@ -88,7 +91,7 @@ class FixUnevenAmount extends Command
$source = $journal->transactions()->where('amount', '<', 0)->first(); $source = $journal->transactions()->where('amount', '<', 0)->first();
if (null === $source) { if (null === $source) {
$this->error( $this->friendlyError(
sprintf( sprintf(
'Journal #%d ("%s") has no source transaction. It will be deleted to maintain database consistency.', 'Journal #%d ("%s") has no source transaction. It will be deleted to maintain database consistency.',
$journal->id ?? 0, $journal->id ?? 0,
@@ -108,7 +111,7 @@ class FixUnevenAmount extends Command
$destination = $journal->transactions()->where('amount', '>', 0)->first(); $destination = $journal->transactions()->where('amount', '>', 0)->first();
if (null === $destination) { if (null === $destination) {
$this->error( $this->friendlyError(
sprintf( sprintf(
'Journal #%d ("%s") has no destination transaction. It will be deleted to maintain database consistency.', 'Journal #%d ("%s") has no destination transaction. It will be deleted to maintain database consistency.',
$journal->id ?? 0, $journal->id ?? 0,
@@ -126,6 +129,6 @@ class FixUnevenAmount extends Command
$destination->save(); $destination->save();
$message = sprintf('Corrected amount in transaction journal #%d', $param); $message = sprintf('Corrected amount in transaction journal #%d', $param);
$this->line($message); $this->friendlyInfo($message);
} }
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -32,6 +33,8 @@ use Illuminate\Console\Command;
*/ */
class RemoveBills extends Command class RemoveBills extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Remove bills from transactions that shouldn\'t have one.'; protected $description = 'Remove bills from transactions that shouldn\'t have one.';
protected $signature = 'firefly-iii:remove-bills'; 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(); $journals = TransactionJournal::whereNotNull('bill_id')->where('transaction_type_id', '!=', $withdrawal->id)->get();
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($journals as $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->bill_id = null;
$journal->save(); $journal->save();
} }
if ($journals->count() > 0) { 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; return 0;
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use DB; use DB;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** /**
@@ -31,6 +32,8 @@ use Illuminate\Console\Command;
*/ */
class RenameMetaFields extends Command class RenameMetaFields extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Rename changed meta fields.'; protected $description = 'Rename changed meta fields.';
protected $signature = 'firefly-iii:rename-meta-fields'; protected $signature = 'firefly-iii:rename-meta-fields';
@@ -63,10 +66,10 @@ class RenameMetaFields extends Command
$this->rename($original, $update); $this->rename($original, $update);
} }
if (0 === $this->count) { if (0 === $this->count) {
$this->info('Correct: all meta fields are correct.'); $this->friendlyPositive('All meta fields are correct.');
} }
if (0 !== $this->count) { 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; return 0;
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -33,6 +34,8 @@ use Illuminate\Support\Facades\Log;
*/ */
class TransferBudgets extends Command class TransferBudgets extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Removes budgets from transfers.'; protected $description = 'Removes budgets from transfers.';
protected $signature = 'firefly-iii:fix-transfer-budgets'; protected $signature = 'firefly-iii:fix-transfer-budgets';
@@ -52,19 +55,19 @@ class TransferBudgets extends Command
/** @var TransactionJournal $entry */ /** @var TransactionJournal $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
$message = sprintf('Transaction journal #%d is a %s, so has no longer a budget.', $entry->id, $entry->transactionType->type); $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); Log::debug($message);
$entry->budgets()->sync([]); $entry->budgets()->sync([]);
$count++; $count++;
} }
if (0 === $count) { if (0 === $count) {
$message = 'Correct: no invalid budget/journal entries.'; $message = 'No invalid budget/journal entries.';
$this->info($message); $this->friendlyPositive($message);
} }
if (0 !== $count) { if (0 !== $count) {
$message = sprintf('Corrected %d invalid budget/journal entries (entry).', $count); $message = sprintf('Corrected %d invalid budget/journal entries (entry).', $count);
Log::debug($message); Log::debug($message);
$this->line($message); $this->friendlyInfo($message);
} }
return 0; return 0;
} }

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Console\Commands\Export;
use Carbon\Carbon; use Carbon\Carbon;
use Exception; use Exception;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Console\Commands\VerifiesAccessToken;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@@ -43,6 +44,7 @@ use Illuminate\Support\Facades\Log;
*/ */
class ExportData extends Command class ExportData extends Command
{ {
use ShowsFriendlyMessages;
use VerifiesAccessToken; use VerifiesAccessToken;
/** /**
@@ -86,7 +88,7 @@ class ExportData extends Command
{ {
// verify access token // verify access token
if (!$this->verifyAccessToken()) { if (!$this->verifyAccessToken()) {
$this->error('Invalid access token. Check /profile.'); $this->friendlyError('Invalid access token. Check /profile.');
return 1; return 1;
} }
@@ -99,7 +101,7 @@ class ExportData extends Command
try { try {
$options = $this->parseOptions(); $options = $this->parseOptions();
} catch (FireflyException $e) { } 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; return 1;
} }
@@ -122,14 +124,14 @@ class ExportData extends Command
$exporter->setExportPiggies($options['export']['piggies']); $exporter->setExportPiggies($options['export']['piggies']);
$data = $exporter->export(); $data = $exporter->export();
if (0 === count($data)) { 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; $returnCode = 0;
if (0 !== count($data)) { if (0 !== count($data)) {
try { try {
$this->exportData($options, $data); $this->exportData($options, $data);
} catch (FireflyException $e) { } 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; $returnCode = 1;
} }
@@ -139,16 +141,116 @@ class ExportData extends Command
} }
/** /**
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is * @param array $options
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should * @param array $data
* be called from the handle method instead of using the constructor to initialize the command.
* *
* @throws FireflyException
*/ */
private function stupidLaravel(): void private function exportData(array $options, array $data): void
{ {
$this->journalRepository = app(JournalRepositoryInterface::class); $date = date('Y_m_d');
$this->accountRepository = app(AccountRepositoryInterface::class); 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(); $this->journalRepository = app(JournalRepositoryInterface::class);
$error = false; $this->accountRepository = app(AccountRepositoryInterface::class);
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));
}
} }
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Integrity;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\GroupMembership; use FireflyIII\Models\GroupMembership;
use FireflyIII\Models\UserGroup; use FireflyIII\Models\UserGroup;
@@ -37,6 +38,8 @@ use Illuminate\Support\Facades\Log;
*/ */
class CreateGroupMemberships extends Command class CreateGroupMemberships extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '560_create_group_memberships'; public const CONFIG_NAME = '560_create_group_memberships';
protected $description = 'Update group memberships'; protected $description = 'Update group memberships';
protected $signature = 'firefly-iii:create-group-memberships'; protected $signature = 'firefly-iii:create-group-memberships';
@@ -88,7 +91,7 @@ class CreateGroupMemberships extends Command
public function handle(): int public function handle(): int
{ {
$this->createGroupMemberships(); $this->createGroupMemberships();
$this->info('Correct: validated group memberships'); $this->friendlyPositive('Validated group memberships');
return 0; return 0;
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Integrity;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
@@ -35,6 +36,8 @@ use stdClass;
*/ */
class ReportEmptyObjects extends Command class ReportEmptyObjects extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -81,7 +84,7 @@ class ReportEmptyObjects extends Command
foreach ($set as $entry) { foreach ($set as $entry) {
$line = 'User #%d (%s) has account #%d ("%s") which has no transactions.'; $line = 'User #%d (%s) has account #%d ("%s") which has no transactions.';
$line = sprintf($line, $entry->user_id, $entry->email, $entry->id, $entry->name); $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->id,
$entry->name $entry->name
); );
$this->line($line); $this->friendlyWarning($line);
} }
} }
@@ -130,7 +133,7 @@ class ReportEmptyObjects extends Command
$entry->id, $entry->id,
$entry->name $entry->name
); );
$this->line($line); $this->friendlyWarning($line);
} }
} }
@@ -155,7 +158,7 @@ class ReportEmptyObjects extends Command
$entry->id, $entry->id,
$entry->name $entry->name
); );
$this->line($line); $this->friendlyWarning($line);
} }
} }
@@ -180,7 +183,7 @@ class ReportEmptyObjects extends Command
$entry->id, $entry->id,
$entry->tag $entry->tag
); );
$this->line($line); $this->friendlyWarning($line);
} }
} }
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Integrity;
use Artisan; use Artisan;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Schema; use Schema;
@@ -34,6 +35,8 @@ use Schema;
*/ */
class ReportIntegrity extends Command class ReportIntegrity extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -63,7 +66,7 @@ class ReportIntegrity extends Command
'firefly-iii:upgrade-group-information', 'firefly-iii:upgrade-group-information',
]; ];
foreach ($commands as $command) { foreach ($commands as $command) {
$this->line(sprintf('Now executing %s', $command)); $this->friendlyLine(sprintf('Now executing %s', $command));
$this->call($command); $this->call($command);
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Integrity;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -32,6 +33,8 @@ use Illuminate\Console\Command;
*/ */
class ReportSum extends Command class ReportSum extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Report on the total sum of transactions. Must be 0.'; protected $description = 'Report on the total sum of transactions. Must be 0.';
protected $signature = 'firefly-iii:report-sum'; protected $signature = 'firefly-iii:report-sum';
@@ -60,15 +63,15 @@ class ReportSum extends Command
$sum = (string)$user->transactions()->sum('amount'); $sum = (string)$user->transactions()->sum('amount');
if (!is_numeric($sum)) { if (!is_numeric($sum)) {
$message = sprintf('Error: Transactions for user #%d (%s) have an invalid sum ("%s").', $user->id, $user->email, $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; continue;
} }
if (0 !== bccomp($sum, '0')) { if (0 !== bccomp($sum, '0')) {
$message = sprintf('Error: Transactions for user #%d (%s) are off by %s!', $user->id, $user->email, $sum); $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')) { 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));
} }
} }
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Integrity;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Support\System\OAuthKeys; use FireflyIII\Support\System\OAuthKeys;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -32,6 +33,8 @@ use Illuminate\Console\Command;
*/ */
class RestoreOAuthKeys extends Command class RestoreOAuthKeys extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Will restore the OAuth keys generated for the system.'; protected $description = 'Will restore the OAuth keys generated for the system.';
protected $signature = 'firefly-iii:restore-oauth-keys'; protected $signature = 'firefly-iii:restore-oauth-keys';
@@ -87,30 +90,30 @@ class RestoreOAuthKeys extends Command
if (!$this->keysInDatabase() && !$this->keysOnDrive()) { if (!$this->keysInDatabase() && !$this->keysOnDrive()) {
$this->generateKeys(); $this->generateKeys();
$this->storeKeysInDB(); $this->storeKeysInDB();
$this->line('Correct: generated and stored new keys.'); $this->friendlyInfo('Generated and stored new keys.');
return; return;
} }
if ($this->keysInDatabase() && !$this->keysOnDrive()) { if ($this->keysInDatabase() && !$this->keysOnDrive()) {
$result = $this->restoreKeysFromDB(); $result = $this->restoreKeysFromDB();
if (true === $result) { if (true === $result) {
$this->line('Correct: restored OAuth keys from database.'); $this->friendlyInfo('Restored OAuth keys from database.');
return; return;
} }
$this->generateKeys(); $this->generateKeys();
$this->storeKeysInDB(); $this->storeKeysInDB();
$this->line('Correct: generated and stored new keys.'); $this->friendlyInfo('Generated and stored new keys.');
return; return;
} }
if (!$this->keysInDatabase() && $this->keysOnDrive()) { if (!$this->keysInDatabase() && $this->keysOnDrive()) {
$this->storeKeysInDB(); $this->storeKeysInDB();
$this->line('Correct: stored OAuth keys in database.'); $this->friendlyInfo('Stored OAuth keys in database.');
return; return;
} }
$this->line('Correct: OAuth keys are OK'); $this->friendlyPositive('OAuth keys are OK');
} }
/** /**

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Integrity; namespace FireflyIII\Console\Commands\Integrity;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Attachment; use FireflyIII\Models\Attachment;
use FireflyIII\Models\AvailableBudget; use FireflyIII\Models\AvailableBudget;
@@ -48,6 +49,8 @@ use Illuminate\Database\QueryException;
*/ */
class UpdateGroupInformation extends Command class UpdateGroupInformation extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Makes sure that every object is linked to a group'; protected $description = 'Makes sure that every object is linked to a group';
protected $signature = 'firefly-iii:upgrade-group-information'; protected $signature = 'firefly-iii:upgrade-group-information';
@@ -74,7 +77,7 @@ class UpdateGroupInformation extends Command
{ {
$group = $user->userGroup; $group = $user->userGroup;
if (null === $group) { if (null === $group) {
$this->warn(sprintf('User "%s" has no group.', $user->email)); $this->friendlyWarning(sprintf('User "%s" has no group.', $user->email));
return; return;
} }
@@ -111,12 +114,12 @@ class UpdateGroupInformation extends Command
try { try {
$result = $className::where('user_id', $user->id)->where('user_group_id', null)->update(['user_group_id' => $group->id]); $result = $className::where('user_id', $user->id)->where('user_group_id', null)->update(['user_group_id' => $group->id]);
} catch (QueryException $e) { } 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; return;
} }
if (0 !== $result) { 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)));
} }
} }
} }

View File

@@ -0,0 +1,83 @@
<?php
/*
* ShowsFriendlyMessages.php
* Copyright (c) 2023 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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)));
}
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\System; namespace FireflyIII\Console\Commands\System;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use PDO; use PDO;
use PDOException; use PDOException;
@@ -33,6 +34,8 @@ use PDOException;
*/ */
class CreateDatabase extends Command class CreateDatabase extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -54,7 +57,7 @@ class CreateDatabase extends Command
public function handle(): int public function handle(): int
{ {
if ('mysql' !== env('DB_CONNECTION', 'mysql')) { 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; return 0;
} }
@@ -67,7 +70,7 @@ class CreateDatabase extends Command
if ('' !== env('DB_SOCKET', '')) { if ('' !== env('DB_SOCKET', '')) {
$dsn = sprintf('mysql:unix_socket=%s;charset=utf8mb4', 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 = [ $options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
@@ -79,7 +82,7 @@ class CreateDatabase extends Command
try { try {
$pdo = new PDO($dsn, env('DB_USERNAME'), env('DB_PASSWORD'), $options); $pdo = new PDO($dsn, env('DB_USERNAME'), env('DB_PASSWORD'), $options);
} catch (PDOException $e) { } 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. // only continue when no error.
@@ -96,14 +99,14 @@ class CreateDatabase extends Command
} }
} }
if (false === $exists && true === $checked) { 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. // try to create it.
$pdo->exec(sprintf('CREATE DATABASE `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;', env('DB_DATABASE'))); $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) { 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; return 0;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\System; namespace FireflyIII\Console\Commands\System;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
@@ -36,6 +37,8 @@ use Str;
*/ */
class CreateFirstUser extends Command class CreateFirstUser extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -58,14 +61,14 @@ class CreateFirstUser extends Command
public function handle(): int public function handle(): int
{ {
if ('testing' !== env('APP_ENV', 'local')) { 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; return 1;
} }
$this->stupidLaravel(); $this->stupidLaravel();
$count = $this->repository->count(); $count = $this->repository->count();
if ($count > 0) { 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; return 1;
} }
@@ -81,8 +84,8 @@ class CreateFirstUser extends Command
$user->save(); $user->save();
$user->setRememberToken(Str::random(60)); $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->friendlyInfo(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->friendlyWarning('Change this password.');
return 0; return 0;
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\System; namespace FireflyIII\Console\Commands\System;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AutoBudget; use FireflyIII\Models\AutoBudget;
@@ -51,6 +52,8 @@ use Illuminate\Support\Facades\Log;
*/ */
class ForceDecimalSize extends Command class ForceDecimalSize extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).'; protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).';
protected $signature = 'firefly-iii:force-decimal-size'; protected $signature = 'firefly-iii:force-decimal-size';
private string $cast; private string $cast;
@@ -96,8 +99,8 @@ class ForceDecimalSize extends Command
Log::debug('Now in ForceDecimalSize::handle()'); Log::debug('Now in ForceDecimalSize::handle()');
$this->determineDatabaseType(); $this->determineDatabaseType();
$this->error('Running this command is dangerous and can cause data loss.'); $this->friendlyError('Running this command is dangerous and can cause data loss.');
$this->error('Please do not continue.'); $this->friendlyError('Please do not continue.');
$question = $this->confirm('Do you want to continue?'); $question = $this->confirm('Do you want to continue?');
if (true === $question) { if (true === $question) {
$this->correctAmounts(); $this->correctAmounts();
@@ -136,7 +139,7 @@ class ForceDecimalSize extends Command
}); });
$result = $query->get(['accounts.*']); $result = $query->get(['accounts.*']);
if (0 === $result->count()) { 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; return;
} }
@@ -150,7 +153,7 @@ class ForceDecimalSize extends Command
// fix $field by rounding it down correctly. // fix $field by rounding it down correctly.
$pow = pow(10, (int)$currency->decimal_places); $pow = pow(10, (int)$currency->decimal_places);
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12); $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]); 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)) { 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; return;
} }
@@ -188,7 +191,6 @@ class ForceDecimalSize extends Command
*/ */
private function correctAmountsByCurrency(): void private function correctAmountsByCurrency(): void
{ {
$this->line('Going to correct amounts.');
/** @var Collection $enabled */ /** @var Collection $enabled */
$enabled = TransactionCurrency::whereEnabled(1)->get(); $enabled = TransactionCurrency::whereEnabled(1)->get();
/** @var TransactionCurrency $currency */ /** @var TransactionCurrency $currency */
@@ -207,7 +209,6 @@ class ForceDecimalSize extends Command
*/ */
private function correctByCurrency(TransactionCurrency $currency): void 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 string $name
* @var array $fields * @var array $fields
@@ -216,7 +217,7 @@ class ForceDecimalSize extends Command
switch ($name) { switch ($name) {
default: default:
$message = sprintf('Cannot handle table "%s"', $name); $message = sprintf('Cannot handle table "%s"', $name);
$this->line($message); $this->friendlyError($message);
throw new FireflyException($message); throw new FireflyException($message);
case 'accounts': case 'accounts':
$this->correctAccountAmounts($currency, $fields); $this->correctAccountAmounts($currency, $fields);
@@ -279,7 +280,7 @@ class ForceDecimalSize extends Command
$result = $query->get(['*']); $result = $query->get(['*']);
if (0 === $result->count()) { 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; return;
} }
@@ -293,7 +294,7 @@ class ForceDecimalSize extends Command
// fix $field by rounding it down correctly. // fix $field by rounding it down correctly.
$pow = pow(10, (int)$currency->decimal_places); $pow = pow(10, (int)$currency->decimal_places);
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12); $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]); $class::find($item->id)->update([$field => $correct]);
} }
} }
@@ -330,7 +331,7 @@ class ForceDecimalSize extends Command
$result = $query->get(['piggy_banks.*']); $result = $query->get(['piggy_banks.*']);
if (0 === $result->count()) { 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; return;
} }
@@ -344,7 +345,7 @@ class ForceDecimalSize extends Command
// fix $field by rounding it down correctly. // fix $field by rounding it down correctly.
$pow = pow(10, (int)$currency->decimal_places); $pow = pow(10, (int)$currency->decimal_places);
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12); $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]); PiggyBank::find($item->id)->update([$field => $correct]);
} }
} }
@@ -382,7 +383,7 @@ class ForceDecimalSize extends Command
$result = $query->get(['piggy_bank_events.*']); $result = $query->get(['piggy_bank_events.*']);
if (0 === $result->count()) { 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; return;
} }
@@ -396,7 +397,9 @@ class ForceDecimalSize extends Command
// fix $field by rounding it down correctly. // fix $field by rounding it down correctly.
$pow = pow(10, (int)$currency->decimal_places); $pow = pow(10, (int)$currency->decimal_places);
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12); $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]); PiggyBankEvent::find($item->id)->update([$field => $correct]);
} }
} }
@@ -434,7 +437,7 @@ class ForceDecimalSize extends Command
$result = $query->get(['piggy_bank_repetitions.*']); $result = $query->get(['piggy_bank_repetitions.*']);
if (0 === $result->count()) { 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; return;
} }
@@ -448,7 +451,9 @@ class ForceDecimalSize extends Command
// fix $field by rounding it down correctly. // fix $field by rounding it down correctly.
$pow = pow(10, (int)$currency->decimal_places); $pow = pow(10, (int)$currency->decimal_places);
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12); $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]); PiggyBankRepetition::find($item->id)->update([$field => $correct]);
} }
} }
@@ -473,7 +478,7 @@ class ForceDecimalSize extends Command
$result = $query->get(['transactions.*']); $result = $query->get(['transactions.*']);
if (0 === $result->count()) { 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 */ /** @var Transaction $item */
@@ -485,7 +490,7 @@ class ForceDecimalSize extends Command
// fix $field by rounding it down correctly. // fix $field by rounding it down correctly.
$pow = pow(10, (int)$currency->decimal_places); $pow = pow(10, (int)$currency->decimal_places);
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12); $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]); Transaction::find($item->id)->update(['amount' => $correct]);
} }
@@ -499,7 +504,7 @@ class ForceDecimalSize extends Command
$result = $query->get(['*']); $result = $query->get(['*']);
if (0 === $result->count()) { 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; return;
} }
@@ -512,7 +517,9 @@ class ForceDecimalSize extends Command
// fix $field by rounding it down correctly. // fix $field by rounding it down correctly.
$pow = pow(10, (int)$currency->decimal_places); $pow = pow(10, (int)$currency->decimal_places);
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12); $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]); Transaction::find($item->id)->update(['foreign_amount' => $correct]);
} }
} }
@@ -538,7 +545,7 @@ class ForceDecimalSize extends Command
*/ */
private function updateDecimals(): void 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'); $type = (string)config('database.default');
/** /**
@@ -548,11 +555,11 @@ class ForceDecimalSize extends Command
foreach ($this->tables as $name => $fields) { foreach ($this->tables as $name => $fields) {
/** @var string $field */ /** @var string $field */
foreach ($fields as $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) { switch ($type) {
default: default:
$this->error(sprintf('Cannot handle database type "%s".', $type)); $this->friendlyError(sprintf('Cannot handle database type "%s".', $type));
return; return;
case 'pgsql': case 'pgsql':

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\System; namespace FireflyIII\Console\Commands\System;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Console\Commands\VerifiesAccessToken;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -33,6 +34,7 @@ use Illuminate\Support\Facades\Schema;
class ForceMigration extends Command class ForceMigration extends Command
{ {
use ShowsFriendlyMessages;
use VerifiesAccessToken; use VerifiesAccessToken;
/** /**
@@ -58,13 +60,13 @@ class ForceMigration extends Command
public function handle(): int public function handle(): int
{ {
if (!$this->verifyAccessToken()) { if (!$this->verifyAccessToken()) {
$this->error('Invalid access token.'); $this->friendlyError('Invalid access token.');
return 1; return 1;
} }
$this->error('Running this command is dangerous and can cause data loss.'); $this->friendlyError('Running this command is dangerous and can cause data loss.');
$this->error('Please do not continue.'); $this->friendlyError('Please do not continue.');
$question = $this->confirm('Do you want to continue?'); $question = $this->confirm('Do you want to continue?');
if (true === $question) { if (true === $question) {
$user = $this->getUser(); $user = $this->getUser();
@@ -80,16 +82,16 @@ class ForceMigration extends Command
private function forceMigration(): void private function forceMigration(): void
{ {
DB::commit(); DB::commit();
$this->line('Dropping "migrations" table...'); $this->friendlyLine('Dropping "migrations" table...');
sleep(2); sleep(2);
Schema::dropIfExists('migrations'); Schema::dropIfExists('migrations');
$this->line('Re-run all migrations...'); $this->friendlyLine('Re-run all migrations...');
Artisan::call('migrate', ['--seed' => true]); Artisan::call('migrate', ['--seed' => true]);
sleep(2); sleep(2);
$this->line(''); $this->friendlyLine('');
$this->line('There is a good chance you just saw a lot of error messages.'); $this->friendlyWarning('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->friendlyWarning('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->friendlyWarning('The issue, whatever it was, may have been solved now.');
$this->line(''); $this->friendlyLine('');
} }
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\System; namespace FireflyIII\Console\Commands\System;
use Crypt; use Crypt;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Attachment; use FireflyIII\Models\Attachment;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
@@ -37,6 +38,8 @@ use Storage;
*/ */
class ScanAttachments extends Command class ScanAttachments extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -79,7 +82,7 @@ class ScanAttachments extends Command
$attachment->md5 = $md5; $attachment->md5 = $md5;
$attachment->mime = $mime; $attachment->mime = $mime;
$attachment->save(); $attachment->save();
$this->line(sprintf('Fixed attachment #%d', $attachment->id)); $this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id));
} }
return 0; return 0;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\System; namespace FireflyIII\Console\Commands\System;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** /**
@@ -31,6 +32,8 @@ use Illuminate\Console\Command;
*/ */
class SetLatestVersion extends Command class SetLatestVersion extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -52,13 +55,13 @@ class SetLatestVersion extends Command
public function handle(): int public function handle(): int
{ {
if (!$this->option('james-is-cool')) { if (!$this->option('james-is-cool')) {
$this->error('Am too!'); $this->friendlyError('Am too!');
return 0; return 0;
} }
app('fireflyconfig')->set('db_version', config('firefly.db_version')); app('fireflyconfig')->set('db_version', config('firefly.db_version'));
app('fireflyconfig')->set('ff3_version', config('firefly.version')); app('fireflyconfig')->set('ff3_version', config('firefly.version'));
$this->line('Updated version.'); $this->friendlyInfo('Updated version.');
return 0; return 0;
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\System; namespace FireflyIII\Console\Commands\System;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@@ -35,6 +36,8 @@ use Storage;
*/ */
class VerifySecurityAlerts extends Command class VerifySecurityAlerts extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -80,23 +83,23 @@ class VerifySecurityAlerts extends Command
// depends on level // depends on level
if ('info' === $array['level']) { if ('info' === $array['level']) {
Log::debug('INFO level alert'); Log::debug('INFO level alert');
$this->info($array['message']); $this->friendlyInfo($array['message']);
return 0; return 0;
} }
if ('warning' === $array['level']) { if ('warning' === $array['level']) {
Log::debug('WARNING level alert'); Log::debug('WARNING level alert');
$this->warn('------------------------ :o'); $this->friendlyWarning('------------------------ :o');
$this->warn($array['message']); $this->friendlyWarning($array['message']);
$this->warn('------------------------ :o'); $this->friendlyWarning('------------------------ :o');
return 0; return 0;
} }
if ('danger' === $array['level']) { if ('danger' === $array['level']) {
Log::debug('DANGER level alert'); Log::debug('DANGER level alert');
$this->error('------------------------ :-('); $this->friendlyError('------------------------ :-(');
$this->error($array['message']); $this->friendlyError($array['message']);
$this->error('------------------------ :-('); $this->friendlyError('------------------------ :-(');
return 0; return 0;
} }
@@ -104,8 +107,8 @@ class VerifySecurityAlerts extends Command
return 0; 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; return 0;
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Tools; namespace FireflyIII\Console\Commands\Tools;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Console\Commands\VerifiesAccessToken;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@@ -43,6 +44,7 @@ use Illuminate\Support\Facades\Log;
*/ */
class ApplyRules extends Command class ApplyRules extends Command
{ {
use ShowsFriendlyMessages;
use VerifiesAccessToken; use VerifiesAccessToken;
/** /**
@@ -88,7 +90,7 @@ class ApplyRules extends Command
$start = microtime(true); $start = microtime(true);
$this->stupidLaravel(); $this->stupidLaravel();
if (!$this->verifyAccessToken()) { if (!$this->verifyAccessToken()) {
$this->error('Invalid access token.'); $this->friendlyError('Invalid access token.');
return 1; return 1;
} }
@@ -111,11 +113,11 @@ class ApplyRules extends Command
$rulesToApply = $this->getRulesToApply(); $rulesToApply = $this->getRulesToApply();
$count = $rulesToApply->count(); $count = $rulesToApply->count();
if (0 === $count) { if (0 === $count) {
$this->error('No rules or rule groups have been included.'); $this->friendlyError('No rules or rule groups have been included.');
$this->warn('Make a selection using:'); $this->friendlyWarning('Make a selection using:');
$this->warn(' --rules=1,2,...'); $this->friendlyWarning(' --rules=1,2,...');
$this->warn(' --rule_groups=1,2,...'); $this->friendlyWarning(' --rule_groups=1,2,...');
$this->warn(' --all_rules'); $this->friendlyWarning(' --all_rules');
return 1; return 1;
} }
@@ -139,18 +141,61 @@ class ApplyRules extends Command
$ruleEngine->addOperator(['type' => 'date_before', 'value' => $this->endDate->format('Y-m-d')]); $ruleEngine->addOperator(['type' => 'date_before', 'value' => $this->endDate->format('Y-m-d')]);
// start running rules. // 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) // file the rule(s)
$ruleEngine->fire(); $ruleEngine->fire();
$this->line(''); $this->friendlyLine('');
$end = round(microtime(true) - $start, 2); $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 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 * 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 * 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'); $accountString = $this->option('accounts');
if (null === $accountString || '' === $accountString) { 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; return false;
} }
@@ -220,7 +265,7 @@ class ApplyRules extends Command
} }
if (0 === $finalList->count()) { 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; return false;
} }
@@ -229,53 +274,6 @@ class ApplyRules extends Command
return true; 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 * @throws FireflyException
*/ */
@@ -313,45 +311,49 @@ class ApplyRules extends Command
} }
/** /**
*/
private function grabAllRules(): void
{
$this->groups = $this->ruleGroupRepository->getActiveGroups();
}
/**
* @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;
}
/**
* @param Rule $rule
* @param RuleGroup $group
*
* @return bool * @return bool
*/ */
private function includeRule(Rule $rule, RuleGroup $group): bool private function verifyInputRuleGroups(): bool
{ {
return in_array($group->id, $this->ruleGroupSelection, true) $ruleGroupString = $this->option('rule_groups');
|| in_array($rule->id, $this->ruleSelection, true) if (null === $ruleGroupString || '' === $ruleGroupString) {
|| $this->allRules; // 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->friendlyWarning(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;
} }
} }

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Tools; namespace FireflyIII\Console\Commands\Tools;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Support\Cronjobs\AutoBudgetCronjob; use FireflyIII\Support\Cronjobs\AutoBudgetCronjob;
use FireflyIII\Support\Cronjobs\BillWarningCronjob; use FireflyIII\Support\Cronjobs\BillWarningCronjob;
@@ -43,6 +44,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class Cron extends Command class Cron extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -68,7 +71,7 @@ class Cron extends Command
try { try {
$date = new Carbon($this->option('date')); $date = new Carbon($this->option('date'));
} catch (InvalidArgumentException $e) { } 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'); $force = (bool)$this->option('force');
@@ -81,7 +84,7 @@ class Cron extends Command
} catch (FireflyException $e) { } catch (FireflyException $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
Log::error($e->getTraceAsString()); Log::error($e->getTraceAsString());
$this->error($e->getMessage()); $this->friendlyError($e->getMessage());
} }
} }
@@ -93,7 +96,7 @@ class Cron extends Command
} catch (FireflyException $e) { } catch (FireflyException $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
Log::error($e->getTraceAsString()); Log::error($e->getTraceAsString());
$this->error($e->getMessage()); $this->friendlyError($e->getMessage());
} }
/* /*
@@ -104,7 +107,7 @@ class Cron extends Command
} catch (FireflyException $e) { } catch (FireflyException $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
Log::error($e->getTraceAsString()); Log::error($e->getTraceAsString());
$this->error($e->getMessage()); $this->friendlyError($e->getMessage());
} }
/* /*
@@ -115,10 +118,10 @@ class Cron extends Command
} catch (FireflyException $e) { } catch (FireflyException $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
Log::error($e->getTraceAsString()); 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; return 0;
} }
@@ -140,13 +143,13 @@ class Cron extends Command
$autoBudget->fire(); $autoBudget->fire();
if ($autoBudget->jobErrored) { 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) { 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) { 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(); $autoBudget->fire();
if ($autoBudget->jobErrored) { 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) { 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) { 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(); $exchangeRates->fire();
if ($exchangeRates->jobErrored) { 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) { 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) { 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(); $recurring->fire();
if ($recurring->jobErrored) { 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) { 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) { 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));
} }
} }
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
@@ -42,6 +43,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class AccountCurrencies extends Command class AccountCurrencies extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_account_currencies'; public const CONFIG_NAME = '480_account_currencies';
protected $description = 'Give all accounts proper currency info.'; protected $description = 'Give all accounts proper currency info.';
@@ -59,17 +62,17 @@ class AccountCurrencies extends Command
{ {
$this->stupidLaravel(); $this->stupidLaravel();
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
$this->updateAccountCurrencies(); $this->updateAccountCurrencies();
if (0 === $this->count) { if (0 === $this->count) {
$this->info('Correct: all account currencies are OK.'); $this->friendlyPositive('All account currencies are OK.');
} }
if (0 !== $this->count) { if (0 !== $this->count) {
$this->line(sprintf('Corrected %d account(s).', $this->count)); $this->friendlyInfo(sprintf('Corrected %d account(s).', $this->count));
} }
$this->markAsExecuted(); $this->markAsExecuted();
@@ -122,7 +125,7 @@ class AccountCurrencies extends Command
if (0 === $accountCurrency && 0 === $obCurrency) { if (0 === $accountCurrency && 0 === $obCurrency) {
AccountMeta::where('account_id', $account->id)->where('name', 'currency_id')->forceDelete(); AccountMeta::where('account_id', $account->id)->where('name', 'currency_id')->forceDelete();
AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $currency->id]); 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++; $this->count++;
return; return;
@@ -131,7 +134,7 @@ class AccountCurrencies extends Command
// account is set to 0, opening balance is not? // account is set to 0, opening balance is not?
if (0 === $accountCurrency && $obCurrency > 0) { if (0 === $accountCurrency && $obCurrency > 0) {
AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $obCurrency]); 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++; $this->count++;
return; return;
@@ -147,7 +150,7 @@ class AccountCurrencies extends Command
$transaction->save(); $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++; $this->count++;
} }
} }
@@ -186,7 +189,7 @@ class AccountCurrencies extends Command
if (null === $defaultCurrency) { if (null === $defaultCurrency) {
Log::error(sprintf('Users currency pref "%s" does not exist!', $defaultCurrencyCode)); 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; return;
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -32,6 +33,8 @@ use Psr\Container\NotFoundExceptionInterface;
class AppendBudgetLimitPeriods extends Command class AppendBudgetLimitPeriods extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '550_budget_limit_periods'; public const CONFIG_NAME = '550_budget_limit_periods';
/** /**
* The console command description. * The console command description.
@@ -57,7 +60,7 @@ class AppendBudgetLimitPeriods extends Command
public function handle(): int public function handle(): int
{ {
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -82,7 +85,7 @@ class AppendBudgetLimitPeriods extends Command
$limit->start_date->format('Y-m-d'), $limit->start_date->format('Y-m-d'),
$limit->end_date->format('Y-m-d') $limit->end_date->format('Y-m-d')
); );
$this->warn($message); $this->friendlyWarning($message);
app('log')->warning($message); app('log')->warning($message);
return; return;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use DB; use DB;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
@@ -40,6 +41,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class BackToJournals extends Command class BackToJournals extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_back_to_journals'; public const CONFIG_NAME = '480_back_to_journals';
/** /**
* The console command description. * The console command description.
@@ -65,20 +68,20 @@ class BackToJournals extends Command
public function handle(): int public function handle(): int
{ {
if (!$this->isMigrated()) { 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')) { 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; return 0;
} }
if (true === $this->option('force')) { if (true === $this->option('force')) {
$this->warn('Forcing the command.'); $this->friendlyWarning('Forcing the command.');
} }
$this->migrateAll(); $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(); $this->markAsExecuted();
return 0; return 0;
@@ -177,7 +180,6 @@ class BackToJournals extends Command
$collected = TransactionJournal::whereIn('id', $journalIds)->with(['transactions', 'budgets', 'transactions.budgets'])->get(); $collected = TransactionJournal::whereIn('id', $journalIds)->with(['transactions', 'budgets', 'transactions.budgets'])->get();
$journals = $journals->merge($collected); $journals = $journals->merge($collected);
} }
$this->line(sprintf('Check %d transaction journal(s) for budget info.', count($journals)));
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($journals as $journal) { foreach ($journals as $journal) {
$this->migrateBudgetsForJournal($journal); $this->migrateBudgetsForJournal($journal);
@@ -193,7 +195,7 @@ class BackToJournals extends Command
/** @var Transaction|null $transaction */ /** @var Transaction|null $transaction */
$transaction = $journal->transactions->first(); $transaction = $journal->transactions->first();
if (null === $transaction) { 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; return;
} }
@@ -246,7 +248,7 @@ class BackToJournals extends Command
/** @var Transaction|null $transaction */ /** @var Transaction|null $transaction */
$transaction = $journal->transactions->first(); $transaction = $journal->transactions->first();
if (null === $transaction) { 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; return;
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -34,6 +35,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class BudgetLimitCurrency extends Command class BudgetLimitCurrency extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_bl_currency'; public const CONFIG_NAME = '480_bl_currency';
/** /**
* The console command description. * The console command description.
@@ -59,7 +62,7 @@ class BudgetLimitCurrency extends Command
public function handle(): int public function handle(): int
{ {
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -77,7 +80,7 @@ class BudgetLimitCurrency extends Command
$currency = app('amount')->getDefaultCurrencyByUser($user); $currency = app('amount')->getDefaultCurrencyByUser($user);
$budgetLimit->transaction_currency_id = $currency->id; $budgetLimit->transaction_currency_id = $currency->id;
$budgetLimit->save(); $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) sprintf('Budget limit #%d (part of budget "%s") now has a currency setting (%s).', $budgetLimit->id, $budget->name, $currency->name)
); );
$count++; $count++;
@@ -86,7 +89,7 @@ class BudgetLimitCurrency extends Command
} }
} }
if (0 === $count) { if (0 === $count) {
$this->info('Correct: all budget limits are OK.'); $this->friendlyPositive('All budget limits are OK.');
} }
$this->markAsExecuted(); $this->markAsExecuted();

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class CCLiabilities extends Command class CCLiabilities extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_cc_liabilities'; public const CONFIG_NAME = '480_cc_liabilities';
protected $description = 'Convert old credit card liabilities.'; protected $description = 'Convert old credit card liabilities.';
protected $signature = 'firefly-iii:cc-liabilities {--F|force : Force the execution of this command.}'; 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 public function handle(): int
{ {
$start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -62,7 +63,7 @@ class CCLiabilities extends Command
$ccType = AccountType::where('type', AccountType::CREDITCARD)->first(); $ccType = AccountType::where('type', AccountType::CREDITCARD)->first();
$debtType = AccountType::where('type', AccountType::DEBT)->first(); $debtType = AccountType::where('type', AccountType::DEBT)->first();
if (null === $ccType || null === $debtType) { if (null === $ccType || null === $debtType) {
$this->info('Correct: no incorrectly stored credit card liabilities.'); $this->friendlyPositive('No incorrectly stored credit card liabilities.');
$this->markAsExecuted(); $this->markAsExecuted();
return 0; return 0;
@@ -72,16 +73,16 @@ class CCLiabilities extends Command
foreach ($accounts as $account) { foreach ($accounts as $account) {
$account->account_type_id = $debtType->id; $account->account_type_id = $debtType->id;
$account->save(); $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) { 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()) { 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(); $this->markAsExecuted();
return 0; return 0;
@@ -95,11 +96,7 @@ class CCLiabilities extends Command
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { return (bool)$configVar?->data;
return (bool)$configVar->data;
}
return false;
} }
/** /**

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Console\Commands\Upgrade;
use Crypt; use Crypt;
use DB; use DB;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Preference; use FireflyIII\Models\Preference;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -41,6 +42,8 @@ use stdClass;
*/ */
class DecryptDatabase extends Command class DecryptDatabase extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Decrypts the database.'; protected $description = 'Decrypts the database.';
protected $signature = 'firefly-iii:decrypt-all'; 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; $newValue = json_decode($value, true, 512, JSON_THROW_ON_ERROR) ?? $value;
} catch (JsonException $e) { } catch (JsonException $e) {
$message = sprintf('Could not JSON decode preference row #%d: %s. This does not have to be a problem.', $id, $e->getMessage()); $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($message);
app('log')->warning($value); app('log')->warning($value);
app('log')->warning($e->getTraceAsString()); app('log')->warning($e->getTraceAsString());
@@ -132,7 +135,7 @@ class DecryptDatabase extends Command
$value = $this->tryDecrypt($original); $value = $this->tryDecrypt($original);
} catch (FireflyException $e) { } catch (FireflyException $e) {
$message = sprintf('Could not decrypt field "%s" in row #%d of table "%s": %s', $field, $id, $table, $e->getMessage()); $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($message);
Log::error($e->getTraceAsString()); Log::error($e->getTraceAsString());
} }
@@ -159,14 +162,14 @@ class DecryptDatabase extends Command
private function decryptTable(string $table, array $fields): void private function decryptTable(string $table, array $fields): void
{ {
if ($this->isDecrypted($table)) { 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; return;
} }
foreach ($fields as $field) { foreach ($fields as $field) {
$this->decryptField($table, $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: // mark as decrypted:
$configName = sprintf('is_decrypted_%s', $table); $configName = sprintf('is_decrypted_%s', $table);
app('fireflyconfig')->set($configName, true); app('fireflyconfig')->set($configName, true);

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use DB; use DB;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** /**
@@ -32,6 +33,8 @@ use Illuminate\Console\Command;
*/ */
class FixPostgresSequences extends Command class FixPostgresSequences extends Command
{ {
use ShowsFriendlyMessages;
/** /**
* The console command description. * The console command description.
* *
@@ -55,7 +58,7 @@ class FixPostgresSequences extends Command
if (DB::connection()->getName() !== 'pgsql') { if (DB::connection()->getName() !== 'pgsql') {
return 0; return 0;
} }
$this->line('Going to verify PostgreSQL table sequences.'); $this->friendlyLine('Going to verify PostgreSQL table sequences.');
$tablesToCheck = [ $tablesToCheck = [
'2fa_tokens', '2fa_tokens',
'account_meta', 'account_meta',
@@ -116,12 +119,13 @@ class FixPostgresSequences extends Command
]; ];
foreach ($tablesToCheck as $tableToCheck) { 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(); $highestId = DB::table($tableToCheck)->select(DB::raw('MAX(id)'))->first();
$nextId = DB::table($tableToCheck)->select(DB::raw(sprintf('nextval(\'%s_id_seq\')', $tableToCheck)))->first(); $nextId = DB::table($tableToCheck)->select(DB::raw(sprintf('nextval(\'%s_id_seq\')', $tableToCheck)))->first();
if (null === $nextId) { 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; continue;
} }
@@ -130,14 +134,14 @@ class FixPostgresSequences extends Command
$highestId = DB::table($tableToCheck)->select(DB::raw('MAX(id)'))->first(); $highestId = DB::table($tableToCheck)->select(DB::raw('MAX(id)'))->first();
$nextId = DB::table($tableToCheck)->select(DB::raw(sprintf('nextval(\'%s_id_seq\')', $tableToCheck)))->first(); $nextId = DB::table($tableToCheck)->select(DB::raw(sprintf('nextval(\'%s_id_seq\')', $tableToCheck)))->first();
if ($nextId->nextval > $highestId->max) { 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) { 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) { if ($nextId->nextval >= $highestId->max) {
$this->info(sprintf('Table "%s" autoincrement is correct.', $tableToCheck)); $this->friendlyPositive(sprintf('Table "%s" autoincrement is correct.', $tableToCheck));
} }
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Attachment; use FireflyIII\Models\Attachment;
use FireflyIII\Models\Note; use FireflyIII\Models\Note;
@@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class MigrateAttachments extends Command class MigrateAttachments extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_migrate_attachments'; public const CONFIG_NAME = '480_migrate_attachments';
/** /**
* The console command description. * The console command description.
@@ -62,7 +65,7 @@ class MigrateAttachments extends Command
{ {
$start = microtime(true); $start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -94,13 +97,13 @@ class MigrateAttachments extends Command
} }
} }
if (0 === $count) { if (0 === $count) {
$this->info('Correct: all attachments are OK.'); $this->friendlyPositive('All attachments are OK.');
} }
if (0 !== $count) { 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); $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(); $this->markAsExecuted();
return 0; return 0;

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Note; use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournalMeta; use FireflyIII\Models\TransactionJournalMeta;
@@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class MigrateJournalNotes extends Command class MigrateJournalNotes extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_migrate_notes'; public const CONFIG_NAME = '480_migrate_notes';
/** /**
* The console command description. * The console command description.
@@ -63,7 +66,7 @@ class MigrateJournalNotes extends Command
$start = microtime(true); $start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -88,14 +91,14 @@ class MigrateJournalNotes extends Command
} }
if (0 === $count) { if (0 === $count) {
$this->info('Correct: No notes to migrate.'); $this->friendlyPositive('No notes to migrate.');
} }
if (0 !== $count) { 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); $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(); $this->markAsExecuted();
return 0; return 0;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Recurrence; use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceMeta; use FireflyIII\Models\RecurrenceMeta;
@@ -38,6 +39,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class MigrateRecurrenceMeta extends Command class MigrateRecurrenceMeta extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '481_migrate_recurrence_meta'; public const CONFIG_NAME = '481_migrate_recurrence_meta';
/** /**
* The console command description. * The console command description.
@@ -64,17 +67,17 @@ class MigrateRecurrenceMeta extends Command
public function handle(): int public function handle(): int
{ {
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
$count = $this->migrateMetaData(); $count = $this->migrateMetaData();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: no recurrence meta data migrated.'); $this->friendlyPositive('No recurrence meta data migrated.');
} }
if ($count > 0) { if ($count > 0) {
$this->line(sprintf('Migrated %d meta data entries', $count)); $this->friendlyInfo(sprintf('Migrated %d meta data entries', $count));
} }
$this->markAsExecuted(); $this->markAsExecuted();

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Recurrence; use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceTransaction; use FireflyIII\Models\RecurrenceTransaction;
@@ -37,6 +38,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class MigrateRecurrenceType extends Command class MigrateRecurrenceType extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '550_migrate_recurrence_type'; public const CONFIG_NAME = '550_migrate_recurrence_type';
/** /**
* The console command description. * The console command description.
@@ -62,7 +65,7 @@ class MigrateRecurrenceType extends Command
public function handle(): int public function handle(): int
{ {
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -90,11 +93,7 @@ class MigrateRecurrenceType extends Command
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { return (bool)$configVar?->data;
return (bool)$configVar->data;
}
return false;
} }
/** /**
@@ -105,6 +104,10 @@ class MigrateRecurrenceType extends Command
app('fireflyconfig')->set(self::CONFIG_NAME, true); app('fireflyconfig')->set(self::CONFIG_NAME, true);
} }
/**
* @param Recurrence $recurrence
* @return void
*/
private function migrateRecurrence(Recurrence $recurrence): void private function migrateRecurrence(Recurrence $recurrence): void
{ {
$originalType = (int)$recurrence->transaction_type_id; $originalType = (int)$recurrence->transaction_type_id;
@@ -116,7 +119,7 @@ class MigrateRecurrenceType extends Command
$transaction->transaction_type_id = $originalType; $transaction->transaction_type_id = $originalType;
$transaction->save(); $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));
} }
/** /**

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Location; use FireflyIII\Models\Location;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
@@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class MigrateTagLocations extends Command class MigrateTagLocations extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '500_migrate_tag_locations'; public const CONFIG_NAME = '500_migrate_tag_locations';
/** /**
* The console command description. * The console command description.
@@ -61,7 +64,7 @@ class MigrateTagLocations extends Command
public function handle(): int public function handle(): int
{ {
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Console\Commands\Upgrade;
use DB; use DB;
use Exception; use Exception;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\TransactionGroupFactory; use FireflyIII\Factory\TransactionGroupFactory;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
@@ -49,6 +50,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class MigrateToGroups extends Command class MigrateToGroups extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_migrated_to_groups'; 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 $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.}'; 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(); $this->stupidLaravel();
if ($this->isMigrated() && true !== $this->option('force')) { if ($this->isMigrated() && true !== $this->option('force')) {
$this->info('Correct: database is already migrated.'); $this->friendlyInfo('Database is already migrated.');
return 0; return 0;
} }
if (true === $this->option('force')) { 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(); $this->makeGroupsFromAll();
if (0 !== $this->count) { 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) { if (0 === $this->count) {
$this->info('Correct: no journals to migrate to groups.'); $this->friendlyPositive('No journals to migrate to groups.');
} }
$this->markAsMigrated(); $this->markAsMigrated();
@@ -235,14 +238,14 @@ class MigrateToGroups extends Command
$total = count($orphanedJournals); $total = count($orphanedJournals);
if ($total > 0) { if ($total > 0) {
Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $total)); 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 */ /** @var array $array */
foreach ($orphanedJournals as $array) { foreach ($orphanedJournals as $array) {
$this->giveGroup($array); $this->giveGroup($array);
} }
} }
if (0 === $total) { 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(); $splitJournals = $this->cliRepository->getSplitJournals();
if ($splitJournals->count() > 0) { 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 */ /** @var TransactionJournal $journal */
foreach ($splitJournals as $journal) { foreach ($splitJournals as $journal) {
$this->makeMultiGroup($journal); $this->makeMultiGroup($journal);
@@ -320,7 +323,7 @@ class MigrateToGroups extends Command
$opposingTr = $this->findOpposingTransaction($journal, $transaction); $opposingTr = $this->findOpposingTransaction($journal, $transaction);
if (null === $opposingTr) { if (null === $opposingTr) {
$this->error( $this->friendlyError(
sprintf( sprintf(
'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.', 'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.',
$journal->id, $journal->id,
@@ -393,7 +396,7 @@ class MigrateToGroups extends Command
implode(', #', $group->transactionJournals->pluck('id')->toArray()) implode(', #', $group->transactionJournals->pluck('id')->toArray())
) )
); );
$this->line( $this->friendlyInfo(
sprintf( sprintf(
'Migrated journal #%d into group #%d with these journals: #%s', 'Migrated journal #%d into group #%d with these journals: #%s',
$journal->id, $journal->id,

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
use FireflyIII\Models\Preference; use FireflyIII\Models\Preference;
@@ -41,6 +42,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class MigrateToRules extends Command class MigrateToRules extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_bills_to_rules'; public const CONFIG_NAME = '480_bills_to_rules';
/** /**
* The console command description. * The console command description.
@@ -75,11 +78,9 @@ class MigrateToRules extends Command
public function handle(): int public function handle(): int
{ {
$this->stupidLaravel(); $this->stupidLaravel();
$start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -92,14 +93,12 @@ class MigrateToRules extends Command
} }
if (0 === $this->count) { if (0 === $this->count) {
$this->info('Correct: all bills are OK.'); $this->friendlyPositive('All bills are OK.');
} }
if (0 !== $this->count) { 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(); $this->markAsExecuted();
return 0; return 0;

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@@ -43,6 +44,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class OtherCurrenciesCorrections extends Command class OtherCurrenciesCorrections extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_other_currencies'; public const CONFIG_NAME = '480_other_currencies';
protected $description = 'Update all journal currency information.'; protected $description = 'Update all journal currency information.';
protected $signature = 'firefly-iii:other-currencies {--F|force : Force the execution of this command.}'; protected $signature = 'firefly-iii:other-currencies {--F|force : Force the execution of this command.}';
@@ -66,7 +69,7 @@ class OtherCurrenciesCorrections extends Command
$this->stupidLaravel(); $this->stupidLaravel();
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -75,7 +78,7 @@ class OtherCurrenciesCorrections extends Command
$this->updateOtherJournalsCurrencies(); $this->updateOtherJournalsCurrencies();
$this->markAsExecuted(); $this->markAsExecuted();
$this->info('Correct: verified and fixed transaction currencies.'); $this->friendlyPositive('Verified and fixed transaction currencies.');
return 0; return 0;
} }
@@ -202,7 +205,7 @@ class OtherCurrenciesCorrections extends Command
$leadTransaction = $this->getLeadTransaction($journal); $leadTransaction = $this->getLeadTransaction($journal);
if (null === $leadTransaction) { 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; return;
} }
@@ -210,7 +213,7 @@ class OtherCurrenciesCorrections extends Command
$account = $leadTransaction->account; $account = $leadTransaction->account;
$currency = $this->getCurrency($account); $currency = $this->getCurrency($account);
if (null === $currency) { if (null === $currency) {
$this->error( $this->friendlyError(
sprintf( sprintf(
'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', 'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected',
$account->id, $account->id,

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -34,6 +35,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class RenameAccountMeta extends Command class RenameAccountMeta extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_rename_account_meta'; public const CONFIG_NAME = '480_rename_account_meta';
/** /**
* The console command description. * The console command description.
@@ -59,7 +62,7 @@ class RenameAccountMeta extends Command
public function handle(): int public function handle(): int
{ {
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -86,10 +89,10 @@ class RenameAccountMeta extends Command
$this->markAsExecuted(); $this->markAsExecuted();
if (0 === $count) { if (0 === $count) {
$this->info('Correct: all account meta is OK.'); $this->friendlyPositive('All account meta is OK.');
} }
if (0 !== $count) { 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; return 0;

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
@@ -39,6 +40,8 @@ use Schema;
*/ */
class TransactionIdentifier extends Command class TransactionIdentifier extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_transaction_identifier'; public const CONFIG_NAME = '480_transaction_identifier';
protected $description = 'Fixes transaction identifiers.'; protected $description = 'Fixes transaction identifiers.';
protected $signature = 'firefly-iii:transaction-identifiers {--F|force : Force the execution of this command.}'; protected $signature = 'firefly-iii:transaction-identifiers {--F|force : Force the execution of this command.}';
@@ -64,7 +67,7 @@ class TransactionIdentifier extends Command
$this->stupidLaravel(); $this->stupidLaravel();
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -81,10 +84,10 @@ class TransactionIdentifier extends Command
} }
if (0 === $this->count) { 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) { 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(); $this->markAsExecuted();
@@ -111,10 +114,10 @@ class TransactionIdentifier extends Command
->first(); ->first();
} catch (QueryException $e) { } catch (QueryException $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
$this->error('Firefly III could not find the "identifier" field in the "transactions" table.'); $this->friendlyError('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->friendlyError(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->friendlyError('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('Then, run "php artisan firefly:upgrade-database" to try again.');
return null; return null;
} }

View File

@@ -23,7 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
@@ -41,6 +41,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class TransferCurrenciesCorrections extends Command class TransferCurrenciesCorrections extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_transfer_currencies'; public const CONFIG_NAME = '480_transfer_currencies';
protected $description = 'Updates transfer currency information.'; protected $description = 'Updates transfer currency information.';
protected $signature = 'firefly-iii:transfer-currencies {--F|force : Force the execution of this command.}'; protected $signature = 'firefly-iii:transfer-currencies {--F|force : Force the execution of this command.}';
@@ -66,7 +68,7 @@ class TransferCurrenciesCorrections extends Command
$this->stupidLaravel(); $this->stupidLaravel();
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -76,13 +78,11 @@ class TransferCurrenciesCorrections extends Command
$this->markAsExecuted(); $this->markAsExecuted();
if (0 === $this->count) { if (0 === $this->count) {
$message = 'Correct: all transfers have correct currency information.'; $this->friendlyPositive('All transfers have correct currency information.');
$this->info($message); return 0;
}
if (0 !== $this->count) {
$message = sprintf('Verified currency information of %d transfer(s).', $this->count);
$this->line($message);
} }
$this->friendlyInfo(sprintf('Verified currency information of %d transfer(s).', $this->count));
return 0; return 0;
} }
@@ -101,7 +101,7 @@ class TransferCurrenciesCorrections extends Command
$this->destinationTransaction->id, $this->destinationTransaction->id,
$this->destinationCurrency->code $this->destinationCurrency->code
); );
$this->line($message); $this->friendlyInfo($message);
$this->count++; $this->count++;
$this->destinationTransaction->save(); $this->destinationTransaction->save();
} }
@@ -117,7 +117,7 @@ class TransferCurrenciesCorrections extends Command
$this->destinationTransaction->foreign_amount = bcmul((string)$this->sourceTransaction->foreign_amount, '-1'); $this->destinationTransaction->foreign_amount = bcmul((string)$this->sourceTransaction->foreign_amount, '-1');
$this->destinationTransaction->save(); $this->destinationTransaction->save();
$this->count++; $this->count++;
$this->line( $this->friendlyInfo(
sprintf( sprintf(
'Restored foreign amount of destination transaction #%d to %s', 'Restored foreign amount of destination transaction #%d to %s',
$this->destinationTransaction->id, $this->destinationTransaction->id,
@@ -144,7 +144,7 @@ class TransferCurrenciesCorrections extends Command
$this->destinationAccount->id, $this->destinationAccount->id,
$this->destinationTransaction->amount $this->destinationTransaction->amount
); );
$this->line($message); $this->friendlyWarning($message);
$this->count++; $this->count++;
$this->destinationTransaction->transaction_currency_id = (int)$this->destinationCurrency->id; $this->destinationTransaction->transaction_currency_id = (int)$this->destinationCurrency->id;
$this->destinationTransaction->save(); $this->destinationTransaction->save();
@@ -187,7 +187,9 @@ class TransferCurrenciesCorrections extends Command
$this->sourceTransaction->save(); $this->sourceTransaction->save();
$this->destinationTransaction->save(); $this->destinationTransaction->save();
$this->count++; $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->sourceTransaction->id,
$this->sourceCurrency->code $this->sourceCurrency->code
); );
$this->line($message); $this->friendlyInfo($message);
$this->count++; $this->count++;
$this->sourceTransaction->save(); $this->sourceTransaction->save();
} }
@@ -222,7 +224,7 @@ class TransferCurrenciesCorrections extends Command
$this->sourceTransaction->foreign_amount = bcmul((string)$this->destinationTransaction->foreign_amount, '-1'); $this->sourceTransaction->foreign_amount = bcmul((string)$this->destinationTransaction->foreign_amount, '-1');
$this->sourceTransaction->save(); $this->sourceTransaction->save();
$this->count++; $this->count++;
$this->line( $this->friendlyInfo(
sprintf( sprintf(
'Restored foreign amount of source transaction #%d to %s', 'Restored foreign amount of source transaction #%d to %s',
$this->sourceTransaction->id, $this->sourceTransaction->id,
@@ -249,7 +251,7 @@ class TransferCurrenciesCorrections extends Command
$this->sourceAccount->id, $this->sourceAccount->id,
$this->sourceTransaction->amount $this->sourceTransaction->amount
); );
$this->line($message); $this->friendlyWarning($message);
$this->count++; $this->count++;
$this->sourceTransaction->transaction_currency_id = (int)$this->sourceCurrency->id; $this->sourceTransaction->transaction_currency_id = (int)$this->sourceCurrency->id;
$this->sourceTransaction->save(); $this->sourceTransaction->save();
@@ -274,7 +276,7 @@ class TransferCurrenciesCorrections extends Command
$oldCurrencyCode $oldCurrencyCode
); );
$this->count++; $this->count++;
$this->line($message); $this->friendlyInfo($message);
$journal->save(); $journal->save();
} }
} }
@@ -388,7 +390,7 @@ class TransferCurrenciesCorrections extends Command
if (null === $this->sourceCurrency) { if (null === $this->sourceCurrency) {
$message = sprintf('Account #%d ("%s") must have currency preference but has none.', $this->sourceAccount->id, $this->sourceAccount->name); $message = sprintf('Account #%d ("%s") must have currency preference but has none.', $this->sourceAccount->id, $this->sourceAccount->name);
Log::error($message); Log::error($message);
$this->error($message); $this->friendlyError($message);
return true; return true;
} }
@@ -401,7 +403,7 @@ class TransferCurrenciesCorrections extends Command
$this->destinationAccount->name $this->destinationAccount->name
); );
Log::error($message); Log::error($message);
$this->error($message); $this->friendlyError($message);
return true; return true;
} }
@@ -486,7 +488,7 @@ class TransferCurrenciesCorrections extends Command
if ($this->isSplitJournal($transfer)) { 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; return;
} }
@@ -498,7 +500,7 @@ class TransferCurrenciesCorrections extends Command
// unexpectedly, either one is null: // unexpectedly, either one is null:
if ($this->isEmptyTransactions()) { 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; return;
} }
@@ -506,7 +508,7 @@ class TransferCurrenciesCorrections extends Command
// both accounts must have currency preference: // both accounts must have currency preference:
if ($this->isNoCurrencyPresent()) { 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) sprintf('Source or destination accounts for transaction journal #%d have no currency information. Cannot fix this one.', $transfer->id)
); );

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Console\Commands\Upgrade;
set_time_limit(0); set_time_limit(0);
use Artisan; use Artisan;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** /**
@@ -35,6 +36,8 @@ use Illuminate\Console\Command;
*/ */
class UpgradeDatabase extends Command class UpgradeDatabase extends Command
{ {
use ShowsFriendlyMessages;
protected $description = 'Upgrades the database to the latest version.'; protected $description = 'Upgrades the database to the latest version.';
protected $signature = 'firefly-iii:upgrade-database {--F|force : Force all upgrades.}'; protected $signature = 'firefly-iii:upgrade-database {--F|force : Force all upgrades.}';
@@ -72,7 +75,7 @@ class UpgradeDatabase extends Command
$args = ['--force' => true]; $args = ['--force' => true];
} }
foreach ($commands as $command) { foreach ($commands as $command) {
$this->line(sprintf('Now executing %s', $command)); $this->friendlyLine(sprintf('Now executing %s', $command));
$this->call($command, $args); $this->call($command, $args);
} }
// set new DB version. // set new DB version.

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountMetaFactory; use FireflyIII\Factory\AccountMetaFactory;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@@ -42,6 +43,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class UpgradeLiabilities extends Command class UpgradeLiabilities extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '560_upgrade_liabilities'; public const CONFIG_NAME = '560_upgrade_liabilities';
protected $description = 'Upgrade liabilities to new 5.6.0 structure.'; protected $description = 'Upgrade liabilities to new 5.6.0 structure.';
protected $signature = 'firefly-iii:upgrade-liabilities {--F|force : Force the execution of this command.}'; 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 public function handle(): int
{ {
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@@ -44,6 +45,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class UpgradeLiabilitiesEight extends Command class UpgradeLiabilitiesEight extends Command
{ {
use ShowsFriendlyMessages;
public const CONFIG_NAME = '600_upgrade_liabilities'; public const CONFIG_NAME = '600_upgrade_liabilities';
protected $description = 'Upgrade liabilities to new 6.0.0 structure.'; protected $description = 'Upgrade liabilities to new 6.0.0 structure.';
protected $signature = 'firefly-iii:liabilities-600 {--F|force : Force the execution of this command.}'; 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 public function handle(): int
{ {
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }
@@ -257,12 +260,12 @@ class UpgradeLiabilitiesEight extends Command
if ('credit' === $direction && $this->hasBadOpening($account)) { if ('credit' === $direction && $this->hasBadOpening($account)) {
$this->deleteCreditTransaction($account); $this->deleteCreditTransaction($account);
$this->reverseOpeningBalance($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) { if ('credit' === $direction) {
$count = $this->deleteTransactions($account); $count = $this->deleteTransactions($account);
if ($count > 0) { 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));
} }
} }
} }

View File

@@ -33,7 +33,7 @@ class UpgradeSkeleton extends Command
{ {
$start = microtime(true); $start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) { 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; return 0;
} }