Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit 4bd9790

Browse files
committed
Merge branch 'develop'
2 parents b5246b1 + 6f2e644 commit 4bd9790

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
"illuminate/support": "~5",
1717
"cartalyst/sentinel": "2.0.*",
1818
"cyrildewit/eloquent-viewable": "^3.0",
19+
"composer/semver": "^1.4",
1920
"danielme85/laravel-cconverter": "^0.2.1",
2021
"ext-zip": "*",
2122
"ext-json": "*",
2223
"intervention/image": "^2.4",
2324
"intervention/imagecache": "^2.3",
25+
"knplabs/packagist-api": "^1.5",
2426
"laravel/scout": "^7.1",
2527
"league/fractal": "^0.17.0",
2628
"mcamara/laravel-localization": "^1.3",

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
## Introduction
1010

1111
Shopper is an Admin Management build for Laravel 5.6+ (Not yet compatible with Laravel 5.8) which includes all the necessary for your online market application. This project is inspired by [Orchid/Platform](https://github.com/orchidsoftware/platform).
12-
This package is still in development.
12+
Please note that this package is still under active development.
13+
14+
![Shopper Screenshot](https://pix.watch/kvtzzS/NK1CPv.png)
1315

1416
![Shopper Screenshot](https://pix.watch/kvtzzS/NK1CPv.png)
1517

resources/views/pages/dashboard/index.blade.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,25 @@
4545
</li>
4646
<li>
4747
<img src="{{ asset('/shopper/img/logo.svg') }}">
48-
<span>{{ $shopper }}</span>
48+
<span>
49+
{{ $currentVersion }}
50+
@if($updateAvailable)
51+
<i class="fas fa-exclamation-circle text-warning"></i>
52+
@else
53+
<i class="fas fa-check-circle text-success"></i>
54+
@endif
55+
</span>
56+
</li>
57+
<li>
58+
@if($updateAvailable)
59+
<span class="text-warning">
60+
{{ _('A new version of Shopper is available') }} - v{{ $latestVersion }}
61+
</span>
62+
<i class="fas fa-exclamation-circle text-warning"></i>
63+
@else
64+
<span>{{ __('You are up to date with Shopper') }}</span>
65+
<i class="fas fa-check-circle text-success"></i>
66+
@endif
4967
</li>
5068
</ul>
5169
</div>

src/Core/Version.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Mckenziearts\Shopper\Core;
4+
5+
use Composer\Semver\Semver;
6+
use Composer\Semver\Comparator;
7+
use Composer\Semver\VersionParser;
8+
9+
class Version extends Semver
10+
{
11+
/**
12+
* Normalize the version number.
13+
*
14+
* @param string $version
15+
*
16+
* @return string
17+
*/
18+
public static function normalize($version)
19+
{
20+
$version = preg_replace('/^(v|\^|~)/', '', $version);
21+
if (preg_match('/^\d\.\d$/', $version)) {
22+
$version .= '.0';
23+
}
24+
25+
return $version;
26+
}
27+
/**
28+
* Get the last version number from a list of versions.
29+
*
30+
* @param array $versions
31+
*
32+
* @return string
33+
*/
34+
public static function latest(array $versions)
35+
{
36+
// Normalize version numbers.
37+
$versions = array_map(function ($version) {
38+
return static::normalize($version);
39+
}, $versions);
40+
// Get the highest version number.
41+
$latest = array_reduce($versions, function ($carry, $item) {
42+
// Skip unstable versions.
43+
if (VersionParser::parseStability($item) !== 'stable') {
44+
return $carry;
45+
}
46+
return Comparator::greaterThan($carry, $item) ? $carry : $item;
47+
}, '0.0.0');
48+
49+
return $latest;
50+
}
51+
}

src/Http/Controllers/Backend/DashboardController.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Algolia\ScoutExtended\Facades\Algolia;
66
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
77
use Illuminate\Support\Facades\DB;
8+
use Mckenziearts\Shopper\Core\Version;
89
use Mckenziearts\Shopper\Http\Controllers\Controller;
910
use Mckenziearts\Shopper\Plugins\Catalogue\Models\Brand;
1011
use Mckenziearts\Shopper\Plugins\Catalogue\Models\Category;
@@ -14,6 +15,7 @@
1415
use Mckenziearts\Shopper\Plugins\Users\Models\User;
1516
use Mckenziearts\Shopper\Plugins\Users\Repositories\UserRepository;
1617
use Mckenziearts\Shopper\Shopper;
18+
use Packagist\Api\Client;
1719
use Spatie\SslCertificate\SslCertificate;
1820

1921
class DashboardController extends Controller
@@ -53,11 +55,20 @@ public function dashboard()
5355
$os = php_uname('s');
5456
$laravel = app()->version();
5557
$database = $this->getDatabase();
56-
$shopper = Shopper::version();
5758
$php = phpversion();
5859

5960
$algolia = $this->algoliaIndices();
6061

62+
$client = new Client();
63+
$package = $client->get('mckenziearts/shopper');
64+
$versions = array_map(function ($version) {
65+
return $version->getVersion();
66+
}, $package->getVersions());
67+
68+
$currentVersion = Shopper::version();
69+
$latestVersion = Version::latest($versions);
70+
$updateAvailable = version_compare($currentVersion, $latestVersion, '<');
71+
6172
try {
6273
$certificate = SslCertificate::createForHostName(request()->getHost());
6374
$sslCertificate = [
@@ -79,10 +90,12 @@ public function dashboard()
7990
'os',
8091
'laravel',
8192
'database',
82-
'shopper',
8393
'php',
8494
'sslCertificate',
85-
'algolia'
95+
'algolia',
96+
'currentVersion',
97+
'latestVersion',
98+
'updateAvailable'
8699
)
87100
);
88101
}

0 commit comments

Comments
 (0)