mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-11 09:29:34 +00:00
Auto commit for release 'develop' on 2024-04-02
This commit is contained in:
@@ -73,7 +73,7 @@ class CorrectDatabase extends Command
|
||||
// new!
|
||||
'firefly-iii:unify-group-accounts',
|
||||
'firefly-iii:trigger-credit-recalculation',
|
||||
'firefly-iii:migrate-preferences'
|
||||
'firefly-iii:migrate-preferences',
|
||||
];
|
||||
foreach ($commands as $command) {
|
||||
$this->friendlyLine(sprintf('Now executing command "%s"', $command));
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* MigratePreferences.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -33,7 +35,7 @@ class MigratePreferences extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:migrate-preferences';
|
||||
protected $signature = 'firefly-iii:migrate-preferences';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -49,26 +51,26 @@ class MigratePreferences extends Command
|
||||
{
|
||||
$items = config('firefly.admin_specific_prefs');
|
||||
$users = User::get();
|
||||
|
||||
/** @var User $user */
|
||||
foreach($users as $user) {
|
||||
foreach ($users as $user) {
|
||||
$count = 0;
|
||||
foreach($items as $item) {
|
||||
foreach ($items as $item) {
|
||||
$preference = Preference::where('name', $item)->where('user_id', $user->id)->first();
|
||||
if(null === $preference) {
|
||||
if (null === $preference) {
|
||||
continue;
|
||||
}
|
||||
if(null !== $preference->user_group_id) {
|
||||
if (null !== $preference->user_group_id) {
|
||||
$preference->user_group_id = $user->user_group_id;
|
||||
$preference->save();
|
||||
$count++;
|
||||
++$count;
|
||||
}
|
||||
}
|
||||
if($count > 0) {
|
||||
if ($count > 0) {
|
||||
$this->info(sprintf('Migrated %d preference(s) for user #%d ("%s").', $count, $user->id, $user->email));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CommandAlias::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ class CreateGroupMemberships extends Command
|
||||
use ShowsFriendlyMessages;
|
||||
|
||||
public const string CONFIG_NAME = '560_create_group_memberships';
|
||||
protected $description = 'Update group memberships';
|
||||
protected $signature = 'firefly-iii:create-group-memberships';
|
||||
protected $description = 'Update group memberships';
|
||||
protected $signature = 'firefly-iii:create-group-memberships';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
@@ -78,19 +78,20 @@ class CreateGroupMemberships extends Command
|
||||
public static function createGroupMembership(User $user): void
|
||||
{
|
||||
// check if membership exists
|
||||
$userGroup = UserGroup::where('title', $user->email)->first();
|
||||
$userGroup = UserGroup::where('title', $user->email)->first();
|
||||
if (null === $userGroup) {
|
||||
$userGroup = UserGroup::create(['title' => $user->email, 'default_administration' => true]);
|
||||
}
|
||||
|
||||
$userRole = UserRole::where('title', UserRoleEnum::OWNER->value)->first();
|
||||
$userRole = UserRole::where('title', UserRoleEnum::OWNER->value)->first();
|
||||
|
||||
if (null === $userRole) {
|
||||
throw new FireflyException('Firefly III could not find a user role. Please make sure all migrations have run.');
|
||||
}
|
||||
$membership = GroupMembership::where('user_id', $user->id)
|
||||
->where('user_group_id', $userGroup->id)
|
||||
->where('user_role_id', $userRole->id)->first();
|
||||
->where('user_group_id', $userGroup->id)
|
||||
->where('user_role_id', $userRole->id)->first()
|
||||
;
|
||||
if (null === $membership) {
|
||||
GroupMembership::create(
|
||||
[
|
||||
@@ -105,5 +106,4 @@ class CreateGroupMemberships extends Command
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user