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() public static function all()
{ {
// Get data from cache // Get data from cache
$data = Cache::get('updates'); $updates = Cache::get('updates');
if (!empty($data)) { if (!empty($updates)) {
return $data; return $updates;
} }
// No data in cache, grab them from remote $updates = [];
$data = array();
$modules = module()->all(); $modules = module()->all();
$versions = Versions::latest($modules); $versions = Versions::latest($modules);
foreach ($versions as $alias => $version) { foreach ($versions as $alias => $latest_version) {
// Modules come as array $installed_version = ($alias == 'core') ? version('short') : module($alias)->get('version');
if ($alias == 'core') {
if (version_compare(version('short'), $version, '<')) {
$data['core'] = $version;
}
} else {
$module = module($alias);
// Up-to-date if (version_compare($installed_version, $latest_version, '>=')) {
if (version_compare($module->get('version'), $version, '>=')) { continue;
continue;
}
$data[$alias] = $version;
} }
$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; return $output;
} }
public static function latest($modules = array()) public static function latest($modules = [])
{ {
// Get data from cache // Get data from cache
$data = Cache::get('versions'); $versions = Cache::get('versions');
if (!empty($data)) { if (!empty($versions)) {
return $data; return $versions;
} }
$info = Info::all(); $info = Info::all();
// No data in cache, grab them from remote $versions = [];
$data = [];
// Check core first // Check core first
$url = 'core/version/' . $info['akaunting'] . '/' . $info['php'] . '/' . $info['mysql'] . '/' . $info['companies']; $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 // Then modules
foreach ($modules as $module) { foreach ($modules as $module) {
@ -78,12 +77,12 @@ class Versions
$url = 'apps/' . $alias . '/version/' . $version . '/' . $info['akaunting']; $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) public static function getLatestVersion($url, $latest)