diff --git a/app/Console/Commands/Correction/CorrectAccountBalance.php b/app/Console/Commands/Correction/CorrectAccountBalance.php deleted file mode 100644 index d6c35929de..0000000000 --- a/app/Console/Commands/Correction/CorrectAccountBalance.php +++ /dev/null @@ -1,32 +0,0 @@ -correctBalanceAmounts(); - - return 0; - } - - private function correctBalanceAmounts(): void - { - AccountBalanceCalculator::recalculateAll(); - } -} diff --git a/app/Console/Commands/Correction/CorrectDatabase.php b/app/Console/Commands/Correction/CorrectDatabase.php index 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.php new file mode 100644 index 0000000000..2fc946fa49 --- /dev/null +++ b/app/Console/Commands/Upgrade/CorrectAccountBalance.php @@ -0,0 +1,69 @@ +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.php index 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.php index 2440e93777..0e7111094d 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -93,7 +93,6 @@ class DebugController extends Controller Artisan::call('view:clear'); // also do some recalculations. - Artisan::call('firefly-iii:correct-account-balance'); Artisan::call('firefly-iii:trigger-credit-recalculation'); try {