Files
speedtest-tracker/app/Console/Commands/VersionChecker.php
T
Alex Justesen ce21ae24db Laravel 11.x Shift (#1389)
Co-authored-by: Shift <shift@laravelshift.com>
2024-05-06 08:00:29 -04:00

58 lines
1.5 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\User;
use App\Services\SystemChecker;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
use Illuminate\Console\Command;
class VersionChecker extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:version';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Sends a notification to the admin users when Speedtest Tracker is outdated.';
/**
* Execute the console command.
*/
public function handle(): void
{
$system = new SystemChecker;
if (! $system->isOutOfDate()) {
return;
}
$admins = User::select(['id', 'name', 'email', 'role'])
->where('role', 'admin')
->get();
foreach ($admins as $user) {
Notification::make()
->title('Update Available')
->body("There's a new version of Speedtest Tracker available: {$system->getRemoteVersion()}")
->info()
->actions([
Action::make('view releases')
->button()
->color('gray')
->url('https://github.com/alexjustesen/speedtest-tracker/releases')
->openUrlInNewTab(),
])
->sendToDatabase($user);
}
}
}