Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix https://github.com/firefly-iii/firefly-iii/issues/8911
James Colea20622ac0c94
diff --git a/app/Console/Commands/Correction/CorrectAccountBalance.php b/app/Console/Commands/Correction/CorrectAccountBalance.phpdeleted file mode 100644index d6c35929de..0000000000--- a/app/Console/Commands/Correction/CorrectAccountBalance.php+++ /dev/null@@ -1,32 +0,0 @@-<?php--declare(strict_types=1);--namespace FireflyIII\Console\Commands\Correction;--use FireflyIII\Console\Commands\ShowsFriendlyMessages;-use FireflyIII\Support\Models\AccountBalanceCalculator;-use Illuminate\Console\Command;--/**- * Class CorrectionSkeleton- */-class CorrectAccountBalance extends Command-{- use ShowsFriendlyMessages;- protected $description = 'Recalculate all account balance amounts';-- protected $signature = 'firefly-iii:correct-account-balance';-- public function handle(): int- {- $this->correctBalanceAmounts();-- return 0;- }-- private function correctBalanceAmounts(): void- {- AccountBalanceCalculator::recalculateAll();- }-}diff --git a/app/Console/Commands/Correction/CorrectDatabase.php b/app/Console/Commands/Correction/CorrectDatabase.phpindex d5d127b3f2..82750c1a9d 100644--- a/app/Console/Commands/Correction/CorrectDatabase.php+++ b/app/Console/Commands/Correction/CorrectDatabase.php@@ -74,7 +74,6 @@ class CorrectDatabase extends Command'firefly-iii:unify-group-accounts','firefly-iii:trigger-credit-recalculation','firefly-iii:migrate-preferences',- 'firefly-iii:correct-account-balance',];foreach ($commands as $command) {$this->friendlyLine(sprintf('Now executing command "%s"', $command));diff --git a/app/Console/Commands/Upgrade/CorrectAccountBalance.php b/app/Console/Commands/Upgrade/CorrectAccountBalance.phpnew file mode 100644index 0000000000..2fc946fa49--- /dev/null+++ b/app/Console/Commands/Upgrade/CorrectAccountBalance.php@@ -0,0 +1,69 @@+<?php+/*+ * CorrectAccountBalance.php+ * Copyright (c) 2024 [email protected].+ *+ * 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/.+ */++declare(strict_types=1);++namespace FireflyIII\Console\Commands\Upgrade;++use FireflyIII\Console\Commands\ShowsFriendlyMessages;+use FireflyIII\Support\Models\AccountBalanceCalculator;+use Illuminate\Console\Command;++/**+ * Class CorrectionSkeleton+ */+class CorrectAccountBalance extends Command+{+ use ShowsFriendlyMessages;+ public const string CONFIG_NAME = '620_correct_balances';+ protected $description = 'Recalculate all account balance amounts';++ protected $signature = 'firefly-iii:correct-account-balance {--F|force : Force the execution of this command.}';++ public function handle(): int+ {+ if ($this->isExecuted() && true !== $this->option('force')) {+ $this->friendlyInfo('This command has already been executed.');++ return 0;+ }+ $this->correctBalanceAmounts();+ $this->markAsExecuted();++ return 0;+ }++ private function correctBalanceAmounts(): void+ {+ AccountBalanceCalculator::recalculateAll();+ }+ private function isExecuted(): bool+ {+ $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);++ return (bool)$configVar?->data;+ }++ private function markAsExecuted(): void+ {+ app('fireflyconfig')->set(self::CONFIG_NAME, true);+ }+}diff --git a/app/Console/Commands/Upgrade/UpgradeDatabase.php b/app/Console/Commands/Upgrade/UpgradeDatabase.phpindex 1614dc5c3c..a761b3da33 100644--- a/app/Console/Commands/Upgrade/UpgradeDatabase.php+++ b/app/Console/Commands/Upgrade/UpgradeDatabase.php@@ -65,6 +65,7 @@ class UpgradeDatabase extends Command'firefly-iii:budget-limit-periods','firefly-iii:migrate-rule-actions','firefly-iii:restore-oauth-keys',+ 'firefly-iii:correct-account-balance',// also just in case, some integrity commands:'firefly-iii:create-group-memberships','firefly-iii:upgrade-group-information',diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.phpindex 2440e93777..0e7111094d 100644--- a/app/Http/Controllers/DebugController.php+++ b/app/Http/Controllers/DebugController.php@@ -93,7 +93,6 @@ class DebugController extends ControllerArtisan::call('view:clear');// also do some recalculations.- Artisan::call('firefly-iii:correct-account-balance');Artisan::call('firefly-iii:trigger-credit-recalculation');try {