diff --git a/app/Services/SystemChecker.php b/app/Services/SystemChecker.php new file mode 100644 index 000000000..e4d83b5f1 --- /dev/null +++ b/app/Services/SystemChecker.php @@ -0,0 +1,65 @@ +localVersion = trim($this->getLocalVersion()); + + $this->remoteVersion = trim($this->getRemoteVersion()); + + return $this; + } + + public function getLocalVersion() + { + return cache()->remember($this->cacheKeyLocal, now()->addDay(), function () { + return shell_exec('git describe --tag --abbrev=0'); + }); + } + + 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 || $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(); + } +}