mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add administration specific thing to preferences.
This commit is contained in:
parent
9f95221ba3
commit
4cdb14301d
@ -73,6 +73,7 @@ class CorrectDatabase extends Command
|
||||
// new!
|
||||
'firefly-iii:unify-group-accounts',
|
||||
'firefly-iii:trigger-credit-recalculation',
|
||||
'firefly-iii:migrate-preferences'
|
||||
];
|
||||
foreach ($commands as $command) {
|
||||
$this->friendlyLine(sprintf('Now executing command "%s"', $command));
|
||||
|
74
app/Console/Commands/Correction/MigratePreferences.php
Normal file
74
app/Console/Commands/Correction/MigratePreferences.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/*
|
||||
* MigratePreferences.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\Correction;
|
||||
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||
|
||||
class MigratePreferences extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:migrate-preferences';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Give Firefly III preferences a user group ID so they can be made administration specific.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$items = ['frontpageAccounts'];
|
||||
$users = User::get();
|
||||
/** @var User $user */
|
||||
foreach($users as $user) {
|
||||
$count = 0;
|
||||
foreach($items as $item) {
|
||||
$preference = Preference::where('name', $item)->where('user_id', $user->id)->first();
|
||||
if(null === $preference) {
|
||||
continue;
|
||||
}
|
||||
if(null !== $preference->user_group_id) {
|
||||
$preference->user_group_id = $user->user_group_id;
|
||||
$preference->save();
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if($count > 0) {
|
||||
$this->info(sprintf('Migrated %d preference(s) for user #%d ("%s").', $count, $user->id, $user->email));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CommandAlias::SUCCESS;
|
||||
}
|
||||
}
|
@ -69,6 +69,7 @@ class UpgradeDatabase extends Command
|
||||
'firefly-iii:create-group-memberships',
|
||||
'firefly-iii:upgrade-group-information',
|
||||
'firefly-iii:upgrade-currency-preferences',
|
||||
'firefly-iii:correct-database',
|
||||
];
|
||||
$args = [];
|
||||
if ($this->option('force')) {
|
||||
|
@ -119,7 +119,7 @@ return [
|
||||
],
|
||||
'version' => '6.1.13',
|
||||
'api_version' => '2.0.13',
|
||||
'db_version' => 23,
|
||||
'db_version' => 24,
|
||||
|
||||
// generic settings
|
||||
'maxUploadSize' => 1073741824, // 1 GB
|
||||
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
try {
|
||||
Schema::table(
|
||||
'preferences',
|
||||
static function (Blueprint $table): void {
|
||||
if (!Schema::hasColumn('preferences', 'user_group_id')) {
|
||||
$table->bigInteger('user_group_id', false, true)->nullable()->after('user_id');
|
||||
$table->foreign('user_group_id', 'preferences_to_ugi')->references('id')->on('user_groups')->onDelete('set null')->onUpdate('cascade');
|
||||
}
|
||||
}
|
||||
);
|
||||
} catch (QueryException $e) {
|
||||
app('log')->error(sprintf('Could not execute query: %s', $e->getMessage()));
|
||||
app('log')->error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user