formatting

This commit is contained in:
denisdulici 2019-12-17 16:27:50 +03:00
parent 2ab45ac5a8
commit 4914e34f6c
2 changed files with 21 additions and 31 deletions

View File

@ -139,39 +139,30 @@ class Updater
public static function all()
{
// Get data from cache
$data = Cache::get('updates');
$updates = Cache::get('updates');
if (!empty($data)) {
return $data;
if (!empty($updates)) {
return $updates;
}
// No data in cache, grab them from remote
$data = array();
$updates = [];
$modules = module()->all();
$versions = Versions::latest($modules);
foreach ($versions as $alias => $version) {
// Modules come as array
if ($alias == 'core') {
if (version_compare(version('short'), $version, '<')) {
$data['core'] = $version;
}
} else {
$module = module($alias);
foreach ($versions as $alias => $latest_version) {
$installed_version = ($alias == 'core') ? version('short') : module($alias)->get('version');
// Up-to-date
if (version_compare($module->get('version'), $version, '>=')) {
continue;
}
$data[$alias] = $version;
if (version_compare($installed_version, $latest_version, '>=')) {
continue;
}
$updates[$alias] = $latest_version;
}
Cache::put('updates', $data, Date::now()->addHour(6));
Cache::put('updates', $updates, Date::now()->addHour(6));
return $data;
return $updates;
}
}

View File

@ -52,24 +52,23 @@ class Versions
return $output;
}
public static function latest($modules = array())
public static function latest($modules = [])
{
// Get data from cache
$data = Cache::get('versions');
$versions = Cache::get('versions');
if (!empty($data)) {
return $data;
if (!empty($versions)) {
return $versions;
}
$info = Info::all();
// No data in cache, grab them from remote
$data = [];
$versions = [];
// Check core first
$url = 'core/version/' . $info['akaunting'] . '/' . $info['php'] . '/' . $info['mysql'] . '/' . $info['companies'];
$data['core'] = static::getLatestVersion($url, $info['akaunting']);
$versions['core'] = static::getLatestVersion($url, $info['akaunting']);
// Then modules
foreach ($modules as $module) {
@ -78,12 +77,12 @@ class Versions
$url = 'apps/' . $alias . '/version/' . $version . '/' . $info['akaunting'];
$data[$alias] = static::getLatestVersion($url, $version);
$versions[$alias] = static::getLatestVersion($url, $version);
}
Cache::put('versions', $data, Date::now()->addHour(6));
Cache::put('versions', $versions, Date::now()->addHour(6));
return $data;
return $versions;
}
public static function getLatestVersion($url, $latest)