From b38a31f81be3096940903ef2348d4830245ff23d Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Wed, 5 Jun 2024 15:44:24 -0400 Subject: [PATCH 1/9] renamed user reset password and use prompts for input --- app/Console/Commands/ResetUserPassword.php | 46 ------------------ app/Console/Commands/UserResetPassword.php | 55 ++++++++++++++++++++++ 2 files changed, 55 insertions(+), 46 deletions(-) delete mode 100644 app/Console/Commands/ResetUserPassword.php create mode 100644 app/Console/Commands/UserResetPassword.php diff --git a/app/Console/Commands/ResetUserPassword.php b/app/Console/Commands/ResetUserPassword.php deleted file mode 100644 index fa03dacd4..000000000 --- a/app/Console/Commands/ResetUserPassword.php +++ /dev/null @@ -1,46 +0,0 @@ -argument('email')); - - if (! $user) { - // couldn't find the user so should fail. - $this->error('Could not find a user with the email address of '.$this->argument('email')); - - return; - } - - $password = $this->secret('What is the password?'); - - $user->update([ - 'password' => Hash::make($password), - ]); - } -} diff --git a/app/Console/Commands/UserResetPassword.php b/app/Console/Commands/UserResetPassword.php new file mode 100644 index 000000000..b6fb784e1 --- /dev/null +++ b/app/Console/Commands/UserResetPassword.php @@ -0,0 +1,55 @@ + match (true) { + ! User::firstWhere('email', $value) => 'User not found.', + default => null + } + ); + + $password = password( + label: 'What is the new password?', + required: true, + ); + + User::where('email', '=', $email) + ->update([ + 'password' => Hash::make($password), + ]); + + info('The password for "'.$email.'" has been updated.'); + } +} From f2a2d0f557e0bc0e79150506c11a03d258c00dac Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Wed, 5 Jun 2024 15:46:17 -0400 Subject: [PATCH 2/9] renamed user change role --- ...{UpdateUserRole.php => UserChangeRole.php} | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) rename app/Console/Commands/{UpdateUserRole.php => UserChangeRole.php} (66%) diff --git a/app/Console/Commands/UpdateUserRole.php b/app/Console/Commands/UserChangeRole.php similarity index 66% rename from app/Console/Commands/UpdateUserRole.php rename to app/Console/Commands/UserChangeRole.php index 2bf62f75d..e21db8f96 100644 --- a/app/Console/Commands/UpdateUserRole.php +++ b/app/Console/Commands/UserChangeRole.php @@ -5,26 +5,25 @@ use App\Models\User; use Illuminate\Console\Command; -use function Laravel\Prompts\confirm; use function Laravel\Prompts\info; use function Laravel\Prompts\select; use function Laravel\Prompts\text; -class UpdateUserRole extends Command +class UserChangeRole extends Command { /** * The name and signature of the console command. * * @var string */ - protected $signature = 'app:update-user-role'; + protected $signature = 'app:user-change-role'; /** * The console command description. * * @var string */ - protected $description = 'Change the role for a given user.'; + protected $description = 'Change the role for a user.'; /** * Execute the console command. @@ -49,18 +48,11 @@ public function handle(): void default: 'user' ); - $confirmed = confirm( - label: 'Are you sure?', - required: true - ); - - if ($confirmed) { - User::firstWhere('email', $email) - ->update([ - 'role' => $role, - ]); + User::where('email', '=', $email) + ->update([ + 'role' => $role, + ]); - info('User role updated.'); - } + info('User role updated.'); } } From 343b2634a85626794bf7d86d2ae8d668f3be5193 Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Wed, 5 Jun 2024 15:48:00 -0400 Subject: [PATCH 3/9] fail fix result status command if cancelled --- app/Console/Commands/Maintenance/FixResultStatuses.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/Maintenance/FixResultStatuses.php b/app/Console/Commands/Maintenance/FixResultStatuses.php index e3e36c498..2d24e8ac7 100644 --- a/app/Console/Commands/Maintenance/FixResultStatuses.php +++ b/app/Console/Commands/Maintenance/FixResultStatuses.php @@ -34,7 +34,7 @@ public function handle(): void $this->info('📖 Read the docs: https://docs.speedtest-tracker.dev/other/commands'); if (! $this->confirm('Do you want to continue?')) { - return; + $this->fail('Command cancelled.'); } /** From dd35675a4890cbd41aa03d8f96bd307e6b20d4c2 Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Wed, 5 Jun 2024 15:48:11 -0400 Subject: [PATCH 4/9] simplified admins query --- app/Console/Commands/VersionChecker.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/VersionChecker.php b/app/Console/Commands/VersionChecker.php index 29dca0b34..b91de2002 100644 --- a/app/Console/Commands/VersionChecker.php +++ b/app/Console/Commands/VersionChecker.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Enums\UserRole; use App\Models\User; use App\Services\SystemChecker; use Filament\Notifications\Actions\Action; @@ -35,9 +36,7 @@ public function handle(): void return; } - $admins = User::select(['id', 'name', 'email', 'role']) - ->where('role', 'admin') - ->get(); + $admins = User::where('role', '='. UserRole::Admin)->get(); foreach ($admins as $user) { Notification::make() From 6e8ecdca311cddfd524387c9b2a7849feabc5081 Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Wed, 5 Jun 2024 15:50:36 -0400 Subject: [PATCH 5/9] removed site name and public dashboard from update general settings --- .../Commands/UpdateGeneralSettings.php | 46 +------------------ 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/app/Console/Commands/UpdateGeneralSettings.php b/app/Console/Commands/UpdateGeneralSettings.php index fec494b19..449a8c03d 100644 --- a/app/Console/Commands/UpdateGeneralSettings.php +++ b/app/Console/Commands/UpdateGeneralSettings.php @@ -8,7 +8,6 @@ use Illuminate\Console\Command; use function Laravel\Prompts\confirm; -use function Laravel\Prompts\select; use function Laravel\Prompts\text; class UpdateGeneralSettings extends Command @@ -25,7 +24,7 @@ class UpdateGeneralSettings extends Command * * @var string */ - protected $description = 'CLI to update the general settings.'; + protected $description = 'Update the application\'s general settings.'; /** * Execute the console command. @@ -34,8 +33,6 @@ public function handle(): void { $settings = new GeneralSettings(); - $this->updateSiteName($settings); - $this->updatePublicDashboard($settings); $this->updateTimeZone($settings); $this->updateSchedule($settings); $this->resetSevers($settings); @@ -59,26 +56,6 @@ protected function resetSevers($settings): void } } - protected function updatePublicDashboard($settings): void - { - $publicDashboard = select( - label: 'Make the dashboard public?', - options: ['Yes', 'No'], - default: 'Yes', - required: true, - ); - - if ($publicDashboard == 'Yes') { - $settings->public_dashboard_enabled = true; - - $settings->save(); - } else { - $settings->public_dashboard_enabled = false; - } - - $settings->save(); - } - protected function updateSchedule($settings): void { $cron = text( @@ -99,27 +76,6 @@ protected function updateSchedule($settings): void } } - protected function updateSiteName($settings): void - { - $name = text( - label: 'What is the site name?', - placeholder: 'Speedtest Tracker', - default: $settings->site_name, - required: true, - validate: fn (string $value) => match (true) { - strlen($value) < 2 => 'The site name must be at least 2 characters.', - strlen($value) > 50 => 'The site name must not exceed 50 characters.', - default => null - } - ); - - if ($name) { - $settings->site_name = $name; - - $settings->save(); - } - } - protected function updateTimeZone($settings): void { $timezone = text( From 80bc451d4fcdb174e534cf629ed7414a1fb5db80 Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Wed, 5 Jun 2024 15:51:51 -0400 Subject: [PATCH 6/9] removed system maintenance command --- app/Console/Commands/SystemMaintenance.php | 46 ---------------------- bootstrap/app.php | 7 ---- 2 files changed, 53 deletions(-) delete mode 100644 app/Console/Commands/SystemMaintenance.php diff --git a/app/Console/Commands/SystemMaintenance.php b/app/Console/Commands/SystemMaintenance.php deleted file mode 100644 index 5decbd29d..000000000 --- a/app/Console/Commands/SystemMaintenance.php +++ /dev/null @@ -1,46 +0,0 @@ -daily(); } - /** - * Perform system maintenance weekly on Sunday morning, - * start off the week nice and fresh. - */ - $schedule->command(\App\Console\Commands\SystemMaintenance::class)->weeklyOn(0) - ->timezone($settings->timezone ?? 'UTC'); - /** * Checked for new versions weekly on Thursday because * I usually do releases on Thursday or Friday. From 70703e8f84bc53a3805fab1543749483c603e00c Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Wed, 5 Jun 2024 15:59:51 -0400 Subject: [PATCH 7/9] cleaned up install command --- app/Console/Commands/InstallCommand.php | 61 ++++++------------------- 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/app/Console/Commands/InstallCommand.php b/app/Console/Commands/InstallCommand.php index 481dc7ebe..d28b9e562 100644 --- a/app/Console/Commands/InstallCommand.php +++ b/app/Console/Commands/InstallCommand.php @@ -3,7 +3,9 @@ namespace App\Console\Commands; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Artisan; + +use function Laravel\Prompts\confirm; +use function Laravel\Prompts\info; class InstallCommand extends Command { @@ -19,7 +21,7 @@ class InstallCommand extends Command * * @var string */ - protected $description = 'A fresh install of Speedtest Tracker.'; + protected $description = 'Install a fresh version of the Speedtest Tracker application.'; /** * Execute the console command. @@ -27,63 +29,30 @@ class InstallCommand extends Command public function handle(): void { if (! $this->option('force')) { - $this->newLine(2); - - $this->info("Running the install will reset all of the application's data."); - $this->warn('!!! ALL OF THE DATA WILL BE DELETED !!!'); - - if (! $this->confirm('Do you wish to continue?')) { - $this->info('Install cancelled.'); + $confirmed = confirm('Are you sure you want to continue?'); - return; + if (! $confirmed) { + $this->fail('Application install cancelled.'); } } - $this->info('Starting to install the application...'); - - $this->newLine(); - - $this->checkAppKey(); - - $this->line('⏳ Optimizing the cache...'); + $this->info('⏳ Starting to install the application...'); if (app()->environment('production') || app()->environment('testing')) { - Artisan::call('view:clear'); - Artisan::call('filament:cache-components'); - Artisan::call('optimize'); + $this->call('filament:cache-components'); + $this->call('optimize'); + } else { + $this->call('optimize:clear'); } - $this->line('✅ Optimized cache'); - - $this->newLine(); - - $this->line('⏳ Migrating the database...'); - try { - Artisan::call('migrate:fresh', [ + $this->call('migrate:fresh', [ '--force' => true, ]); } catch (\Throwable $th) { - $this->error('❌ There was an issue migrating the database, check the logs.'); - - return; + $this->fail('❌ There was an issue migrating the database, check the logs.'); } - $this->line('✅ Database migrated'); - - $this->newLine(); - - $this->line('🚀 Finished installing the application!'); - } - - public function checkAppKey() - { - if (empty(config('app.key'))) { - $this->line('🔑 Creating an application key'); - - Artisan::call('key:generate'); - - $this->line('✅ Application key created'); - } + info('🚀 Finished installing Speedtest Tracker!'); } } From 2fc0d922704da85573be472e1836eb4ccf0c7a73 Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Wed, 5 Jun 2024 16:01:27 -0400 Subject: [PATCH 8/9] renamed result fix statuses --- .../FixResultStatuses.php => ResultFixStatuses.php} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename app/Console/Commands/{Maintenance/FixResultStatuses.php => ResultFixStatuses.php} (94%) diff --git a/app/Console/Commands/Maintenance/FixResultStatuses.php b/app/Console/Commands/ResultFixStatuses.php similarity index 94% rename from app/Console/Commands/Maintenance/FixResultStatuses.php rename to app/Console/Commands/ResultFixStatuses.php index 2d24e8ac7..cefd18557 100644 --- a/app/Console/Commands/Maintenance/FixResultStatuses.php +++ b/app/Console/Commands/ResultFixStatuses.php @@ -7,14 +7,14 @@ use Illuminate\Database\Query\Builder; use Illuminate\Support\Facades\DB; -class FixResultStatuses extends Command +class ResultFixStatuses extends Command { /** * The name and signature of the console command. * * @var string */ - protected $signature = 'app:fix-result-statuses'; + protected $signature = 'app:result-fix-statuses'; /** * The console command description. From 5eec6d67b82d0373751cb479cba4916841319582 Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Wed, 5 Jun 2024 16:02:07 -0400 Subject: [PATCH 9/9] query typo --- app/Console/Commands/VersionChecker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/VersionChecker.php b/app/Console/Commands/VersionChecker.php index b91de2002..6737e8c43 100644 --- a/app/Console/Commands/VersionChecker.php +++ b/app/Console/Commands/VersionChecker.php @@ -36,7 +36,7 @@ public function handle(): void return; } - $admins = User::where('role', '='. UserRole::Admin)->get(); + $admins = User::where('role', '=', UserRole::Admin)->get(); foreach ($admins as $user) { Notification::make()