Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -47,7 +47,6 @@ class CreateGroupMemberships extends Command
/**
* Execute the console command.
*
* @return int
* @throws FireflyException
*/
public function handle(): int
@@ -58,24 +57,9 @@ class CreateGroupMemberships extends Command
return 0;
}
/**
*
* @throws FireflyException
*/
private function createGroupMemberships(): void
{
$users = User::get();
/** @var User $user */
foreach ($users as $user) {
self::createGroupMembership($user);
}
}
/**
* TODO move to helper.
*
* @param User $user
*
* @throws FireflyException
*/
public static function createGroupMembership(User $user): void
@@ -92,8 +76,9 @@ class CreateGroupMemberships extends Command
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(
[
@@ -108,4 +93,17 @@ class CreateGroupMemberships extends Command
$user->save();
}
}
/**
* @throws FireflyException
*/
private function createGroupMemberships(): void
{
$users = User::get();
/** @var User $user */
foreach ($users as $user) {
self::createGroupMembership($user);
}
}
}

View File

@@ -29,7 +29,6 @@ use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use Illuminate\Console\Command;
use stdClass;
/**
* Class ReportEmptyObjects
@@ -38,15 +37,12 @@ class ReportEmptyObjects extends Command
{
use ShowsFriendlyMessages;
protected $description = 'Reports on empty database objects.';
protected $signature = 'firefly-iii:report-empty-objects';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
@@ -65,13 +61,14 @@ class ReportEmptyObjects extends Command
private function reportEmptyBudgets(): void
{
$set = Budget::leftJoin('budget_transaction_journal', 'budgets.id', '=', 'budget_transaction_journal.budget_id')
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
->distinct()
->whereNull('budget_transaction_journal.budget_id')
->whereNull('budgets.deleted_at')
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email']);
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
->distinct()
->whereNull('budget_transaction_journal.budget_id')
->whereNull('budgets.deleted_at')
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email'])
;
/** @var stdClass $entry */
/** @var \stdClass $entry */
foreach ($set as $entry) {
$line = sprintf(
'User #%d (%s) has budget #%d ("%s") which has no transaction journals.',
@@ -90,13 +87,14 @@ class ReportEmptyObjects extends Command
private function reportEmptyCategories(): void
{
$set = Category::leftJoin('category_transaction_journal', 'categories.id', '=', 'category_transaction_journal.category_id')
->leftJoin('users', 'categories.user_id', '=', 'users.id')
->distinct()
->whereNull('category_transaction_journal.category_id')
->whereNull('categories.deleted_at')
->get(['categories.id', 'categories.name', 'categories.user_id', 'users.email']);
->leftJoin('users', 'categories.user_id', '=', 'users.id')
->distinct()
->whereNull('category_transaction_journal.category_id')
->whereNull('categories.deleted_at')
->get(['categories.id', 'categories.name', 'categories.user_id', 'users.email'])
;
/** @var stdClass $entry */
/** @var \stdClass $entry */
foreach ($set as $entry) {
$line = sprintf(
'User #%d (%s) has category #%d ("%s") which has no transaction journals.',
@@ -109,19 +107,17 @@ class ReportEmptyObjects extends Command
}
}
/**
*
*/
private function reportEmptyTags(): void
{
$set = Tag::leftJoin('tag_transaction_journal', 'tags.id', '=', 'tag_transaction_journal.tag_id')
->leftJoin('users', 'tags.user_id', '=', 'users.id')
->distinct()
->whereNull('tag_transaction_journal.tag_id')
->whereNull('tags.deleted_at')
->get(['tags.id', 'tags.tag', 'tags.user_id', 'users.email']);
->leftJoin('users', 'tags.user_id', '=', 'users.id')
->distinct()
->whereNull('tag_transaction_journal.tag_id')
->whereNull('tags.deleted_at')
->get(['tags.id', 'tags.tag', 'tags.user_id', 'users.email'])
;
/** @var stdClass $entry */
/** @var \stdClass $entry */
foreach ($set as $entry) {
$line = sprintf(
'User #%d (%s) has tag #%d ("%s") which has no transaction journals.',
@@ -140,14 +136,15 @@ class ReportEmptyObjects extends Command
private function reportAccounts(): void
{
$set = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
->leftJoin('users', 'accounts.user_id', '=', 'users.id')
->groupBy(['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email'])
->whereNull('transactions.account_id')
->get(
['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email']
);
->leftJoin('users', 'accounts.user_id', '=', 'users.id')
->groupBy(['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email'])
->whereNull('transactions.account_id')
->get(
['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email']
)
;
/** @var stdClass $entry */
/** @var \stdClass $entry */
foreach ($set as $entry) {
$line = 'User #%d (%s) has account #%d ("%s") which has no transactions.';
$line = sprintf($line, $entry->user_id, $entry->email, $entry->id, $entry->name);
@@ -161,10 +158,11 @@ class ReportEmptyObjects extends Command
private function reportBudgetLimits(): void
{
$set = Budget::leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budgets.id')
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
->groupBy(['budgets.id', 'budgets.name', 'budgets.encrypted', 'budgets.user_id', 'users.email'])
->whereNull('budget_limits.id')
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'budgets.encrypted', 'users.email']);
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
->groupBy(['budgets.id', 'budgets.name', 'budgets.encrypted', 'budgets.user_id', 'users.email'])
->whereNull('budget_limits.id')
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'budgets.encrypted', 'users.email'])
;
/** @var Budget $entry */
foreach ($set as $entry) {

View File

@@ -25,18 +25,14 @@ namespace FireflyIII\Console\Commands\Integrity;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command;
use Schema;
/**
* Class ReportIntegrity
*
*/
class ReportIntegrity extends Command
{
use ShowsFriendlyMessages;
protected $description = 'Will report on the integrity of your database.';
protected $signature = 'firefly-iii:report-integrity';
@@ -47,7 +43,7 @@ class ReportIntegrity extends Command
public function handle(): int
{
// if table does not exist, return false
if (!Schema::hasTable('users')) {
if (!\Schema::hasTable('users')) {
return 1;
}
$commands = [

View File

@@ -40,8 +40,6 @@ class ReportSum extends Command
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
@@ -64,6 +62,7 @@ class ReportSum extends Command
if (!is_numeric($sum)) {
$message = sprintf('Error: Transactions for user #%d (%s) have an invalid sum ("%s").', $user->id, $user->email, $sum);
$this->friendlyError($message);
continue;
}
if (0 !== bccomp($sum, '0')) {

View File

@@ -40,8 +40,6 @@ class RestoreOAuthKeys extends Command
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
@@ -50,9 +48,6 @@ class RestoreOAuthKeys extends Command
return 0;
}
/**
*
*/
private function restoreOAuthKeys(): void
{
if (!$this->keysInDatabase() && !$this->keysOnDrive()) {
@@ -84,41 +79,26 @@ class RestoreOAuthKeys extends Command
$this->friendlyPositive('OAuth keys are OK');
}
/**
* @return bool
*/
private function keysInDatabase(): bool
{
return OAuthKeys::keysInDatabase();
}
/**
* @return bool
*/
private function keysOnDrive(): bool
{
return OAuthKeys::hasKeyFiles();
}
/**
*
*/
private function generateKeys(): void
{
OAuthKeys::generateKeys();
}
/**
*
*/
private function storeKeysInDB(): void
{
OAuthKeys::storeKeysInDB();
}
/**
*
*/
private function restoreKeysFromDB(): bool
{
return OAuthKeys::restoreKeysFromDB();

View File

@@ -66,6 +66,7 @@ class UpdateGroupInformation extends Command
// recurrences, rule groups, rules, tags, transaction groups, transaction journals, webhooks
$users = User::get();
/** @var User $user */
foreach ($users as $user) {
$this->updateGroupInfo($user);
@@ -74,11 +75,6 @@ class UpdateGroupInformation extends Command
return 0;
}
/**
* @param User $user
*
* @return void
*/
private function updateGroupInfo(User $user): void
{
$group = $user->userGroup;
@@ -109,13 +105,6 @@ class UpdateGroupInformation extends Command
}
}
/**
* @param User $user
* @param UserGroup $group
* @param string $className
*
* @return void
*/
private function updateGroupInfoForObject(User $user, UserGroup $group, string $className): void
{
try {