Skip to content

Commit

Permalink
Merge pull request #183 from laravel-enso/feature/version-upgrade
Browse files Browse the repository at this point in the history
Feature/version upgrade
  • Loading branch information
aocneanu committed Feb 11, 2021
2 parents 9219bfc + 6ab7e53 commit 0e9a665
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/config.php
@@ -1,7 +1,7 @@
<?php

return [
'version' => '3.9.x',
'version' => '4.6.0',
'ownerCompanyId' => env('OWNER_COMPANY_ID', 1),
'showQuote' => env('SHOW_QUOTE', true),
'defaultRole' => 'admin',
Expand Down
4 changes: 3 additions & 1 deletion src/AppServiceProvider.php
Expand Up @@ -11,6 +11,7 @@
use LaravelEnso\Core\Commands\ClearPreferences;
use LaravelEnso\Core\Commands\ResetStorage;
use LaravelEnso\Core\Commands\UpdateGlobalPreferences;
use LaravelEnso\Core\Commands\Version;
use LaravelEnso\Core\Http\Middleware\VerifyActiveState;
use LaravelEnso\Core\Http\Middleware\XssSanitizer;
use LaravelEnso\Core\Models\User;
Expand Down Expand Up @@ -41,7 +42,8 @@ public function boot()
AnnounceAppUpdate::class,
ClearPreferences::class,
ResetStorage::class,
UpdateGlobalPreferences::class
UpdateGlobalPreferences::class,
Version::class,
);
}

Expand Down
23 changes: 23 additions & 0 deletions src/Commands/Version.php
@@ -0,0 +1,23 @@
<?php

namespace LaravelEnso\Core\Commands;

use Illuminate\Console\Command;
use LaravelEnso\Core\Services\Version as Service;

class Version extends Command
{
protected $signature = 'enso:version';

protected $description = 'Display framework version';

public function handle()
{
$version = (new Service());
$this->info("Current version is {$version->current()}");

if ($version->isOutdated()) {
$this->warn("Latest version is {$version->latest()}");
}
}
}
36 changes: 36 additions & 0 deletions src/Services/Version.php
@@ -0,0 +1,36 @@
<?php

namespace LaravelEnso\Core\Services;

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;

class Version
{
private const Endpoint = 'https://api.github.com/repos/laravel-enso/enso/releases/latest';

private $release;

public function __construct()
{
$this->channels = new Collection();
}

public function latest()
{
$this->release ??= Http::get(self::Endpoint)->json();

return $this->release['tag_name'] ?? null;
}

public function current()
{
return Config::get('enso.config.version');
}

public function isOutdated()
{
return $this->current() !== $this->latest();
}
}

0 comments on commit 0e9a665

Please sign in to comment.