mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
cleanup: Commands are a lot less verbal and report better on success / failue
This commit is contained in:
@@ -38,18 +38,8 @@ use Illuminate\Support\Facades\Log;
|
||||
class CreateGroupMemberships extends Command
|
||||
{
|
||||
public const CONFIG_NAME = '560_create_group_memberships';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Update group memberships';
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:create-group-memberships';
|
||||
protected $signature = 'firefly-iii:create-group-memberships';
|
||||
|
||||
/**
|
||||
* TODO move to helper.
|
||||
@@ -64,7 +54,6 @@ class CreateGroupMemberships extends Command
|
||||
$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();
|
||||
@@ -83,15 +72,11 @@ class CreateGroupMemberships extends Command
|
||||
'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.');
|
||||
}
|
||||
|
||||
Log::debug(sprintf('User #%d now has main group.', $user->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,12 +87,8 @@ class CreateGroupMemberships extends Command
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$start = microtime(true);
|
||||
|
||||
$this->createGroupMemberships();
|
||||
|
||||
$end = round(microtime(true) - $start, 2);
|
||||
$this->info(sprintf('Validated group memberships in %s seconds.', $end));
|
||||
$this->info('Correct: validated group memberships');
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -121,9 +102,7 @@ class CreateGroupMemberships extends Command
|
||||
$users = User::get();
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
Log::debug(sprintf('Manage group memberships for user #%d', $user->id));
|
||||
self::createGroupMembership($user);
|
||||
Log::debug(sprintf('Done with user #%d', $user->id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -55,14 +55,11 @@ class ReportEmptyObjects extends Command
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$start = microtime(true);
|
||||
$this->reportEmptyBudgets();
|
||||
$this->reportEmptyCategories();
|
||||
$this->reportEmptyTags();
|
||||
$this->reportAccounts();
|
||||
$this->reportBudgetLimits();
|
||||
$end = round(microtime(true) - $start, 2);
|
||||
$this->info(sprintf('Report on empty objects finished in %s seconds', $end));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -32,18 +32,8 @@ use Illuminate\Console\Command;
|
||||
*/
|
||||
class ReportSum extends Command
|
||||
{
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Report on the total sum of transactions. Must be 0.';
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:report-sum';
|
||||
protected $signature = 'firefly-iii:report-sum';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
@@ -62,7 +52,6 @@ class ReportSum extends Command
|
||||
*/
|
||||
private function reportSum(): void
|
||||
{
|
||||
$start = microtime(true);
|
||||
/** @var UserRepositoryInterface $userRepository */
|
||||
$userRepository = app(UserRepositoryInterface::class);
|
||||
|
||||
@@ -74,10 +63,8 @@ class ReportSum extends Command
|
||||
$this->error($message);
|
||||
}
|
||||
if (0 === bccomp($sum, '0')) {
|
||||
$this->info(sprintf('Amount integrity OK for user #%d', $user->id));
|
||||
$this->info(sprintf('Correct: Amount integrity OK for user #%d', $user->id));
|
||||
}
|
||||
}
|
||||
$end = round(microtime(true) - $start, 2);
|
||||
$this->info(sprintf('Report on total sum finished in %s seconds', $end));
|
||||
}
|
||||
}
|
||||
|
@@ -26,25 +26,14 @@ namespace FireflyIII\Console\Commands\Integrity;
|
||||
|
||||
use FireflyIII\Support\System\OAuthKeys;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class RestoreOAuthKeys
|
||||
*/
|
||||
class RestoreOAuthKeys extends Command
|
||||
{
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Will restore the OAuth keys generated for the system.';
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:restore-oauth-keys';
|
||||
protected $signature = 'firefly-iii:restore-oauth-keys';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
@@ -95,38 +84,33 @@ class RestoreOAuthKeys extends Command
|
||||
*/
|
||||
private function restoreOAuthKeys(): void
|
||||
{
|
||||
Log::debug('Going to restoreOAuthKeys()');
|
||||
if (!$this->keysInDatabase() && !$this->keysOnDrive()) {
|
||||
Log::debug('Keys are not in DB and keys are not on the drive.');
|
||||
$this->generateKeys();
|
||||
$this->storeKeysInDB();
|
||||
$this->line('Generated and stored new keys.');
|
||||
$this->line('Correct: generated and stored new keys.');
|
||||
|
||||
return;
|
||||
}
|
||||
if ($this->keysInDatabase() && !$this->keysOnDrive()) {
|
||||
Log::debug('Keys are in DB and keys are not on the drive. Restore.');
|
||||
$result = $this->restoreKeysFromDB();
|
||||
if (true === $result) {
|
||||
$this->line('Restored OAuth keys from database.');
|
||||
$this->line('Correct: restored OAuth keys from database.');
|
||||
|
||||
return;
|
||||
}
|
||||
app('log')->warning('Could not restore keys. Will create new ones.');
|
||||
$this->generateKeys();
|
||||
$this->storeKeysInDB();
|
||||
$this->line('Generated and stored new keys.');
|
||||
$this->line('Correct: generated and stored new keys.');
|
||||
|
||||
return;
|
||||
}
|
||||
if (!$this->keysInDatabase() && $this->keysOnDrive()) {
|
||||
Log::debug('Keys are not in DB and keys are on the drive. Save in DB.');
|
||||
$this->storeKeysInDB();
|
||||
$this->line('Stored OAuth keys in database.');
|
||||
$this->line('Correct: stored OAuth keys in database.');
|
||||
|
||||
return;
|
||||
}
|
||||
$this->line('OAuth keys are OK');
|
||||
$this->line('Correct: OAuth keys are OK');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -48,18 +48,8 @@ use Illuminate\Database\QueryException;
|
||||
*/
|
||||
class UpdateGroupInformation extends Command
|
||||
{
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Makes sure that every object is linked to a group';
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:upgrade-group-information';
|
||||
protected $signature = 'firefly-iii:upgrade-group-information';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
@@ -126,7 +116,7 @@ class UpdateGroupInformation extends Command
|
||||
return;
|
||||
}
|
||||
if (0 !== $result) {
|
||||
$this->line(sprintf('Moved %d %s objects to the correct group.', $result, str_replace('FireflyIII\\Models\\', '', $className)));
|
||||
$this->info(sprintf('Correct: Moved %d %s objects to the correct group.', $result, str_replace('FireflyIII\\Models\\', '', $className)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user