Update center added alert message
This commit is contained in:
parent
3400f006af
commit
8fbee840ea
@ -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;
|
||||
}
|
||||
}
|
5
resources/views/components/update-alert.blade.php
Normal file
5
resources/views/components/update-alert.blade.php
Normal file
@ -0,0 +1,5 @@
|
||||
@foreach ($alerts as $type => $messages)
|
||||
@foreach ($messages as $message)
|
||||
<x-alert :type="$type" :message="$message" />
|
||||
@endforeach
|
||||
@endforeach
|
@ -10,6 +10,8 @@
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="content">
|
||||
<x-update-alert />
|
||||
|
||||
<div class="my-10">
|
||||
<div class="flex items-center">
|
||||
<div class="relative px-4 text-sm text-center pb-2 text-purple font-medium border-purple transition-all after:absolute after:w-full after:h-0.5 after:left-0 after:right-0 after:bottom-0 after:bg-purple after:rounded-tl-md after:rounded-tr-md">
|
||||
@ -31,9 +33,17 @@
|
||||
|
||||
<x-table.td kind="right" class="w-6/12" kind="cursor-none">
|
||||
<x-slot name="first" class="flex justify-end" override="class">
|
||||
<x-link href="{{ route('updates.run', ['alias' => 'core', 'version' => $core]) }}" class="px-3 py-1.5 rounded-xl text-sm font-medium leading-6 ltr:mr-2 rtl:ml-2 bg-green text-white hover:bg-green-700 disabled:bg-green-100" override="class">
|
||||
{{ trans('updates.update', ['version' => $core]) }}
|
||||
</x-link>
|
||||
@if (! $core->errors)
|
||||
<x-link href="{{ route('updates.run', ['alias' => 'core', 'version' => $core->latest]) }}" class="px-3 py-1.5 rounded-xl text-sm font-medium leading-6 ltr:mr-2 rtl:ml-2 bg-green text-white hover:bg-green-700 disabled:bg-green-100" override="class">
|
||||
{{ trans('updates.update', ['version' => $core->latest]) }}
|
||||
</x-link>
|
||||
@else
|
||||
<x-tooltip id="tooltip-core-button" placement="top" :message="$core->message">
|
||||
<x-button class="px-3 py-1.5 rounded-xl text-sm font-medium leading-6 ltr:mr-2 rtl:ml-2 text-white bg-green-300 cursor-default" override="class">
|
||||
{{ trans('updates.update', ['version' => $core->latest]) }}
|
||||
</x-button>
|
||||
</x-tooltip>
|
||||
@endif
|
||||
|
||||
<x-button @click="onChangelog">
|
||||
{{ trans('updates.changelog') }}
|
||||
@ -76,7 +86,7 @@
|
||||
|
||||
<x-table.tbody>
|
||||
@if ($modules)
|
||||
@foreach($modules as $module)
|
||||
@foreach ($modules as $module)
|
||||
<x-table.tr>
|
||||
<x-table.td class="w-3/12" kind="cursor-none">
|
||||
{{ $module->name }}
|
||||
@ -91,9 +101,17 @@
|
||||
</x-table.td>
|
||||
|
||||
<x-table.td class="w-3/12" kind="right">
|
||||
<x-link href="{{ route('updates.run', ['alias' => $module->alias, 'version' => $module->latest]) }}" kind="primary">
|
||||
{{ trans_choice('general.updates', 1) }}
|
||||
</x-link>
|
||||
@if (empty($module->errors))
|
||||
<x-link href="{{ route('updates.run', ['alias' => $module->alias, 'version' => $module->latest]) }}" kind="primary">
|
||||
{{ trans_choice('general.updates', 1) }}
|
||||
</x-link>
|
||||
@else
|
||||
<x-tooltip id="tooltip-modules-{{ $module->alias }}" placement="top" :message="$module->message">
|
||||
<x-button class="px-3 py-1.5 rounded-xl text-sm font-medium leading-6 text-white bg-green-300 cursor-default" override="class">
|
||||
{{ trans_choice('general.updates', 1) }}
|
||||
</x-button>
|
||||
</x-tooltip>
|
||||
@endif
|
||||
</x-table.td>
|
||||
</x-table.tr>
|
||||
@endforeach
|
||||
|
Loading…
x
Reference in New Issue
Block a user