Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/version upgrade #183

Merged
merged 13 commits into from Feb 11, 2021
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();
}
}