mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 21:49:01 +01:00
Merge pull request #1189 from cachethq/update-system
Update check system
This commit is contained in:
commit
f3fec2c58c
70
app/GitHub/Release.php
Normal file
70
app/GitHub/Release.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\GitHub;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Contracts\Cache\Repository as CacheRepository;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
|
||||
class Release
|
||||
{
|
||||
/**
|
||||
* Cache instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* Config repository.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Creates a new release instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Repository $cache
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(CacheRepository $cache, ConfigRepository $config)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the latest GitHub release.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function latest()
|
||||
{
|
||||
$release = $this->cache->remember('version', 720, function () {
|
||||
$headers = ['Accept' => 'application/vnd.github.v3+json'];
|
||||
|
||||
// We can re-use the Emoji token here, if we have it.
|
||||
if ($token = $this->config->get('services.github.token')) {
|
||||
$headers['OAUTH-TOKEN'] = $token;
|
||||
}
|
||||
|
||||
return json_decode((new Client())->get('https://api.github.com/repos/cachethq/cachet/releases/latest', [
|
||||
'headers' => $headers,
|
||||
])->getBody(), true);
|
||||
});
|
||||
|
||||
return $release['tag_name'];
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
|
||||
|
||||
use CachetHQ\Cachet\GitHub\Release;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
@ -18,6 +19,7 @@ use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class ApiController extends Controller
|
||||
{
|
||||
@ -89,4 +91,20 @@ class ApiController extends Controller
|
||||
|
||||
throw new ModelNotFoundException("Incident template for $templateSlug could not be found.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Cachet is up to date.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function checkVersion()
|
||||
{
|
||||
$latest = app(Release::class)->latest();
|
||||
|
||||
return Response::json([
|
||||
'cachet_version' => CACHET_VERSION,
|
||||
'latest_version' => $latest,
|
||||
'is_latest' => version_compare(CACHET_VERSION, $latest) === 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -265,6 +265,7 @@ class DashboardRoutes
|
||||
$router->post('components/groups/order', 'ApiController@postUpdateComponentGroupOrder');
|
||||
$router->post('components/order', 'ApiController@postUpdateComponentOrder');
|
||||
$router->post('components/{component}', 'ApiController@postUpdateComponent');
|
||||
$router->get('system/version', 'ApiController@checkVersion');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
45
app/Providers/GitHubServiceProvider.php
Normal file
45
app/Providers/GitHubServiceProvider.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use CachetHQ\Cachet\GitHub\Release;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class GitHubServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerRelease();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the releases class.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerRelease()
|
||||
{
|
||||
$this->app->singleton('cachet.release', function ($app) {
|
||||
$cache = $app['cache.store'];
|
||||
$config = $app['config'];
|
||||
|
||||
return new Release($cache, $config);
|
||||
});
|
||||
|
||||
$this->app->alias('cachet.release', Release::class);
|
||||
}
|
||||
}
|
@ -171,6 +171,7 @@ return [
|
||||
'CachetHQ\Cachet\Providers\ComposerServiceProvider',
|
||||
'CachetHQ\Cachet\Providers\ConfigServiceProvider',
|
||||
'CachetHQ\Cachet\Providers\EventServiceProvider',
|
||||
'CachetHQ\Cachet\Providers\GitHubServiceProvider',
|
||||
'CachetHQ\Cachet\Providers\RepositoryServiceProvider',
|
||||
'CachetHQ\Cachet\Providers\RouteServiceProvider',
|
||||
|
||||
|
@ -23,6 +23,10 @@ return [
|
||||
|
|
||||
*/
|
||||
|
||||
'github' => [
|
||||
'token' => env('GITHUB_TOKEN'),
|
||||
],
|
||||
|
||||
'mailgun' => [
|
||||
'domain' => env('MAILGUN_DOMAIN'),
|
||||
'secret' => env('MAILGUN_SECRET'),
|
||||
|
16
public/build/dist/js/all-29dc2bf4b8.js
vendored
16
public/build/dist/js/all-29dc2bf4b8.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
||||
{
|
||||
"dist/css/all.css": "dist/css/all-ec9a9babc0.css",
|
||||
"dist/js/all.js": "dist/js/all-a7eebd3275.js"
|
||||
"dist/js/all.js": "dist/js/all-9ed1a73f72.js"
|
||||
}
|
@ -363,6 +363,19 @@ $(function() {
|
||||
|
||||
// Password strength
|
||||
$('.password-strength').strengthify();
|
||||
|
||||
// Check for updates.
|
||||
if ($('#update-alert').length > 0) {
|
||||
$.ajax({
|
||||
async: true,
|
||||
dataType: 'json',
|
||||
url: '/dashboard/api/system/version',
|
||||
}).done(function (result) {
|
||||
if (result.is_latest == false) {
|
||||
$('#update-alert').removeClass('hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function askConfirmation(callback) {
|
||||
|
@ -106,6 +106,10 @@ return [
|
||||
'failure' => 'Something went wrong with the signup.',
|
||||
],
|
||||
|
||||
'system' => [
|
||||
'update' => 'There is a newer version of Cachet available. You can learn how to update <a href="https://docs.cachethq.io/docs/updating-cachet">here</a>!',
|
||||
],
|
||||
|
||||
// Other
|
||||
'powered_by' => ':app Status Page is powered by <a href="https://cachethq.io" class="links">Cachet</a>.',
|
||||
'about_this_site' => 'About This Site',
|
||||
|
@ -10,6 +10,11 @@
|
||||
</span>
|
||||
</div>
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="alert alert-info hidden" id="update-alert">{!! trans('cachet.system.update') !!}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h4 class="sub-header">{{ trans('dashboard.components.component_statuses') }}</h4>
|
||||
|
Loading…
x
Reference in New Issue
Block a user