mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
commit
b98050e238
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
* CreateGroupMemberships.php
|
||||
* Copyright (c) 2021 james@firefly-iii.org
|
||||
* Copyright (c) 2023 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Upgrade;
|
||||
namespace FireflyIII\Console\Commands\Integrity;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\GroupMembership;
|
||||
@ -31,8 +31,6 @@ use FireflyIII\Models\UserRole;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Log;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* Class CreateGroupMemberships
|
||||
@ -51,7 +49,7 @@ class CreateGroupMemberships extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:create-group-memberships {--F|force : Force the execution of this command.}';
|
||||
protected $signature = 'firefly-iii:create-group-memberships';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
@ -62,36 +60,15 @@ class CreateGroupMemberships extends Command
|
||||
public function handle(): int
|
||||
{
|
||||
$start = microtime(true);
|
||||
if ($this->isExecuted() && true !== $this->option('force')) {
|
||||
$this->warn('This command has already been executed.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
$this->createGroupMemberships();
|
||||
$this->markAsExecuted();
|
||||
|
||||
$end = round(microtime(true) - $start, 2);
|
||||
$this->info(sprintf('in %s seconds.', $end));
|
||||
$this->info(sprintf('Validated group memberships in %s seconds.', $end));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||
if (null !== $configVar) {
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws FireflyException
|
||||
@ -127,35 +104,37 @@ class CreateGroupMemberships extends Command
|
||||
*/
|
||||
private function createGroupMembership(User $user): void
|
||||
{
|
||||
$userGroup = UserGroup::create(['title' => $user->email]);
|
||||
$userRole = UserRole::where('title', UserRole::OWNER)->first();
|
||||
// check if membership exists
|
||||
$userGroup = UserGroup::where('title', $user->email)->first();
|
||||
if (null === $userGroup) {
|
||||
$userGroup = UserGroup::create(['title' => $user->email]);
|
||||
Log::debug(sprintf('Created new user group #%d ("%s")', $userGroup->id, $userGroup->title));
|
||||
}
|
||||
|
||||
$userRole = UserRole::where('title', UserRole::OWNER)->first();
|
||||
|
||||
if (null === $userRole) {
|
||||
throw new FireflyException('Firefly III could not find a user role. Please make sure all validations have run.');
|
||||
throw new FireflyException('Firefly III could not find a user role. Please make sure all migrations have run.');
|
||||
}
|
||||
|
||||
/** @var GroupMembership|null $membership */
|
||||
$membership = GroupMembership::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'user_role_id' => $userRole->id,
|
||||
'user_group_id' => $userGroup->id,
|
||||
]
|
||||
);
|
||||
$membership = GroupMembership::where('user_id', $user->id)
|
||||
->where('user_group_id', $userGroup->id)
|
||||
->where('user_role_id', $userRole->id)->first();
|
||||
if (null === $membership) {
|
||||
throw new FireflyException('Firefly III could not create user group management object. Please make sure all validations have run.');
|
||||
GroupMembership::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'user_role_id' => $userRole->id,
|
||||
'user_group_id' => $userGroup->id,
|
||||
]
|
||||
);
|
||||
Log::debug('Created new membership.');
|
||||
}
|
||||
if (null === $user->user_group_id) {
|
||||
$user->user_group_id = $userGroup->id;
|
||||
$user->save();
|
||||
Log::debug('Put user in default group.');
|
||||
}
|
||||
$user->user_group_id = $userGroup->id;
|
||||
$user->save();
|
||||
|
||||
Log::debug(sprintf('User #%d now has main group.', $user->id));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
}
|
||||
}
|
@ -74,7 +74,6 @@ class UpgradeDatabase extends Command
|
||||
'firefly-iii:migrate-tag-locations',
|
||||
'firefly-iii:migrate-recurrence-type',
|
||||
'firefly-iii:upgrade-liabilities',
|
||||
'firefly-iii:create-group-memberships',
|
||||
'firefly-iii:liabilities-600',
|
||||
|
||||
// there are 16 verify commands.
|
||||
@ -100,6 +99,7 @@ class UpgradeDatabase extends Command
|
||||
'firefly-iii:fix-transaction-types',
|
||||
'firefly-iii:fix-frontpage-accounts',
|
||||
'firefly-iii:fix-ibans',
|
||||
'firefly-iii:create-group-memberships',
|
||||
'firefly-iii:upgrade-group-information',
|
||||
|
||||
// two report commands
|
||||
|
@ -85,7 +85,6 @@ class InstallController extends Controller
|
||||
'firefly-iii:migrate-tag-locations' => [],
|
||||
'firefly-iii:migrate-recurrence-type' => [],
|
||||
'firefly-iii:upgrade-liabilities' => [],
|
||||
'firefly-iii:create-group-memberships' => [],
|
||||
'firefly-iii:liabilities-600' => [],
|
||||
|
||||
// verify commands
|
||||
@ -111,9 +110,10 @@ class InstallController extends Controller
|
||||
'firefly-iii:fix-transaction-types' => [],
|
||||
'firefly-iii:fix-frontpage-accounts' => [],
|
||||
'firefly-iii:fix-ibans' => [],
|
||||
'firefly-iii:create-group-memberships' => [],
|
||||
'firefly-iii:upgrade-group-information' => [],
|
||||
|
||||
// final command to set latest version in DB
|
||||
// final command to set the latest version in DB
|
||||
'firefly-iii:set-latest-version' => ['--james-is-cool' => true],
|
||||
'firefly-iii:verify-security-alerts' => [],
|
||||
];
|
||||
|
@ -174,7 +174,6 @@
|
||||
"@php artisan firefly-iii:migrate-tag-locations",
|
||||
"@php artisan firefly-iii:migrate-recurrence-type",
|
||||
"@php artisan firefly-iii:upgrade-liabilities",
|
||||
"@php artisan firefly-iii:create-group-memberships",
|
||||
"@php artisan firefly-iii:liabilities-600",
|
||||
"@php artisan firefly-iii:fix-piggies",
|
||||
"@php artisan firefly-iii:create-link-types",
|
||||
@ -198,6 +197,7 @@
|
||||
"@php artisan firefly-iii:fix-transaction-types",
|
||||
"@php artisan firefly-iii:fix-frontpage-accounts",
|
||||
"@php artisan firefly-iii:fix-ibans",
|
||||
"@php artisan firefly-iii:create-group-memberships",
|
||||
"@php artisan firefly-iii:report-empty-objects",
|
||||
"@php artisan firefly-iii:report-sum",
|
||||
"@php artisan firefly-iii:restore-oauth-keys",
|
||||
|
45
composer.lock
generated
45
composer.lock
generated
@ -1855,21 +1855,21 @@
|
||||
},
|
||||
{
|
||||
"name": "laravel/framework",
|
||||
"version": "v9.48.0",
|
||||
"version": "v9.49.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/framework.git",
|
||||
"reference": "c78ae7aeb0cbcb1a205050d3592247ba07f5b711"
|
||||
"reference": "e02d9453442ad0a6a2f5dc9df96ea0319d218026"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/c78ae7aeb0cbcb1a205050d3592247ba07f5b711",
|
||||
"reference": "c78ae7aeb0cbcb1a205050d3592247ba07f5b711",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/e02d9453442ad0a6a2f5dc9df96ea0319d218026",
|
||||
"reference": "e02d9453442ad0a6a2f5dc9df96ea0319d218026",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"brick/math": "^0.10.2",
|
||||
"doctrine/inflector": "^2.0",
|
||||
"brick/math": "^0.9.3|^0.10.2|^0.11",
|
||||
"doctrine/inflector": "^2.0.5",
|
||||
"dragonmantank/cron-expression": "^3.3.2",
|
||||
"egulias/email-validator": "^3.2.1|^4.0",
|
||||
"ext-mbstring": "*",
|
||||
@ -1968,7 +1968,6 @@
|
||||
"aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage, and SES mail driver (^3.235.5).",
|
||||
"brianium/paratest": "Required to run tests in parallel (^6.0).",
|
||||
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.13.3|^3.1.4).",
|
||||
"ext-bcmath": "Required to use the multiple_of validation rule.",
|
||||
"ext-ftp": "Required to use the Flysystem FTP driver.",
|
||||
"ext-gd": "Required to use Illuminate\\Http\\Testing\\FileFactory::image().",
|
||||
"ext-memcached": "Required to use the memcache cache driver.",
|
||||
@ -2040,20 +2039,20 @@
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"time": "2023-01-17T15:06:19+00:00"
|
||||
"time": "2023-01-31T14:36:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/passport",
|
||||
"version": "v11.5.1",
|
||||
"version": "v11.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/passport.git",
|
||||
"reference": "b20282266211a0a19b0294d3459b5fd268807a6c"
|
||||
"reference": "1d8204e40c63bb6cbb981907fdbeb5c69a4fbae9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/passport/zipball/b20282266211a0a19b0294d3459b5fd268807a6c",
|
||||
"reference": "b20282266211a0a19b0294d3459b5fd268807a6c",
|
||||
"url": "https://api.github.com/repos/laravel/passport/zipball/1d8204e40c63bb6cbb981907fdbeb5c69a4fbae9",
|
||||
"reference": "1d8204e40c63bb6cbb981907fdbeb5c69a4fbae9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2117,7 +2116,7 @@
|
||||
"issues": "https://github.com/laravel/passport/issues",
|
||||
"source": "https://github.com/laravel/passport"
|
||||
},
|
||||
"time": "2023-01-16T14:52:08+00:00"
|
||||
"time": "2023-01-31T13:41:55+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/sanctum",
|
||||
@ -2186,16 +2185,16 @@
|
||||
},
|
||||
{
|
||||
"name": "laravel/serializable-closure",
|
||||
"version": "v1.2.2",
|
||||
"version": "v1.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/serializable-closure.git",
|
||||
"reference": "47afb7fae28ed29057fdca37e16a84f90cc62fae"
|
||||
"reference": "f23fe9d4e95255dacee1bf3525e0810d1a1b0f37"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/47afb7fae28ed29057fdca37e16a84f90cc62fae",
|
||||
"reference": "47afb7fae28ed29057fdca37e16a84f90cc62fae",
|
||||
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/f23fe9d4e95255dacee1bf3525e0810d1a1b0f37",
|
||||
"reference": "f23fe9d4e95255dacee1bf3525e0810d1a1b0f37",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2242,7 +2241,7 @@
|
||||
"issues": "https://github.com/laravel/serializable-closure/issues",
|
||||
"source": "https://github.com/laravel/serializable-closure"
|
||||
},
|
||||
"time": "2022-09-08T13:45:54+00:00"
|
||||
"time": "2023-01-30T18:31:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/slack-notification-channel",
|
||||
@ -3482,16 +3481,16 @@
|
||||
},
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
"version": "2.65.0",
|
||||
"version": "2.66.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/briannesbitt/Carbon.git",
|
||||
"reference": "09acf64155c16dc6f580f36569ae89344e9734a3"
|
||||
"reference": "496712849902241f04902033b0441b269effe001"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/09acf64155c16dc6f580f36569ae89344e9734a3",
|
||||
"reference": "09acf64155c16dc6f580f36569ae89344e9734a3",
|
||||
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/496712849902241f04902033b0441b269effe001",
|
||||
"reference": "496712849902241f04902033b0441b269effe001",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -3580,7 +3579,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2023-01-06T15:55:01+00:00"
|
||||
"time": "2023-01-29T18:53:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nette/schema",
|
||||
|
Loading…
Reference in New Issue
Block a user