File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 66
77use App \Models \Site ;
88use App \RemoteSite \Connection ;
9+ use App \TUF \TufFetcher ;
910use Carbon \Carbon ;
1011use Illuminate \Contracts \Queue \ShouldQueue ;
1112use Illuminate \Foundation \Queue \Queueable ;
13+ use Illuminate \Support \Str ;
1214
1315class CheckSiteHealth implements ShouldQueue
1416{
@@ -39,5 +41,19 @@ public function handle(): void
3941 // @phpstan-ignore-next-line
4042 $ this ->site ->last_seen = Carbon::now ();
4143 $ this ->site ->save ();
44+
45+ // Check if a newer Joomla version for that site is available
46+ $ latestVersion = (new TufFetcher ())->getLatestVersionForBranch ((int ) $ this ->site ->cms_version [0 ]);
47+
48+ // Available version is not newer, exit
49+ if (!version_compare ($ latestVersion , $ this ->site ->cms_version , "> " )) {
50+ return ;
51+ }
52+
53+ // We have a newer version, queue Update
54+ UpdateSite::dispatch (
55+ $ this ->site ,
56+ $ latestVersion
57+ );
4258 }
4359}
Original file line number Diff line number Diff line change @@ -17,7 +17,10 @@ public function __construct()
1717 $ this ->updateStorage = App::make (StorageInterface::class);
1818 }
1919
20- public function getReleases (): mixed
20+ /**
21+ * @return Collection
22+ */
23+ public function getReleases (): Collection
2124 {
2225 // Cache response to avoid to make constant calls on the fly
2326 return Cache::remember (
@@ -43,4 +46,13 @@ function () {
4346 }
4447 );
4548 }
49+
50+ public function getLatestVersionForBranch (int $ branch ): string
51+ {
52+ return $ this ->getReleases ()->filter (function ($ release ) {
53+ return $ release ["stability " ] === "Stable " ;
54+ })->sort (function ($ releaseA , $ releaseB ) {
55+ return version_compare ($ releaseA ["version " ], $ releaseB ["version " ], '< ' );
56+ })->pluck ('version ' )->first ();
57+ }
4658}
You can’t perform that action at this time.
0 commit comments