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

View File

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

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use DB;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
@@ -40,6 +41,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/
class BackToJournals extends Command
{
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_back_to_journals';
/**
* The console command description.
@@ -65,20 +68,20 @@ class BackToJournals extends Command
public function handle(): int
{
if (!$this->isMigrated()) {
$this->error('Please run firefly-iii:migrate-to-groups first.');
$this->friendlyError('Please run firefly-iii:migrate-to-groups first.');
}
if ($this->isExecuted() && true !== $this->option('force')) {
$this->info('Correct: this command has already been executed.');
$this->friendlyInfo('This command has already been executed.');
return 0;
}
if (true === $this->option('force')) {
$this->warn('Forcing the command.');
$this->friendlyWarning('Forcing the command.');
}
$this->migrateAll();
$this->info('Correct: updated category and budget info for all transaction journals');
$this->friendlyInfo('Updated category and budget info for all transaction journals');
$this->markAsExecuted();
return 0;
@@ -177,7 +180,6 @@ class BackToJournals extends Command
$collected = TransactionJournal::whereIn('id', $journalIds)->with(['transactions', 'budgets', 'transactions.budgets'])->get();
$journals = $journals->merge($collected);
}
$this->line(sprintf('Check %d transaction journal(s) for budget info.', count($journals)));
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
$this->migrateBudgetsForJournal($journal);
@@ -193,7 +195,7 @@ class BackToJournals extends Command
/** @var Transaction|null $transaction */
$transaction = $journal->transactions->first();
if (null === $transaction) {
$this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
$this->friendlyInfo(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
return;
}
@@ -246,7 +248,7 @@ class BackToJournals extends Command
/** @var Transaction|null $transaction */
$transaction = $journal->transactions->first();
if (null === $transaction) {
$this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
$this->friendlyInfo(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
return;
}

View File

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

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/
class CCLiabilities extends Command
{
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_cc_liabilities';
protected $description = 'Convert old credit card liabilities.';
protected $signature = 'firefly-iii:cc-liabilities {--F|force : Force the execution of this command.}';
@@ -50,10 +53,8 @@ class CCLiabilities extends Command
*/
public function handle(): int
{
$start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) {
$this->info('Correct: this command has already been executed.');
$this->friendlyInfo('This command has already been executed.');
return 0;
}
@@ -62,7 +63,7 @@ class CCLiabilities extends Command
$ccType = AccountType::where('type', AccountType::CREDITCARD)->first();
$debtType = AccountType::where('type', AccountType::DEBT)->first();
if (null === $ccType || null === $debtType) {
$this->info('Correct: no incorrectly stored credit card liabilities.');
$this->friendlyPositive('No incorrectly stored credit card liabilities.');
$this->markAsExecuted();
return 0;
@@ -72,16 +73,16 @@ class CCLiabilities extends Command
foreach ($accounts as $account) {
$account->account_type_id = $debtType->id;
$account->save();
$this->line(sprintf('Converted credit card liability account "%s" (#%d) to generic debt liability.', $account->name, $account->id));
$this->friendlyInfo(sprintf('Converted credit card liability account "%s" (#%d) to generic debt liability.', $account->name, $account->id));
}
if ($accounts->count() > 0) {
$this->info('Credit card liability types are no longer supported and have been converted to generic debts. See: https://bit.ly/FF3-credit-cards');
$this->friendlyWarning(
'Credit card liability types are no longer supported and have been converted to generic debts. See: https://bit.ly/FF3-credit-cards'
);
}
if (0 === $accounts->count()) {
$this->info('Correct: no incorrectly stored credit card liabilities.');
$this->friendlyPositive('No incorrectly stored credit card liabilities.');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified credit card liabilities in %s seconds', $end));
$this->markAsExecuted();
return 0;
@@ -95,11 +96,7 @@ class CCLiabilities extends Command
private function isExecuted(): bool
{
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) {
return (bool)$configVar->data;
}
return false;
return (bool)$configVar?->data;
}
/**

View File

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

View File

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

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\Note;
@@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/
class MigrateAttachments extends Command
{
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_migrate_attachments';
/**
* The console command description.
@@ -62,7 +65,7 @@ class MigrateAttachments extends Command
{
$start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) {
$this->info('Correct: this command has already been executed.');
$this->friendlyInfo('This command has already been executed.');
return 0;
}
@@ -94,13 +97,13 @@ class MigrateAttachments extends Command
}
}
if (0 === $count) {
$this->info('Correct: all attachments are OK.');
$this->friendlyPositive('All attachments are OK.');
}
if (0 !== $count) {
$this->line(sprintf('Updated %d attachment(s).', $count));
$this->friendlyInfo(sprintf('Updated %d attachment(s).', $count));
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Migrated attachment notes in %s seconds.', $end));
$this->friendlyInfo(sprintf('Migrated attachment notes in %s seconds.', $end));
$this->markAsExecuted();
return 0;

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournalMeta;
@@ -36,6 +37,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/
class MigrateJournalNotes extends Command
{
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_migrate_notes';
/**
* The console command description.
@@ -63,7 +66,7 @@ class MigrateJournalNotes extends Command
$start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) {
$this->info('Correct: this command has already been executed.');
$this->friendlyInfo('This command has already been executed.');
return 0;
}
@@ -88,14 +91,14 @@ class MigrateJournalNotes extends Command
}
if (0 === $count) {
$this->info('Correct: No notes to migrate.');
$this->friendlyPositive('No notes to migrate.');
}
if (0 !== $count) {
$this->line(sprintf('Migrated %d note(s).', $count));
$this->friendlyInfo(sprintf('Migrated %d note(s).', $count));
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Migrated notes in %s seconds.', $end));
$this->friendlyInfo(sprintf('Migrated notes in %s seconds.', $end));
$this->markAsExecuted();
return 0;

View File

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

View File

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

View File

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

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Console\Commands\Upgrade;
use DB;
use Exception;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\TransactionGroupFactory;
use FireflyIII\Models\Budget;
@@ -49,6 +50,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/
class MigrateToGroups extends Command
{
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_migrated_to_groups';
protected $description = 'Migrates a pre-4.7.8 transaction structure to the 4.7.8+ transaction structure.';
protected $signature = 'firefly-iii:migrate-to-groups {--F|force : Force the migration, even if it fired before.}';
@@ -68,13 +71,13 @@ class MigrateToGroups extends Command
$this->stupidLaravel();
if ($this->isMigrated() && true !== $this->option('force')) {
$this->info('Correct: database is already migrated.');
$this->friendlyInfo('Database is already migrated.');
return 0;
}
if (true === $this->option('force')) {
$this->warn('Forcing the migration.');
$this->friendlyWarning('Forcing the migration.');
}
@@ -82,10 +85,10 @@ class MigrateToGroups extends Command
$this->makeGroupsFromAll();
if (0 !== $this->count) {
$this->line(sprintf('Migrated %d transaction journal(s).', $this->count));
$this->friendlyInfo(sprintf('Migrated %d transaction journal(s).', $this->count));
}
if (0 === $this->count) {
$this->info('Correct: no journals to migrate to groups.');
$this->friendlyPositive('No journals to migrate to groups.');
}
$this->markAsMigrated();
@@ -235,14 +238,14 @@ class MigrateToGroups extends Command
$total = count($orphanedJournals);
if ($total > 0) {
Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $total));
$this->line(sprintf('Going to convert %d transaction journals. Please hold..', $total));
$this->friendlyInfo(sprintf('Going to convert %d transaction journals. Please hold..', $total));
/** @var array $array */
foreach ($orphanedJournals as $array) {
$this->giveGroup($array);
}
}
if (0 === $total) {
$this->info('Correct: no need to convert transaction journals.');
$this->friendlyPositive('No need to convert transaction journals.');
}
}
@@ -253,7 +256,7 @@ class MigrateToGroups extends Command
{
$splitJournals = $this->cliRepository->getSplitJournals();
if ($splitJournals->count() > 0) {
$this->info(sprintf('Going to convert %d split transaction(s). Please hold..', $splitJournals->count()));
$this->friendlyLine(sprintf('Going to convert %d split transaction(s). Please hold..', $splitJournals->count()));
/** @var TransactionJournal $journal */
foreach ($splitJournals as $journal) {
$this->makeMultiGroup($journal);
@@ -320,7 +323,7 @@ class MigrateToGroups extends Command
$opposingTr = $this->findOpposingTransaction($journal, $transaction);
if (null === $opposingTr) {
$this->error(
$this->friendlyError(
sprintf(
'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.',
$journal->id,
@@ -393,7 +396,7 @@ class MigrateToGroups extends Command
implode(', #', $group->transactionJournals->pluck('id')->toArray())
)
);
$this->line(
$this->friendlyInfo(
sprintf(
'Migrated journal #%d into group #%d with these journals: #%s',
$journal->id,

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Preference;
@@ -41,6 +42,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/
class MigrateToRules extends Command
{
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_bills_to_rules';
/**
* The console command description.
@@ -75,11 +78,9 @@ class MigrateToRules extends Command
public function handle(): int
{
$this->stupidLaravel();
$start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) {
$this->info('Correct: this command has already been executed.');
$this->friendlyInfo('This command has already been executed.');
return 0;
}
@@ -92,14 +93,12 @@ class MigrateToRules extends Command
}
if (0 === $this->count) {
$this->info('Correct: all bills are OK.');
$this->friendlyPositive('All bills are OK.');
}
if (0 !== $this->count) {
$this->line(sprintf('Verified and fixed %d bill(s).', $this->count));
$this->friendlyInfo(sprintf('Verified and fixed %d bill(s).', $this->count));
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified and fixed bills in %s seconds.', $end));
$this->markAsExecuted();
return 0;

View File

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

View File

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

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
@@ -39,6 +40,8 @@ use Schema;
*/
class TransactionIdentifier extends Command
{
use ShowsFriendlyMessages;
public const CONFIG_NAME = '480_transaction_identifier';
protected $description = 'Fixes transaction identifiers.';
protected $signature = 'firefly-iii:transaction-identifiers {--F|force : Force the execution of this command.}';
@@ -64,7 +67,7 @@ class TransactionIdentifier extends Command
$this->stupidLaravel();
if ($this->isExecuted() && true !== $this->option('force')) {
$this->info('Correct: this command has already been executed.');
$this->friendlyInfo('This command has already been executed.');
return 0;
}
@@ -81,10 +84,10 @@ class TransactionIdentifier extends Command
}
if (0 === $this->count) {
$this->line('Correct: all split journal transaction identifiers are OK.');
$this->friendlyPositive('All split journal transaction identifiers are OK.');
}
if (0 !== $this->count) {
$this->line(sprintf('Correct: fixed %d split journal transaction identifier(s).', $this->count));
$this->friendlyInfo(sprintf('Fixed %d split journal transaction identifier(s).', $this->count));
}
$this->markAsExecuted();
@@ -111,10 +114,10 @@ class TransactionIdentifier extends Command
->first();
} catch (QueryException $e) {
Log::error($e->getMessage());
$this->error('Firefly III could not find the "identifier" field in the "transactions" table.');
$this->error(sprintf('This field is required for Firefly III version %s to run.', config('firefly.version')));
$this->error('Please run "php artisan migrate" to add this field to the table.');
$this->info('Then, run "php artisan firefly:upgrade-database" to try again.');
$this->friendlyError('Firefly III could not find the "identifier" field in the "transactions" table.');
$this->friendlyError(sprintf('This field is required for Firefly III version %s to run.', config('firefly.version')));
$this->friendlyError('Please run "php artisan migrate" to add this field to the table.');
$this->friendlyError('Then, run "php artisan firefly:upgrade-database" to try again.');
return null;
}

View File

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

View File

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

View File

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

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@@ -44,6 +45,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/
class UpgradeLiabilitiesEight extends Command
{
use ShowsFriendlyMessages;
public const CONFIG_NAME = '600_upgrade_liabilities';
protected $description = 'Upgrade liabilities to new 6.0.0 structure.';
protected $signature = 'firefly-iii:liabilities-600 {--F|force : Force the execution of this command.}';
@@ -59,7 +62,7 @@ class UpgradeLiabilitiesEight extends Command
public function handle(): int
{
if ($this->isExecuted() && true !== $this->option('force')) {
$this->info('Correct: this command has already been executed.');
$this->friendlyInfo('This command has already been executed.');
return 0;
}
@@ -257,12 +260,12 @@ class UpgradeLiabilitiesEight extends Command
if ('credit' === $direction && $this->hasBadOpening($account)) {
$this->deleteCreditTransaction($account);
$this->reverseOpeningBalance($account);
$this->line(sprintf('Corrected opening balance for liability #%d ("%s")', $account->id, $account->name));
$this->friendlyInfo(sprintf('Corrected opening balance for liability #%d ("%s")', $account->id, $account->name));
}
if ('credit' === $direction) {
$count = $this->deleteTransactions($account);
if ($count > 0) {
$this->line(sprintf('Removed %d old format transaction(s) for liability #%d ("%s")', $count, $account->id, $account->name));
$this->friendlyInfo(sprintf('Removed %d old format transaction(s) for liability #%d ("%s")', $count, $account->id, $account->name));
}
}
}

View File

@@ -33,7 +33,7 @@ class UpgradeSkeleton extends Command
{
$start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) {
$this->info('Correct: this command has already been executed.');
$this->info('FRIENDLY This command has already been executed.');
return 0;
}