mirror of
https://github.com/alexjustesen/speedtest-tracker.git
synced 2026-06-23 04:10:25 +00:00
[Chore] Remove version checker (#2053)
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
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::where('role', '=', UserRole::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Services\SystemChecker;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Console\AboutCommand;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -45,11 +44,8 @@ class AppServiceProvider extends ServiceProvider
|
||||
URL::forceScheme('https');
|
||||
}
|
||||
|
||||
$system = new SystemChecker;
|
||||
|
||||
AboutCommand::add('Speedtest Tracker', fn () => [
|
||||
'Version' => $system->getLocalVersion(),
|
||||
'Out of date' => $system->isOutOfDate() ? 'Yes' : 'No',
|
||||
'Version' => config('speedtest.build_version'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
/**
|
||||
* 🤔 inspired by: https://github.com/ploi/roadmap/blob/main/app/Services/SystemChecker.php
|
||||
*/
|
||||
class SystemChecker
|
||||
{
|
||||
public $localVersion;
|
||||
|
||||
public $remoteVersion;
|
||||
|
||||
public string $cacheKeyLocal = 'speedtest-local-version';
|
||||
|
||||
public string $cacheKeyRemote = 'speedtest-remote-version';
|
||||
|
||||
public function getVersions(): self
|
||||
{
|
||||
$this->localVersion = trim($this->getLocalVersion());
|
||||
|
||||
$this->remoteVersion = trim($this->getRemoteVersion());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLocalVersion()
|
||||
{
|
||||
return config('speedtest.build_version');
|
||||
}
|
||||
|
||||
public function getRemoteVersion()
|
||||
{
|
||||
return cache()->remember($this->cacheKeyRemote, now()->addDay(), function () {
|
||||
return shell_exec('curl https://api.github.com/repos/alexjustesen/speedtest-tracker/releases/latest -s | grep \'"tag_name":\' | sed -E \'s/.*"([^"]+)".*/\1/\'');
|
||||
});
|
||||
}
|
||||
|
||||
public function isOutOfDate()
|
||||
{
|
||||
$this->getVersions();
|
||||
|
||||
return $this->localVersion != $this->remoteVersion;
|
||||
}
|
||||
|
||||
public function flushVersionData()
|
||||
{
|
||||
try {
|
||||
cache()->forget($this->cacheKeyLocal);
|
||||
|
||||
cache()->forget($this->cacheKeyRemote);
|
||||
} catch (\Exception $exception) {
|
||||
// fail silently, it's ok
|
||||
}
|
||||
}
|
||||
|
||||
public function getPhpVersion(): string
|
||||
{
|
||||
return phpversion();
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,6 @@ Schedule::command('model:prune')
|
||||
return config('speedtest.prune_results_older_than') > 0;
|
||||
});
|
||||
|
||||
/**
|
||||
* Checked for new versions weekly on Thursday because
|
||||
* I usually do releases on Thursday or Friday.
|
||||
*/
|
||||
Schedule::command('app:version')
|
||||
->weeklyOn(5);
|
||||
|
||||
/**
|
||||
* Nightly maintenance
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user