mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
chore: code cleanup.
This commit is contained in:
@@ -91,6 +91,7 @@ class CorrectAmounts extends Command
|
||||
$count = $set->count();
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: All auto budget amounts are positive.');
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var AutoBudget $item */
|
||||
@@ -110,6 +111,7 @@ class CorrectAmounts extends Command
|
||||
$count = $set->count();
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: All available budget amounts are positive.');
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var AvailableBudget $item */
|
||||
@@ -129,6 +131,7 @@ class CorrectAmounts extends Command
|
||||
$count = $set->count();
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: All bill amounts are positive.');
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var Bill $item */
|
||||
@@ -148,6 +151,7 @@ class CorrectAmounts extends Command
|
||||
$count = $set->count();
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: All budget limit amounts are positive.');
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var BudgetLimit $item */
|
||||
@@ -167,6 +171,7 @@ class CorrectAmounts extends Command
|
||||
$count = $set->count();
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: All currency exchange rates are positive.');
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var BudgetLimit $item */
|
||||
@@ -186,6 +191,7 @@ class CorrectAmounts extends Command
|
||||
$count = $set->count();
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: All piggy bank amounts are positive.');
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var PiggyBankRepetition $item */
|
||||
@@ -207,6 +213,7 @@ class CorrectAmounts extends Command
|
||||
$count = $set->count();
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: All recurring transaction amounts are positive.');
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var PiggyBankRepetition $item */
|
||||
@@ -227,6 +234,7 @@ class CorrectAmounts extends Command
|
||||
$count = $set->count();
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: All piggy bank repetition amounts are positive.');
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var PiggyBankRepetition $item */
|
||||
@@ -255,6 +263,7 @@ class CorrectAmounts extends Command
|
||||
}
|
||||
if (0 === $fixed) {
|
||||
$this->info('Correct: All rule trigger amounts are positive.');
|
||||
|
||||
return;
|
||||
}
|
||||
$this->line(sprintf('Corrected %d rule trigger amount(s).', $fixed));
|
||||
|
@@ -56,6 +56,7 @@ class CorrectDatabase extends Command
|
||||
// if table does not exist, return false
|
||||
if (!Schema::hasTable('users')) {
|
||||
$this->error('No "users"-table, will not continue.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
$commands = [
|
||||
|
@@ -130,6 +130,7 @@ class CorrectOpeningBalanceCurrencies extends Command
|
||||
return $account;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@@ -63,6 +63,7 @@ class FixIbans extends Command
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function countAndCorrectIbans(Collection $accounts): void
|
||||
@@ -70,9 +71,9 @@ class FixIbans extends Command
|
||||
$set = [];
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$userId = (int)$account->user_id;
|
||||
$userId = (int)$account->user_id;
|
||||
$set[$userId] = $set[$userId] ?? [];
|
||||
$iban = (string)$account->iban;
|
||||
$iban = (string)$account->iban;
|
||||
if ('' === $iban) {
|
||||
continue;
|
||||
}
|
||||
@@ -83,7 +84,8 @@ class FixIbans extends Command
|
||||
if (array_key_exists($iban, $set[$userId])) {
|
||||
// iban already in use! two exceptions exist:
|
||||
if (
|
||||
!(AccountType::EXPENSE === $set[$userId][$iban] && AccountType::REVENUE === $type) && // allowed combination
|
||||
!(AccountType::EXPENSE === $set[$userId][$iban] && AccountType::REVENUE === $type)
|
||||
&& // allowed combination
|
||||
!(AccountType::REVENUE === $set[$userId][$iban] && AccountType::EXPENSE === $type) // also allowed combination.
|
||||
) {
|
||||
$this->line(
|
||||
@@ -108,6 +110,7 @@ class FixIbans extends Command
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function filterIbans(Collection $accounts): void
|
||||
|
@@ -36,11 +36,13 @@ class TriggerCreditCalculation extends Command
|
||||
public function handle(): int
|
||||
{
|
||||
$this->processAccounts();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function processAccount(Account $account): void
|
||||
|
@@ -53,6 +53,7 @@ class CreateGroupMemberships extends Command
|
||||
|
||||
/**
|
||||
* TODO move to helper.
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @throws FireflyException
|
||||
|
@@ -85,6 +85,7 @@ class UpdateGroupInformation extends Command
|
||||
$group = $user->userGroup;
|
||||
if (null === $group) {
|
||||
$this->warn(sprintf('User "%s" has no group.', $user->email));
|
||||
|
||||
return;
|
||||
}
|
||||
$set = [
|
||||
@@ -112,6 +113,7 @@ class UpdateGroupInformation extends Command
|
||||
* @param User $user
|
||||
* @param UserGroup $group
|
||||
* @param string $className
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function updateGroupInfoForObject(User $user, UserGroup $group, string $className): void
|
||||
@@ -120,6 +122,7 @@ class UpdateGroupInformation extends Command
|
||||
$result = $className::where('user_id', $user->id)->where('user_group_id', null)->update(['user_group_id' => $group->id]);
|
||||
} catch (QueryException $e) {
|
||||
$this->error(sprintf('Could not update group information for "%s" because of error "%s"', $className, $e->getMessage()));
|
||||
|
||||
return;
|
||||
}
|
||||
if (0 !== $result) {
|
||||
|
@@ -54,35 +54,37 @@ class ForceDecimalSize extends Command
|
||||
protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).';
|
||||
protected $signature = 'firefly-iii:force-decimal-size';
|
||||
private string $cast;
|
||||
private array $classes = [
|
||||
'accounts' => Account::class,
|
||||
'auto_budgets' => AutoBudget::class,
|
||||
'available_budgets' => AvailableBudget::class,
|
||||
'bills' => Bill::class,
|
||||
'budget_limits' => BudgetLimit::class,
|
||||
'piggy_bank_events' => PiggyBankEvent::class,
|
||||
'piggy_bank_repetitions' => PiggyBankRepetition::class,
|
||||
'piggy_banks' => PiggyBank::class,
|
||||
'recurrences_transactions' => RecurrenceTransaction::class,
|
||||
'transactions' => Transaction::class,
|
||||
];
|
||||
private array $classes
|
||||
= [
|
||||
'accounts' => Account::class,
|
||||
'auto_budgets' => AutoBudget::class,
|
||||
'available_budgets' => AvailableBudget::class,
|
||||
'bills' => Bill::class,
|
||||
'budget_limits' => BudgetLimit::class,
|
||||
'piggy_bank_events' => PiggyBankEvent::class,
|
||||
'piggy_bank_repetitions' => PiggyBankRepetition::class,
|
||||
'piggy_banks' => PiggyBank::class,
|
||||
'recurrences_transactions' => RecurrenceTransaction::class,
|
||||
'transactions' => Transaction::class,
|
||||
];
|
||||
|
||||
private string $operator;
|
||||
private string $regularExpression;
|
||||
private array $tables = [
|
||||
'accounts' => ['virtual_balance'],
|
||||
'auto_budgets' => ['amount'],
|
||||
'available_budgets' => ['amount'],
|
||||
'bills' => ['amount_min', 'amount_max'],
|
||||
'budget_limits' => ['amount'],
|
||||
'currency_exchange_rates' => ['rate', 'user_rate'],
|
||||
'limit_repetitions' => ['amount'],
|
||||
'piggy_bank_events' => ['amount'],
|
||||
'piggy_bank_repetitions' => ['currentamount'],
|
||||
'piggy_banks' => ['targetamount'],
|
||||
'recurrences_transactions' => ['amount', 'foreign_amount'],
|
||||
'transactions' => ['amount', 'foreign_amount'],
|
||||
];
|
||||
private array $tables
|
||||
= [
|
||||
'accounts' => ['virtual_balance'],
|
||||
'auto_budgets' => ['amount'],
|
||||
'available_budgets' => ['amount'],
|
||||
'bills' => ['amount_min', 'amount_max'],
|
||||
'budget_limits' => ['amount'],
|
||||
'currency_exchange_rates' => ['rate', 'user_rate'],
|
||||
'limit_repetitions' => ['amount'],
|
||||
'piggy_bank_events' => ['amount'],
|
||||
'piggy_bank_repetitions' => ['currentamount'],
|
||||
'piggy_banks' => ['targetamount'],
|
||||
'recurrences_transactions' => ['amount', 'foreign_amount'],
|
||||
'transactions' => ['amount', 'foreign_amount'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
@@ -102,6 +104,7 @@ class ForceDecimalSize extends Command
|
||||
$this->updateDecimals();
|
||||
}
|
||||
$this->line('Done!');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -110,6 +113,7 @@ class ForceDecimalSize extends Command
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $fields
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function correctAccountAmounts(TransactionCurrency $currency, array $fields): void
|
||||
@@ -134,6 +138,7 @@ class ForceDecimalSize extends Command
|
||||
$result = $query->get(['accounts.*']);
|
||||
if (0 === $result->count()) {
|
||||
$this->line(sprintf('Correct: All accounts in %s', $currency->code));
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var Account $account */
|
||||
@@ -164,12 +169,14 @@ class ForceDecimalSize extends Command
|
||||
DB::connection()->getPdo()->sqliteCreateFunction('REGEXP', function ($pattern, $value) {
|
||||
mb_regex_encoding('UTF-8');
|
||||
$pattern = trim($pattern, '"');
|
||||
return (false !== mb_ereg($pattern, (string) $value)) ? 1 : 0;
|
||||
|
||||
return (false !== mb_ereg($pattern, (string)$value)) ? 1 : 0;
|
||||
});
|
||||
}
|
||||
|
||||
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')));
|
||||
|
||||
return;
|
||||
}
|
||||
$this->correctAmountsByCurrency();
|
||||
@@ -195,6 +202,7 @@ class ForceDecimalSize extends Command
|
||||
* This method loops the available tables that may need fixing, and calls for the right method that can fix them.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return void
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -243,8 +251,10 @@ class ForceDecimalSize extends Command
|
||||
|
||||
/**
|
||||
* This method fixes all auto budgets in currency $currency.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param string $table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function correctGeneric(TransactionCurrency $currency, string $table): void
|
||||
@@ -271,6 +281,7 @@ class ForceDecimalSize extends Command
|
||||
$result = $query->get(['*']);
|
||||
if (0 === $result->count()) {
|
||||
$this->line(sprintf('Correct: All %s in %s', $table, $currency->code));
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var Model $item */
|
||||
@@ -294,6 +305,7 @@ class ForceDecimalSize extends Command
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $fields
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function correctPiggyAmounts(TransactionCurrency $currency, array $fields): void
|
||||
@@ -320,6 +332,7 @@ class ForceDecimalSize extends Command
|
||||
$result = $query->get(['piggy_banks.*']);
|
||||
if (0 === $result->count()) {
|
||||
$this->line(sprintf('Correct: All piggy banks in %s', $currency->code));
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var PiggyBank $item */
|
||||
@@ -340,8 +353,10 @@ class ForceDecimalSize extends Command
|
||||
|
||||
/**
|
||||
* This method fixes all piggy bank events in currency $currency.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $fields
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function correctPiggyEventAmounts(TransactionCurrency $currency, array $fields): void
|
||||
@@ -369,6 +384,7 @@ class ForceDecimalSize extends Command
|
||||
$result = $query->get(['piggy_bank_events.*']);
|
||||
if (0 === $result->count()) {
|
||||
$this->line(sprintf('Correct: All piggy bank events in %s', $currency->code));
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var PiggyBankEvent $item */
|
||||
@@ -392,6 +408,7 @@ class ForceDecimalSize extends Command
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $fields
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function correctPiggyRepetitionAmounts(TransactionCurrency $currency, array $fields)
|
||||
@@ -419,6 +436,7 @@ class ForceDecimalSize extends Command
|
||||
$result = $query->get(['piggy_bank_repetitions.*']);
|
||||
if (0 === $result->count()) {
|
||||
$this->line(sprintf('Correct: All piggy bank repetitions in %s', $currency->code));
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var PiggyBankRepetition $item */
|
||||
@@ -441,6 +459,7 @@ class ForceDecimalSize extends Command
|
||||
* This method fixes all transactions in currency $currency.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function correctTransactionAmounts(TransactionCurrency $currency): void
|
||||
@@ -482,6 +501,7 @@ class ForceDecimalSize extends Command
|
||||
$result = $query->get(['*']);
|
||||
if (0 === $result->count()) {
|
||||
$this->line(sprintf('Correct: All transactions in foreign currency %s', $currency->code));
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var Transaction $item */
|
||||
@@ -534,6 +554,7 @@ class ForceDecimalSize extends Command
|
||||
switch ($type) {
|
||||
default:
|
||||
$this->error(sprintf('Cannot handle database type "%s".', $type));
|
||||
|
||||
return;
|
||||
case 'pgsql':
|
||||
$query = sprintf('ALTER TABLE %s ALTER COLUMN %s TYPE DECIMAL(32,12);', $name, $field);
|
||||
|
@@ -52,6 +52,7 @@ class ForceMigration extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function handle(): int
|
||||
@@ -69,8 +70,10 @@ class ForceMigration extends Command
|
||||
$user = $this->getUser();
|
||||
Log::channel('audit')->info(sprintf('User #%d ("%s") forced migrations.', $user->id, $user->email));
|
||||
$this->forceMigration();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -124,6 +124,7 @@ class VerifySecurityAlerts extends Command
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function saveSecurityAdvisory(array $array): void
|
||||
|
@@ -153,6 +153,7 @@ class Cron extends Command
|
||||
/**
|
||||
* @param bool $force
|
||||
* @param Carbon|null $date
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
|
@@ -165,6 +165,7 @@ class DecryptDatabase extends Command
|
||||
/**
|
||||
* @param string $table
|
||||
* @param array $fields
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
|
@@ -85,6 +85,7 @@ class UpgradeLiabilitiesEight extends Command
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function deleteCreditTransaction(Account $account): void
|
||||
@@ -100,6 +101,7 @@ class UpgradeLiabilitiesEight extends Command
|
||||
$service = new TransactionGroupDestroyService();
|
||||
$service->destroy($group);
|
||||
Log::debug(sprintf('Deleted liability credit group #%d', $group->id));
|
||||
|
||||
return;
|
||||
}
|
||||
Log::debug('No liability credit journal found.');
|
||||
@@ -107,6 +109,7 @@ class UpgradeLiabilitiesEight extends Command
|
||||
|
||||
/**
|
||||
* @param $account
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function deleteTransactions($account): int
|
||||
@@ -152,11 +155,13 @@ class UpgradeLiabilitiesEight extends Command
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasBadOpening(Account $account): bool
|
||||
@@ -169,6 +174,7 @@ class UpgradeLiabilitiesEight extends Command
|
||||
->first(['transaction_journals.*']);
|
||||
if (null === $openingJournal) {
|
||||
Log::debug('Account has no opening balance and can be skipped.');
|
||||
|
||||
return false;
|
||||
}
|
||||
$liabilityJournal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
@@ -177,10 +183,12 @@ class UpgradeLiabilitiesEight extends Command
|
||||
->first(['transaction_journals.*']);
|
||||
if (null === $liabilityJournal) {
|
||||
Log::debug('Account has no liability credit and can be skipped.');
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!$openingJournal->date->isSameDay($liabilityJournal->date)) {
|
||||
Log::debug('Account has opening/credit not on the same day.');
|
||||
|
||||
return false;
|
||||
}
|
||||
Log::debug('Account has bad opening balance data.');
|
||||
@@ -213,6 +221,7 @@ class UpgradeLiabilitiesEight extends Command
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function reverseOpeningBalance(Account $account): void
|
||||
@@ -235,6 +244,7 @@ class UpgradeLiabilitiesEight extends Command
|
||||
$source->save();
|
||||
$dest->save();
|
||||
Log::debug(sprintf('Opening balance transaction journal #%d reversed.', $openingJournal->id));
|
||||
|
||||
return;
|
||||
}
|
||||
Log::warning('Did not find opening balance.');
|
||||
|
Reference in New Issue
Block a user