Rename and clean up commands.

This commit is contained in:
James Cole 2024-12-27 07:24:47 +01:00
parent 062c148e43
commit 36457455ca
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
42 changed files with 159 additions and 187 deletions

View File

@ -34,7 +34,7 @@ class CorrectsAccountOrder extends Command
use ShowsFriendlyMessages;
protected $description = 'Make sure account order is correct.';
protected $signature = 'firefly-iii:fix-account-order';
protected $signature = 'correction:account-order';
private AccountRepositoryInterface $repository;
@ -51,8 +51,6 @@ class CorrectsAccountOrder extends Command
$this->repository->resetAccountOrder();
}
$this->friendlyPositive('All accounts are ordered correctly');
return 0;
}

View File

@ -41,7 +41,7 @@ class CorrectsAccountTypes extends Command
use ShowsFriendlyMessages;
protected $description = 'Make sure all journals have the correct from/to account types.';
protected $signature = 'firefly-iii:fix-account-types';
protected $signature = 'correction:account-types';
private int $count;
private array $expected;
private AccountFactory $factory;
@ -117,9 +117,6 @@ class CorrectsAccountTypes extends Command
}
}
}
if (0 === $this->count) {
$this->friendlyPositive('All account types are OK');
}
if (0 !== $this->count) {
app('log')->debug(sprintf('%d journals had to be fixed.', $this->count));
$this->friendlyInfo(sprintf('Acted on %d transaction(s)', $this->count));

View File

@ -41,7 +41,7 @@ class CorrectsAmounts extends Command
use ShowsFriendlyMessages;
protected $description = 'This command makes sure positive and negative amounts are recorded correctly.';
protected $signature = 'correction:fix-amount-pos-neg';
protected $signature = 'correction:amounts';
public function handle(): int
{
@ -69,7 +69,6 @@ class CorrectsAmounts extends Command
{
$count = AutoBudget::where('amount', '<', 0)->update(['amount' => DB::raw('amount * -1')]);
if (0 === $count) {
$this->friendlyPositive('All auto budget amounts are positive.');
return;
}
@ -80,7 +79,6 @@ class CorrectsAmounts extends Command
{
$count = AvailableBudget::where('amount', '<', 0)->update(['amount' => DB::raw('amount * -1')]);
if (0 === $count) {
$this->friendlyPositive('All available budget amounts are positive.');
return;
}
@ -93,7 +91,6 @@ class CorrectsAmounts extends Command
$count += Bill::where('amount_max', '<', 0)->update(['amount_max' => DB::raw('amount_max * -1')]);
$count += Bill::where('amount_min', '<', 0)->update(['amount_min' => DB::raw('amount_min * -1')]);
if (0 === $count) {
$this->friendlyPositive('All bill amounts are positive.');
return;
}
@ -104,7 +101,6 @@ class CorrectsAmounts extends Command
{
$count = BudgetLimit::where('amount', '<', 0)->update(['amount' => DB::raw('amount * -1')]);
if (0 === $count) {
$this->friendlyPositive('All budget limit amounts are positive.');
return;
}
@ -115,7 +111,6 @@ class CorrectsAmounts extends Command
{
$count = CurrencyExchangeRate::where('rate', '<', 0)->update(['rate' => DB::raw('rate * -1')]);
if (0 === $count) {
$this->friendlyPositive('All currency exchange rates are positive.');
return;
}
@ -126,7 +121,6 @@ class CorrectsAmounts extends Command
{
$count = PiggyBank::where('target_amount', '<', 0)->update(['target_amount' => DB::raw('target_amount * -1')]);
if (0 === $count) {
$this->friendlyPositive('All piggy bank amounts are positive.');
return;
}
@ -139,7 +133,6 @@ class CorrectsAmounts extends Command
$count += RecurrenceTransaction::where('amount', '<', 0)->update(['amount' => DB::raw('amount * -1')]);
$count += RecurrenceTransaction::where('foreign_amount', '<', 0)->update(['foreign_amount' => DB::raw('foreign_amount * -1')]);
if (0 === $count) {
$this->friendlyPositive('All recurring transaction amounts are positive.');
return;
}
@ -162,7 +155,6 @@ class CorrectsAmounts extends Command
}
}
if (0 === $fixed) {
$this->friendlyPositive('All rule trigger amounts are positive.');
return;
}

View File

@ -42,7 +42,7 @@ class CorrectsCurrencies extends Command
use ShowsFriendlyMessages;
protected $description = 'Enables all currencies in use.';
protected $signature = 'firefly-iii:enable-currencies';
protected $signature = 'correction:currencies';
/**
* Execute the console command.

View File

@ -46,40 +46,36 @@ class CorrectsDatabase extends Command
return 1;
}
$commands = [
// also just in case, some integrity commands:
// 'upgrade:restore-oauth-keys',
// 'upgrade:add-timezones-to-dates',
// 'upgrade:create-group-memberships',
// 'upgrade:upgrade-group-information',
// 'upgrade:610-currency-preferences',
// 'upgrade:620-piggy-banks',
'firefly-iii:fix-piggies',
'firefly-iii:create-link-types',
'firefly-iii:create-access-tokens',
'firefly-iii:remove-bills',
'firefly-iii:fix-amount-pos-neg',
'firefly-iii:enable-currencies',
'firefly-iii:fix-transfer-budgets',
'firefly-iii:fix-uneven-amount',
'firefly-iii:delete-zero-amount',
'firefly-iii:delete-orphaned-transactions',
'firefly-iii:delete-empty-journals',
'firefly-iii:delete-empty-groups',
'firefly-iii:fix-account-types',
'firefly-iii:fix-ibans',
'firefly-iii:fix-account-order',
'firefly-iii:rename-meta-fields',
'firefly-iii:fix-ob-currencies',
'firefly-iii:fix-long-descriptions',
'firefly-iii:fix-recurring-transactions',
'firefly-iii:upgrade-group-information',
// 'firefly-iii:fix-transaction-types', // very resource heavy.
'firefly-iii:fix-frontpage-accounts',
// new!
'firefly-iii:unify-group-accounts',
'firefly-iii:trigger-credit-recalculation',
'firefly-iii:migrate-preferences',
'correction:restore-oauth-keys',
'correction:timezones',
'correction:create-group-memberships',
'correction:group-information',
'correction:piggy-banks',
'correction:link-types',
'correction:access-tokens',
'correction:bills',
'correction:amounts',
'correction:currencies',
'correction:transfer-budgets',
'correction:uneven-amounts',
'correction:zero-amounts',
'correction:orphaned-transactions',
'correction:empty-journals',
'correction:empty-groups',
'correction:account-types',
'correction:ibans',
'correction:account-order',
'correction:meta-fields',
'correction:opening-balance-currencies',
'correction:long-descriptions',
'correction:recurring-transactions',
'correction:frontpage-accounts',
'correction:group-accounts',
'correction:recalculates-liabilities',
'correction:preferences',
// 'correction:transaction-types', // resource heavy, disabled.
// 'correction:recalculate-native-amounts', // not necessary, disabled.
'firefly-iii:report-integrity',
];
foreach ($commands as $command) {
$this->friendlyLine(sprintf('Now executing command "%s"', $command));

View File

@ -36,7 +36,7 @@ class CorrectsFrontpageAccounts extends Command
use ShowsFriendlyMessages;
protected $description = 'Fixes a preference that may include deleted accounts or accounts of another type.';
protected $signature = 'firefly-iii:fix-frontpage-accounts';
protected $signature = 'correction:frontpage-accounts';
/**
* Execute the console command.
@ -52,8 +52,6 @@ class CorrectsFrontpageAccounts extends Command
$this->fixPreference($preference);
}
}
$this->friendlyPositive('Account preferences are OK');
return 0;
}

View File

@ -39,7 +39,7 @@ class CorrectsGroupAccounts extends Command
use ShowsFriendlyMessages;
protected $description = 'Unify the source / destination accounts of split groups.';
protected $signature = 'firefly-iii:unify-group-accounts';
protected $signature = 'correction:group-accounts';
/**
* Execute the console command.
@ -64,8 +64,6 @@ class CorrectsGroupAccounts extends Command
$handler->unifyAccounts($event);
}
$this->friendlyPositive('Updated possible inconsistent transaction groups.');
return 0;
}
}

View File

@ -50,7 +50,7 @@ class CorrectsGroupInformation extends Command
use ShowsFriendlyMessages;
protected $description = 'Makes sure that every object is linked to a group';
protected $signature = 'firefly-iii:upgrade-group-information';
protected $signature = 'correction:group-information';
/**
* Execute the console command.

View File

@ -35,7 +35,7 @@ class CorrectsIbans extends Command
use ShowsFriendlyMessages;
protected $description = 'Removes spaces from IBANs';
protected $signature = 'firefly-iii:fix-ibans';
protected $signature = 'correction:ibans';
private int $count = 0;
/**
@ -46,9 +46,6 @@ class CorrectsIbans extends Command
$accounts = Account::whereNotNull('iban')->get();
$this->filterIbans($accounts);
$this->countAndCorrectIbans($accounts);
if (0 === $this->count) {
$this->friendlyPositive('All IBANs are valid.');
}
return 0;
}

View File

@ -28,6 +28,7 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class CorrectsLongDescriptions extends Command
{
@ -35,14 +36,14 @@ class CorrectsLongDescriptions extends Command
private const int MAX_LENGTH = 1000;
protected $description = 'Fixes long descriptions in journals and groups.';
protected $signature = 'firefly-iii:fix-long-descriptions';
protected $signature = 'correction:long-descriptions';
/**
* Execute the console command.
*/
public function handle(): int
{
$journals = TransactionJournal::get(['id', 'description']);
$journals = TransactionJournal::where(DB::raw('LENGTH(description)'),'>', self::MAX_LENGTH)->get(['id', 'description']);
$count = 0;
/** @var TransactionJournal $journal */
@ -55,7 +56,7 @@ class CorrectsLongDescriptions extends Command
}
}
$groups = TransactionGroup::get(['id', 'title']);
$groups = TransactionGroup::where(DB::raw('LENGTH(title)'),'>', self::MAX_LENGTH)->get(['id', 'title']);
/** @var TransactionGroup $group */
foreach ($groups as $group) {
@ -66,9 +67,6 @@ class CorrectsLongDescriptions extends Command
++$count;
}
}
if (0 === $count) {
$this->friendlyPositive('All transaction group and journal title lengths are within bounds.');
}
return 0;
}

View File

@ -26,13 +26,14 @@ namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class CorrectsMetDataFields extends Command
class CorrectsMetaDataFields extends Command
{
use ShowsFriendlyMessages;
protected $description = 'Rename changed meta fields.';
protected $signature = 'firefly-iii:rename-meta-fields';
protected $signature = 'correction:meta-fields';
private int $count = 0;
@ -58,9 +59,6 @@ class CorrectsMetDataFields extends Command
foreach ($changes as $original => $update) {
$this->rename($original, $update);
}
if (0 === $this->count) {
$this->friendlyPositive('All meta fields are correct.');
}
if (0 !== $this->count) {
$this->friendlyInfo(sprintf('Renamed %d meta field(s).', $this->count));
}
@ -70,7 +68,7 @@ class CorrectsMetDataFields extends Command
private function rename(string $original, string $update): void
{
$total = \DB::table('journal_meta')
$total = DB::table('journal_meta')
->where('name', '=', $original)
->update(['name' => $update])
;

View File

@ -52,7 +52,7 @@ class CorrectsNativeAmounts extends Command
protected $description = 'Recalculate native amounts for all objects.';
protected $signature = 'firefly-iii:recalculate-native-amounts';
protected $signature = 'correction:recalculate-native-amounts';
/**
* Execute the console command.

View File

@ -40,7 +40,7 @@ class CorrectsOpeningBalanceCurrencies extends Command
use ShowsFriendlyMessages;
protected $description = 'Will make sure that opening balance transaction currencies match the account they\'re for.';
protected $signature = 'firefly-iii:fix-ob-currencies';
protected $signature = 'correction:opening-balance-currencies';
/**
* Execute the console command.
@ -59,10 +59,6 @@ class CorrectsOpeningBalanceCurrencies extends Command
$message = sprintf('Corrected %d opening balance transaction(s).', $count);
$this->friendlyInfo($message);
}
if (0 === $count) {
$message = 'There was nothing to fix in the opening balance transactions.';
$this->friendlyPositive($message);
}
return 0;
}

View File

@ -39,7 +39,7 @@ class CorrectsPiggyBanks extends Command
use ShowsFriendlyMessages;
protected $description = 'Fixes common issues with piggy banks.';
protected $signature = 'firefly-iii:fix-piggies';
protected $signature = 'correction:piggy-banks';
/**
* Execute the console command.
@ -66,9 +66,6 @@ class CorrectsPiggyBanks extends Command
continue;
}
}
if (0 === $count) {
$this->friendlyPositive('All piggy bank events are OK.');
}
if (0 !== $count) {
$this->friendlyInfo(sprintf('Fixed %d piggy bank event(s).', $count));
}

View File

@ -32,7 +32,7 @@ class CorrectsPreferences extends Command
{
protected $description = 'Give Firefly III preferences a user group ID so they can be made administration specific.';
protected $signature = 'firefly-iii:migrate-preferences';
protected $signature = 'correction:preferences';
/**
* Execute the console command.
@ -50,7 +50,7 @@ class CorrectsPreferences extends Command
if (null === $preference) {
continue;
}
if (null !== $preference->user_group_id) {
if (null === $preference->user_group_id) {
$preference->user_group_id = $user->user_group_id;
$preference->save();
++$count;

View File

@ -38,7 +38,7 @@ class CorrectsRecurringTransactions extends Command
use ShowsFriendlyMessages;
protected $description = 'Fixes recurring transactions with the wrong transaction type.';
protected $signature = 'firefly-iii:fix-recurring-transactions';
protected $signature = 'correction:recurring-transactions';
private int $count = 0;
private RecurringRepositoryInterface $recurringRepos;
private UserRepositoryInterface $userRepos;
@ -50,9 +50,6 @@ class CorrectsRecurringTransactions extends Command
{
$this->stupidLaravel();
$this->correctTransactions();
if (0 === $this->count) {
$this->friendlyPositive('All recurring transactions are OK.');
}
return 0;
}

View File

@ -92,7 +92,7 @@ class CorrectsTimezoneInformation extends Command
*
* @var string
*/
protected $signature = 'firefly-iii:add-timezones-to-dates';
protected $signature = 'correction:timezones';
/**
* Execute the console command.
@ -126,8 +126,6 @@ class CorrectsTimezoneInformation extends Command
Log::error($e->getMessage());
}
if (0 === $count) {
$this->friendlyPositive(sprintf('Timezone information is present in field "%s" of model "%s".', $field, $shortModel));
return;
}
$this->friendlyInfo(sprintf('Adding timezone information to field "%s" of model "%s".', $field, $shortModel));

View File

@ -39,7 +39,7 @@ class CorrectsTransactionTypes extends Command
use ShowsFriendlyMessages;
protected $description = 'Make sure all transactions are of the correct type, based on source + dest.';
protected $signature = 'firefly-iii:fix-transaction-types';
protected $signature = 'correction:transaction-types';
/**
* Execute the console command.

View File

@ -37,7 +37,7 @@ class CorrectsTransferBudgets extends Command
use ShowsFriendlyMessages;
protected $description = 'Removes budgets from transfers.';
protected $signature = 'firefly-iii:fix-transfer-budgets';
protected $signature = 'correction:transfer-budgets';
/**
* Execute the console command.
@ -60,10 +60,6 @@ class CorrectsTransferBudgets extends Command
$entry->budgets()->sync([]);
++$count;
}
if (0 === $count) {
$message = 'No invalid budget/journal entries.';
$this->friendlyPositive($message);
}
if (0 !== $count) {
$message = sprintf('Corrected %d invalid budget/journal entries (entry).', $count);
app('log')->debug($message);

View File

@ -41,7 +41,7 @@ class CorrectsUnevenAmount extends Command
use ShowsFriendlyMessages;
protected $description = 'Fix journals with uneven amounts.';
protected $signature = 'firefly-iii:fix-uneven-amount';
protected $signature = 'correction:uneven-amounts';
private int $count;
/**
@ -118,11 +118,6 @@ class CorrectsUnevenAmount extends Command
++$count;
}
}
if (0 === $count) {
$this->friendlyPositive('No "old style" foreign currency transfers.');
return;
}
}
private function fixUnevenAmounts(): void
@ -164,9 +159,6 @@ class CorrectsUnevenAmount extends Command
$this->fixJournal($entry->transaction_journal_id);
}
}
if (0 === $this->count) {
$this->friendlyPositive('Database amount integrity is OK');
}
}
private function fixJournal(int $param): void
@ -291,8 +283,6 @@ class CorrectsUnevenAmount extends Command
Log::debug(sprintf('Can skip foreign currency transfer #%d.', $journal->id));
}
if (0 === $count) {
$this->friendlyPositive('Journal currency integrity is OK');
return;
}

View File

@ -38,7 +38,7 @@ class CreatesAccessTokens extends Command
protected $description = 'Creates user access tokens which are used for command line access to personal data.';
protected $signature = 'firefly-iii:create-access-tokens';
protected $signature = 'correction:access-tokens';
/**
* Execute the console command.
@ -64,9 +64,6 @@ class CreatesAccessTokens extends Command
++$count;
}
}
if (0 === $count) {
$this->friendlyPositive('Verified access tokens.');
}
return 0;
}

View File

@ -39,7 +39,7 @@ class CreatesGroupMemberships extends Command
public const string CONFIG_NAME = '560_create_group_memberships';
protected $description = 'Update group memberships';
protected $signature = 'firefly-iii:create-group-memberships';
protected $signature = 'correction:create-group-memberships';
/**
* Execute the console command.
@ -49,7 +49,6 @@ class CreatesGroupMemberships extends Command
public function handle(): int
{
$this->createGroupMemberships();
$this->friendlyPositive('Validated group memberships');
return 0;
}

View File

@ -37,7 +37,7 @@ class CreatesLinkTypes extends Command
protected $description = 'Creates all link types.';
protected $signature = 'firefly-iii:create-link-types';
protected $signature = 'correction:link-types';
/**
* Execute the console command.
@ -66,9 +66,6 @@ class CreatesLinkTypes extends Command
$link->editable = false;
$link->save();
}
if (0 === $count) {
$this->friendlyPositive('All link types are OK');
}
return 0;
}

View File

@ -37,7 +37,7 @@ class RemovesBills extends Command
use ShowsFriendlyMessages;
protected $description = 'Remove bills from transactions that shouldn\'t have one.';
protected $signature = 'firefly-iii:remove-bills';
protected $signature = 'correction:bills';
/**
* Execute the console command.
@ -60,7 +60,6 @@ class RemovesBills extends Command
if ($journals->count() > 0) {
$this->friendlyInfo('Fixed all transaction journals so they have correct bill information.');
}
$this->friendlyPositive('All bills and journals are OK');
return 0;
}

View File

@ -37,7 +37,7 @@ class RemovesEmptyGroups extends Command
use ShowsFriendlyMessages;
protected $description = 'Delete empty transaction groups.';
protected $signature = 'firefly-iii:delete-empty-groups';
protected $signature = 'correction:empty-groups';
/**
* Execute the console command.
@ -61,9 +61,6 @@ class RemovesEmptyGroups extends Command
TransactionGroup::whereNull('deleted_at')->whereIn('id', $chunk)->delete();
}
}
if (0 === $total) {
$this->friendlyInfo('Verified there are no empty groups.');
}
return 0;
}

View File

@ -39,7 +39,7 @@ class RemovesEmptyJournals extends Command
protected $description = 'Delete empty and uneven transaction journals.';
protected $signature = 'firefly-iii:delete-empty-journals';
protected $signature = 'correction:empty-journals';
/**
* Execute the console command.
@ -82,9 +82,6 @@ class RemovesEmptyJournals extends Command
++$total;
}
}
if (0 === $total) {
$this->friendlyPositive('No uneven transaction journals.');
}
}
private function deleteEmptyJournals(): void
@ -107,8 +104,5 @@ class RemovesEmptyJournals extends Command
$this->friendlyInfo(sprintf('Deleted empty transaction journal #%d', $entry->id));
++$count;
}
if (0 === $count) {
$this->friendlyPositive('No empty transaction journals.');
}
}
}

View File

@ -38,7 +38,7 @@ class RemovesOrphanedTransactions extends Command
protected $description = 'Deletes orphaned transactions.';
protected $signature = 'firefly-iii:delete-orphaned-transactions';
protected $signature = 'correction:orphaned-transactions';
/**
* Execute the console command.
@ -63,7 +63,7 @@ class RemovesOrphanedTransactions extends Command
;
$count = $set->count();
if (0 === $count) {
$this->friendlyPositive('No orphaned journals.');
//$this->friendlyPositive('No orphaned journals.');
return;
}
@ -116,9 +116,6 @@ class RemovesOrphanedTransactions extends Command
++$count;
}
}
if (0 === $count) {
$this->friendlyPositive('No orphaned transactions.');
}
}
private function deleteFromOrphanedAccounts(): void
@ -147,8 +144,5 @@ class RemovesOrphanedTransactions extends Command
);
++$count;
}
if (0 === $count) {
$this->friendlyPositive('No orphaned accounts.');
}
}
}

View File

@ -29,16 +29,13 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
/**
* Class DeleteZeroAmount
*/
class DeletesZeroAmount extends Command
class RemovesZeroAmount extends Command
{
use ShowsFriendlyMessages;
protected $description = 'Delete transactions with zero amount.';
protected $signature = 'firefly-iii:delete-zero-amount';
protected $signature = 'correction:zero-amounts';
/**
* Execute the console command.
@ -56,9 +53,6 @@ class DeletesZeroAmount extends Command
Transaction::where('transaction_journal_id', $journal->id)->delete();
}
if (0 === $journals->count()) {
$this->friendlyPositive('No zero-amount transaction journals.');
}
return 0;
}

View File

@ -36,7 +36,7 @@ class RestoresOAuthKeys extends Command
use ShowsFriendlyMessages;
protected $description = 'Will restore the OAuth keys generated for the system.';
protected $signature = 'firefly-iii:restore-oauth-keys';
protected $signature = 'correction:restore-oauth-keys';
/**
* Execute the console command.
@ -76,7 +76,6 @@ class RestoresOAuthKeys extends Command
return;
}
$this->friendlyPositive('OAuth keys are OK');
}
private function keysInDatabase(): bool

View File

@ -28,13 +28,10 @@ use FireflyIII\Models\Account;
use FireflyIII\Services\Internal\Support\CreditRecalculateService;
use Illuminate\Console\Command;
/**
* Class CorrectionSkeleton
*/
class TriggersCreditCalculation extends Command
{
protected $description = 'Triggers the credit recalculation service for liabilities.';
protected $signature = 'firefly-iii:trigger-credit-recalculation';
protected $signature = 'correction:recalculates-liabilities';
/**
* Execute the console command.

View File

@ -32,9 +32,6 @@ use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use Illuminate\Console\Command;
use Illuminate\Database\QueryException;
/**
* Class TransactionIdentifier
*/
class AddsTransactionIdentifiers extends Command
{
use ShowsFriendlyMessages;

View File

@ -14,7 +14,7 @@ class UpgradeSkeleton extends Command
protected $description = 'SOME DESCRIPTION';
protected $signature = 'firefly-iii:UPGRSKELETON {--F|force : Force the execution of this command.}';
protected $signature = 'upgrade:UPGRSKELETON {--F|force : Force the execution of this command.}';
/**
* Execute the console command.

View File

@ -36,9 +36,6 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Console\Command;
/**
* Class AccountCurrencies
*/
class UpgradesAccountCurrencies extends Command
{
use ShowsFriendlyMessages;

View File

@ -30,9 +30,6 @@ use FireflyIII\Models\Attachment;
use FireflyIII\Models\Note;
use Illuminate\Console\Command;
/**
* Class MigrateAttachments
*/
class UpgradesAttachments extends Command
{
use ShowsFriendlyMessages;

View File

@ -32,9 +32,6 @@ use FireflyIII\User;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
/**
* Class UpgradesCurrencyPreferences
*/
class UpgradesCurrencyPreferences extends Command
{
use ShowsFriendlyMessages;

View File

@ -63,6 +63,10 @@ class UpgradesDatabase extends Command
'upgrade:550-budget-limit-periods',
'upgrade:600-rule-actions',
'upgrade:610-account-balance',
'upgrade:610-currency-preferences',
'upgrade:610-currency-preferences',
'upgrade:620-piggy-banks',
'upgrade:620-native-amounts',
'firefly-iii:correct-database',
];
$args = [];

View File

@ -0,0 +1,79 @@
<?php
/*
* UpgradesNativeAmounts.php
* Copyright (c) 2024 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\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
class UpgradesNativeAmounts extends Command
{
use ShowsFriendlyMessages;
public const string CONFIG_NAME = '620_native_amounts';
protected $description = 'Runs the native amounts calculations.';
protected $signature = 'upgrade:620-native-amounts {--F|force : Force the execution of this command.}';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
if ($this->isExecuted() && true !== $this->option('force')) {
$this->friendlyInfo('This command has already been executed.');
return 0;
}
Artisan::call('correction:recalculate-native-amounts');
$this->markAsExecuted();
return 0;
}
/**
* @return bool
*/
private function isExecuted(): bool
{
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) {
return (bool)$configVar->data;
}
return false;
}
/**
*
*/
private function markAsExecuted(): void
{
app('fireflyconfig')->set(self::CONFIG_NAME, true);
}
}

View File

@ -30,9 +30,6 @@ use FireflyIII\Models\RecurrenceMeta;
use FireflyIII\Models\RecurrenceTransactionMeta;
use Illuminate\Console\Command;
/**
* Class MigrateRecurrenceMeta
*/
class UpgradesRecurrenceMetaData extends Command
{
use ShowsFriendlyMessages;

View File

@ -27,9 +27,6 @@ namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command;
/**
* Class MigrateRecurrenceType
*/
class UpgradesRecurrenceType extends Command
{
use ShowsFriendlyMessages;

View File

@ -29,9 +29,6 @@ use FireflyIII\Models\Location;
use FireflyIII\Models\Tag;
use Illuminate\Console\Command;
/**
* Class MigrateTagLocations
*/
class UpgradesTagLocations extends Command
{
use ShowsFriendlyMessages;

View File

@ -34,10 +34,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use Illuminate\Console\Command;
/**
* Class UpgradeTransferCurrencies
*/
class UpgradeTransferCurrencies extends Command
class UpgradesTransferCurrencies extends Command
{
use ShowsFriendlyMessages;

View File

@ -39,13 +39,13 @@ class Preference extends Model
use ReturnsIntegerUserIdTrait;
protected $casts
= [
= [
'created_at' => 'datetime',
'updated_at' => 'datetime',
'data' => 'array',
];
protected $fillable = ['user_id', 'data', 'name'];
protected $fillable = ['user_id', 'data', 'name', 'user_group_id'];
/**
* Route binder. Converts the key in the URL to the specified object (or throw 404).
@ -56,7 +56,7 @@ class Preference extends Model
{
if (auth()->check()) {
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
// some preferences do not have an administration ID.
// some need it, to make sure the correct one is selected.
@ -64,8 +64,8 @@ class Preference extends Model
$userGroupId = 0 === $userGroupId ? null : $userGroupId;
/** @var null|Preference $preference */
$preference = null;
$items = config('firefly.admin_specific_prefs');
$preference = null;
$items = config('firefly.admin_specific_prefs');
if (null !== $userGroupId && in_array($value, $items, true)) {
// find a preference with a specific user_group_id
$preference = $user->preferences()->where('user_group_id', $userGroupId)->where('name', $value)->first();
@ -82,7 +82,7 @@ class Preference extends Model
if (null !== $preference) {
return $preference;
}
$default = config('firefly.default_preferences');
$default = config('firefly.default_preferences');
if (array_key_exists($value, $default)) {
$preference = new self();
$preference->name = $value;