improved version checker
This commit is contained in:
parent
d8a0948faf
commit
4b0e836e21
@ -43,7 +43,11 @@ class Update extends Command
|
|||||||
|
|
||||||
$this->alias = $this->argument('alias');
|
$this->alias = $this->argument('alias');
|
||||||
|
|
||||||
$this->new = $this->getNewVersion();
|
if (false === $this->new = $this->getNewVersion()) {
|
||||||
|
$this->error('Not able to get the latest version of ' . $this->alias . '!');
|
||||||
|
|
||||||
|
return self::CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
$this->old = $this->getOldVersion();
|
$this->old = $this->getOldVersion();
|
||||||
|
|
||||||
@ -71,15 +75,7 @@ class Update extends Command
|
|||||||
|
|
||||||
public function getNewVersion()
|
public function getNewVersion()
|
||||||
{
|
{
|
||||||
$new = $this->argument('new');
|
return ($this->argument('new') == 'latest') ? Versions::latest($this->alias) : $this->argument('new');
|
||||||
|
|
||||||
if ($new == 'latest') {
|
|
||||||
$modules = ($this->alias == 'core') ? [] : [$this->alias];
|
|
||||||
|
|
||||||
$new = Versions::latest($modules)[$this->alias]->data->latest;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $new;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOldVersion()
|
public function getOldVersion()
|
||||||
|
@ -158,7 +158,7 @@ class Updater
|
|||||||
|
|
||||||
$modules = module()->all();
|
$modules = module()->all();
|
||||||
|
|
||||||
$versions = Versions::latest($modules);
|
$versions = Versions::all($modules);
|
||||||
|
|
||||||
foreach ($versions as $alias => $latest_version) {
|
foreach ($versions as $alias => $latest_version) {
|
||||||
$installed_version = ($alias == 'core') ? version('short') : module($alias)->get('version');
|
$installed_version = ($alias == 'core') ? version('short') : module($alias)->get('version');
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Utilities;
|
namespace App\Utilities;
|
||||||
|
|
||||||
|
use Akaunting\Module\Module;
|
||||||
use App\Traits\SiteApi;
|
use App\Traits\SiteApi;
|
||||||
use Cache;
|
use Cache;
|
||||||
use Date;
|
use Date;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Parsedown;
|
use Parsedown;
|
||||||
|
|
||||||
class Versions
|
class Versions
|
||||||
@ -52,7 +54,18 @@ class Versions
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function latest($modules = [])
|
public static function latest($alias)
|
||||||
|
{
|
||||||
|
$versions = static::all($alias);
|
||||||
|
|
||||||
|
if (empty($versions[$alias]) || empty($versions[$alias]->data)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $versions[$alias]->data->latest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function all($modules = null)
|
||||||
{
|
{
|
||||||
// Get data from cache
|
// Get data from cache
|
||||||
$versions = Cache::get('versions');
|
$versions = Cache::get('versions');
|
||||||
@ -70,8 +83,18 @@ class Versions
|
|||||||
|
|
||||||
$versions['core'] = static::getLatestVersion($url, $info['akaunting']);
|
$versions['core'] = static::getLatestVersion($url, $info['akaunting']);
|
||||||
|
|
||||||
|
$modules = Arr::wrap($modules);
|
||||||
|
|
||||||
// Then modules
|
// Then modules
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
|
if (is_string($module)) {
|
||||||
|
$module = module($module);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$module instanceof Module) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$alias = $module->get('alias');
|
$alias = $module->get('alias');
|
||||||
$version = $module->get('version');
|
$version = $module->get('version');
|
||||||
|
|
||||||
@ -85,7 +108,7 @@ class Versions
|
|||||||
return $versions;
|
return $versions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getLatestVersion($url, $latest)
|
protected static function getLatestVersion($url, $latest)
|
||||||
{
|
{
|
||||||
if (!$data = static::getResponseData('GET', $url, ['timeout' => 10])) {
|
if (!$data = static::getResponseData('GET', $url, ['timeout' => 10])) {
|
||||||
return $latest;
|
return $latest;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user