mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Add another command.
This commit is contained in:
@@ -76,6 +76,7 @@ class CorrectDatabase extends Command
|
|||||||
'firefly-iii:fix-recurring-transactions',
|
'firefly-iii:fix-recurring-transactions',
|
||||||
'firefly-iii:restore-oauth-keys',
|
'firefly-iii:restore-oauth-keys',
|
||||||
'firefly-iii:fix-transaction-types',
|
'firefly-iii:fix-transaction-types',
|
||||||
|
'firefly-iii:fix-frontpage-accounts'
|
||||||
];
|
];
|
||||||
foreach ($commands as $command) {
|
foreach ($commands as $command) {
|
||||||
$this->line(sprintf('Now executing %s', $command));
|
$this->line(sprintf('Now executing %s', $command));
|
||||||
|
77
app/Console/Commands/Correction/FixFrontpageAccounts.php
Normal file
77
app/Console/Commands/Correction/FixFrontpageAccounts.php
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Console\Commands\Correction;
|
||||||
|
|
||||||
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Models\Preference;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Facades\Preferences;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FixFrontpageAccounts
|
||||||
|
*/
|
||||||
|
class FixFrontpageAccounts extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Fixes a preference that may include deleted accounts or accounts of another type.';
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'firefly-iii:fix-frontpage-accounts';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle(): int
|
||||||
|
{
|
||||||
|
$users = User::get();
|
||||||
|
/** @var User $user */
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$preference = Preferences::getForUser($user, 'frontPageAccounts', null);
|
||||||
|
if (null !== $preference) {
|
||||||
|
$this->fixPreference($preference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Preference $preference
|
||||||
|
*/
|
||||||
|
private function fixPreference(Preference $preference): void
|
||||||
|
{
|
||||||
|
$fixed = [];
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
if (null === $preference->user) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$repository->setUser($preference->user);
|
||||||
|
$data = $preference->data;
|
||||||
|
if (is_array($data)) {
|
||||||
|
/** @var string $accountId */
|
||||||
|
foreach ($data as $accountId) {
|
||||||
|
$accountId = (int)$accountId;
|
||||||
|
$account = $repository->findNull($accountId);
|
||||||
|
if (null !== $account) {
|
||||||
|
if (in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true)) {
|
||||||
|
$fixed[] = $account->id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Preferences::setForUser($preference->user, 'frontPageAccounts', $fixed);
|
||||||
|
}
|
||||||
|
}
|
@@ -95,6 +95,7 @@ class UpgradeDatabase extends Command
|
|||||||
'firefly-iii:fix-recurring-transactions',
|
'firefly-iii:fix-recurring-transactions',
|
||||||
'firefly-iii:unify-group-accounts',
|
'firefly-iii:unify-group-accounts',
|
||||||
'firefly-iii:fix-transaction-types',
|
'firefly-iii:fix-transaction-types',
|
||||||
|
'firefly-iii:fix-frontpage-accounts',
|
||||||
|
|
||||||
// two report commands
|
// two report commands
|
||||||
'firefly-iii:report-empty-objects',
|
'firefly-iii:report-empty-objects',
|
||||||
|
@@ -105,6 +105,7 @@ class InstallController extends Controller
|
|||||||
'firefly-iii:fix-recurring-transactions' => [],
|
'firefly-iii:fix-recurring-transactions' => [],
|
||||||
'firefly-iii:unify-group-accounts' => [],
|
'firefly-iii:unify-group-accounts' => [],
|
||||||
'firefly-iii:fix-transaction-types' => [],
|
'firefly-iii:fix-transaction-types' => [],
|
||||||
|
'firefly-iii:fix-frontpage-accounts' => [],
|
||||||
|
|
||||||
// final command to set latest version in DB
|
// final command to set latest version in DB
|
||||||
'firefly-iii:set-latest-version' => ['--james-is-cool' => true],
|
'firefly-iii:set-latest-version' => ['--james-is-cool' => true],
|
||||||
|
@@ -192,6 +192,7 @@
|
|||||||
"@php artisan firefly-iii:fix-recurring-transactions",
|
"@php artisan firefly-iii:fix-recurring-transactions",
|
||||||
"@php artisan firefly-iii:unify-group-accounts",
|
"@php artisan firefly-iii:unify-group-accounts",
|
||||||
"@php artisan firefly-iii:fix-transaction-types",
|
"@php artisan firefly-iii:fix-transaction-types",
|
||||||
|
"@php artisan firefly-iii:fix-frontpage-accounts",
|
||||||
|
|
||||||
"@php artisan firefly-iii:report-empty-objects",
|
"@php artisan firefly-iii:report-empty-objects",
|
||||||
"@php artisan firefly-iii:report-sum",
|
"@php artisan firefly-iii:report-sum",
|
||||||
|
Reference in New Issue
Block a user