Update center added alert message
This commit is contained in:
@ -125,6 +125,6 @@ class DownloadModule extends Command
|
||||
$version = Versions::getLatestVersion($url, $current);
|
||||
}
|
||||
|
||||
return $version;
|
||||
return $version?->latest;
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ class Update extends Command
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
return ($this->argument('new') == 'latest') ? Versions::latest($this->alias) : $this->argument('new');
|
||||
return ($this->argument('new') == 'latest') ? Versions::latest($this->alias)?->latest : $this->argument('new');
|
||||
}
|
||||
|
||||
public function getOldVersion()
|
||||
|
@ -48,7 +48,9 @@ class Updates extends Controller
|
||||
$m->name = $row->getName();
|
||||
$m->alias = $row->get('alias');
|
||||
$m->installed = $row->get('version');
|
||||
$m->latest = $updates[$alias];
|
||||
$m->latest = $updates[$alias]->latest;
|
||||
$m->errors = $updates[$alias]->errors;
|
||||
$m->message = $updates[$alias]->message;
|
||||
|
||||
$modules[] = $m;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ class ShowInNotifications
|
||||
$new->notifiable_type = "users";
|
||||
$new->notifiable_id = user()->id;
|
||||
$new->data = [
|
||||
'title' => $name . ' (v' . $update . ')',
|
||||
'title' => $name . ' (v' . $update?->latest . ')',
|
||||
'description' => trans('install.update.' . $prefix, ['module' => $name, 'url' => route('updates.index')]),
|
||||
];
|
||||
$new->created_at = \Carbon\Carbon::now();
|
||||
|
@ -44,7 +44,7 @@ class UpdateExtraModules
|
||||
}
|
||||
|
||||
$installed_version = $extra_module->get('version');
|
||||
$latest_version = Versions::latest($alias);
|
||||
$latest_version = Versions::latest($alias)?->latest;
|
||||
|
||||
// Skip if no update available
|
||||
if (version_compare($installed_version, $latest_version, '>=')) {
|
||||
|
@ -55,15 +55,24 @@ trait SiteApi
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function getResponseData($method, $path, $data = [], $status_code = 200)
|
||||
public static function getResponseBody($method, $path, $data = [], $status_code = 200)
|
||||
{
|
||||
if (!$response = static::getResponse($method, $path, $data, $status_code)) {
|
||||
if (! $response = static::getResponse($method, $path, $data, $status_code)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$body = json_decode($response->getBody());
|
||||
|
||||
if (!is_object($body)) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
public static function getResponseData($method, $path, $data = [], $status_code = 200)
|
||||
{
|
||||
if (! $body = static::getResponseBody($method, $path, $data, $status_code)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! is_object($body)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
@ -55,11 +55,11 @@ class Versions
|
||||
{
|
||||
$versions = static::all($alias);
|
||||
|
||||
if (empty($versions[$alias]) || empty($versions[$alias]->data)) {
|
||||
if (empty($versions[$alias])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $versions[$alias]->data->latest;
|
||||
return $versions[$alias];
|
||||
}
|
||||
|
||||
public static function all($modules = null)
|
||||
@ -67,7 +67,7 @@ class Versions
|
||||
// Get data from cache
|
||||
$versions = Cache::get('versions');
|
||||
|
||||
if (!empty($versions)) {
|
||||
if (! empty($versions)) {
|
||||
return $versions;
|
||||
}
|
||||
|
||||
@ -78,17 +78,33 @@ class Versions
|
||||
// Check core first
|
||||
$url = 'core/version/' . $info['akaunting'] . '/' . $info['php'] . '/' . $info['mysql'] . '/' . $info['companies'];
|
||||
|
||||
$versions['core'] = static::getLatestVersion($url, $info['akaunting']);
|
||||
|
||||
# Installed modules start
|
||||
$modules = Arr::wrap($modules);
|
||||
|
||||
$installed_modules = [];
|
||||
$module_version = '?modules=';
|
||||
|
||||
foreach ($modules as $module) {
|
||||
$alias = $module->get('alias');
|
||||
$version = $module->get('version');
|
||||
|
||||
$installed_modules[] = $alias;
|
||||
}
|
||||
|
||||
$module_version .= implode(',', $installed_modules);
|
||||
|
||||
$url .= $module_version;
|
||||
# Installed modules end
|
||||
|
||||
$versions['core'] = static::getLatestVersion($url, $info['akaunting']);
|
||||
|
||||
// Then modules
|
||||
foreach ($modules as $module) {
|
||||
if (is_string($module)) {
|
||||
$module = module($module);
|
||||
}
|
||||
|
||||
if (!$module instanceof \Akaunting\Module\Module) {
|
||||
if (! $module instanceof \Akaunting\Module\Module) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -107,15 +123,27 @@ class Versions
|
||||
|
||||
public static function getLatestVersion($url, $latest)
|
||||
{
|
||||
if (!$data = static::getResponseData('GET', $url, ['timeout' => 10])) {
|
||||
return $latest;
|
||||
$version = new \stdClass();
|
||||
|
||||
$version->can_update = true;
|
||||
$version->latest = $latest;
|
||||
$version->errors = false;
|
||||
$version->message = '';
|
||||
|
||||
if (! $body = static::getResponseBody('GET', $url, ['timeout' => 10])) {
|
||||
return $version;
|
||||
}
|
||||
|
||||
if (!is_object($data)) {
|
||||
return $latest;
|
||||
if (! is_object($body)) {
|
||||
return $version;
|
||||
}
|
||||
|
||||
return $data->latest;
|
||||
$version->can_update = $body->success;
|
||||
$version->latest = $body->data->latest;
|
||||
$version->errors = $body->errors;
|
||||
$version->message = $body->message;
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
public static function getUpdates()
|
||||
@ -123,7 +151,7 @@ class Versions
|
||||
// Get data from cache
|
||||
$updates = Cache::get('updates');
|
||||
|
||||
if (!empty($updates)) {
|
||||
if (! empty($updates)) {
|
||||
return $updates;
|
||||
}
|
||||
|
||||
@ -146,7 +174,7 @@ class Versions
|
||||
$installed_version = $module->get('version');
|
||||
}
|
||||
|
||||
if (version_compare($installed_version, $latest_version, '>=')) {
|
||||
if (version_compare($installed_version, $latest_version->latest, '>=')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
73
app/View/Components/UpdateAlert.php
Normal file
73
app/View/Components/UpdateAlert.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use App\Abstracts\View\Component;
|
||||
use App\Utilities\Versions;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class UpdateAlert extends Component
|
||||
{
|
||||
public $alerts;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $alerts = [])
|
||||
{
|
||||
$this->alerts = $this->getAlerts($alerts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.update-alert');
|
||||
}
|
||||
|
||||
public function getAlerts()
|
||||
{
|
||||
$alerts = [];
|
||||
|
||||
$updates = Versions::getUpdates();
|
||||
|
||||
if (! $updates) {
|
||||
return $alerts;
|
||||
}
|
||||
|
||||
foreach ($updates as $alias => $update) {
|
||||
if (! $update->errors) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($update->errors as $key => $error) {
|
||||
switch ($key) {
|
||||
case 'core':
|
||||
$type = 'danger';
|
||||
break;
|
||||
case 'expires':
|
||||
case 'compatible':
|
||||
$type = 'warning';
|
||||
break;
|
||||
default:
|
||||
$type = 'danger';
|
||||
}
|
||||
|
||||
if (is_object($error) || is_array($error)) {
|
||||
foreach ($error as $message) {
|
||||
$alerts[$type][] = $message;
|
||||
}
|
||||
} else {
|
||||
$alerts[$type][] = $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $alerts;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user