Skip to content

Commit

Permalink
Merge pull request #52 from KIMB-technologies/update-banner
Browse files Browse the repository at this point in the history
Update Banner on Update
  • Loading branch information
kimbtech authored Feb 27, 2024
2 parents ba1dcc6 + 322e97b commit 6d61f33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
2.8.3
2.8.4
2.8
2
33 changes: 21 additions & 12 deletions php/classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Config {
/**
* The system's version.
*/
const VERSION = 'v2.8.3';
const VERSION = 'v2.8.4';

/**
* The real domain which should be used.
Expand Down Expand Up @@ -226,7 +226,14 @@ public static function updateAvailable() : bool {
self::$redisUpdateStatus = new Cache( 'update_status' );
}

if(!self::$redisUpdateStatus->keyExists('update_available')){
// remove values of "old" update indicator
if(self::$redisUpdateStatus->keyExists('update_available')){
self::$redisUpdateStatus->remove('update_available');
self::$redisUpdateStatus->remove('latest_version');
}

// check for new information from GitHub API
if(!self::$redisUpdateStatus->keyExists('latest_version')){
$infos = json_decode(file_get_contents(
'https://api.github.com/repos/KIMB-technologies/Radio-API/releases/latest',
false,
Expand All @@ -236,23 +243,25 @@ public static function updateAvailable() : bool {
'timeout' => 4
)))
), true);

if(is_null($infos)){
// error checking latest version
return false;
}
else{
self::$redisUpdateStatus->set('latest_version', $infos["tag_name"]);
self::$redisUpdateStatus->set('last_check', date('d.m.Y H:i:s'));
else{
self::$redisUpdateStatus->set(
'latest_version',
$infos["tag_name"],
60*60*24*3 // check every 3 days
);
self::$redisUpdateStatus->set(
'last_check',
date('d.m.Y H:i:s')
);
}

self::$redisUpdateStatus->set(
'update_available',
version_compare(self::VERSION, self::$redisUpdateStatus->get('latest_version'), '<'),
60*60*24*3 // check every 3 days
);
}

return self::$redisUpdateStatus->get('update_available');
return version_compare(self::VERSION, self::$redisUpdateStatus->get('latest_version'), '<');
}

public static function parseAllowedDomain(bool $output = false) : void {
Expand Down

0 comments on commit 6d61f33

Please sign in to comment.