Show if there's a new version available on the admin dashboard #143
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Facades;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use \Illuminate\Support\Facades\Facade;
|
||||
|
||||
class Utils extends Facade
|
||||
@@ -11,6 +12,33 @@ class Utils extends Facade
|
||||
return 'utils';
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a URI. If a file is given, it will save the downloaded
|
||||
* content into that file
|
||||
* @param $uri
|
||||
* @param null $file
|
||||
* @return string
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function downloadUrl($uri, $file=null)
|
||||
{
|
||||
$opts = [];
|
||||
if($file !== null) {
|
||||
$opts['sink'] = $file;
|
||||
}
|
||||
|
||||
$client = new Client();
|
||||
$response = $client->request('GET', $uri, $opts);
|
||||
|
||||
$body = $response->getBody()->getContents();
|
||||
if($response->getHeader('content-type') === 'application/json') {
|
||||
$body = \GuzzleHttp\json_decode($body);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 40 character API key that a user can use
|
||||
* @return string
|
||||
|
||||
@@ -3,12 +3,17 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Auth;
|
||||
use Flash;
|
||||
use Version;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Facades\Utils;
|
||||
use App\Repositories\NewsRepository;
|
||||
use App\Repositories\PirepRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
|
||||
use vierbergenlars\SemVer\version as semver;
|
||||
|
||||
class DashboardController extends BaseController
|
||||
{
|
||||
private $newsRepo, $pirepRepo, $userRepo;
|
||||
@@ -24,10 +29,29 @@ class DashboardController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the Airlines.
|
||||
* Check if a new version is available by checking the VERSION file from
|
||||
* S3 and then using the semver library to do the comparison. Just show
|
||||
* a session flash file on this page that'll get cleared right away
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected function checkNewVersion()
|
||||
{
|
||||
$current_version = new semver(Version::compact());
|
||||
$latest_version = new semver(Utils::downloadUrl(config('phpvms.version_file')));
|
||||
|
||||
if(semver::gt($latest_version, $current_version)) {
|
||||
Flash::warning('New version '.$latest_version.' is available!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the admin dashboard
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->checkNewVersion();
|
||||
|
||||
return view('admin.dashboard.index', [
|
||||
'news' => $this->newsRepo->getLatest(),
|
||||
'pending_pireps' => $this->pirepRepo->getPendingCount(),
|
||||
|
||||
@@ -49,7 +49,8 @@
|
||||
"league/iso3166": "^2.1",
|
||||
"google/apiclient": "^2.0",
|
||||
"theiconic/php-ga-measurement-protocol": "^2.0",
|
||||
"irazasyed/laravel-gamp": "^1.3"
|
||||
"irazasyed/laravel-gamp": "^1.3",
|
||||
"vierbergenlars/php-semver": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "6.4.0",
|
||||
|
||||
54
composer.lock
generated
54
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "6778fdaa04275c7824a22188522f844c",
|
||||
"content-hash": "9fc46733ea4ac9fb3c249612e2e302cf",
|
||||
"packages": [
|
||||
{
|
||||
"name": "arrilot/laravel-widgets",
|
||||
@@ -5130,6 +5130,58 @@
|
||||
],
|
||||
"time": "2015-02-23T12:40:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vierbergenlars/php-semver",
|
||||
"version": "3.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/vierbergenlars/php-semver.git",
|
||||
"reference": "be22b86be4c1133acc42fd1685276792024af5f9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/vierbergenlars/php-semver/zipball/be22b86be4c1133acc42fd1685276792024af5f9",
|
||||
"reference": "be22b86be4c1133acc42fd1685276792024af5f9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4"
|
||||
},
|
||||
"bin": [
|
||||
"bin/semver",
|
||||
"bin/update-versions"
|
||||
],
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"vierbergenlars\\SemVer\\": "src/",
|
||||
"vierbergenlars\\LibJs\\": "src/"
|
||||
},
|
||||
"classmap": [
|
||||
"src/vierbergenlars/SemVer/internal.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Lars Vierbergen",
|
||||
"email": "vierbergenlars@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "The Semantic Versioner for PHP",
|
||||
"keywords": [
|
||||
"semantic",
|
||||
"semver",
|
||||
"versioning"
|
||||
],
|
||||
"time": "2017-07-11T09:53:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vlucas/phpdotenv",
|
||||
"version": "v2.4.0",
|
||||
|
||||
@@ -41,4 +41,9 @@ return [
|
||||
* Misc Settings
|
||||
*/
|
||||
'news_feed_url' => 'http://forum.phpvms.net/rss/1-announcements-feed.xml/?',
|
||||
|
||||
/**
|
||||
* URL to the latest version file
|
||||
*/
|
||||
'version_file' => 'http://downloads.phpvms.net/VERSION',
|
||||
];
|
||||
|
||||
@@ -9,7 +9,7 @@ build:
|
||||
mode: number
|
||||
length: 6
|
||||
increment_by: 1
|
||||
number: 180119-6e12c0
|
||||
number: 180119-a1b989
|
||||
git_absorb: git-local
|
||||
git:
|
||||
git-local: 'git rev-parse --verify HEAD'
|
||||
|
||||
Reference in New Issue
Block a user