From e32977ffff167001f92430d7d63d2c86773cd075 Mon Sep 17 00:00:00 2001 From: "Ing. Petr Suchy" Date: Fri, 7 Feb 2020 07:43:16 +0100 Subject: [PATCH 1/2] *fix - check and update latest version --- src/includes/functions.inc.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 3036c8fa..226b620f 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -555,22 +555,32 @@ namespace { // update last check date psm_update_conf('last_update_check', time()); $latest = psm_curl_get(PSM_UPDATE_URL); + if ($latest['info'] === false || (int)$latest['info']['http_code'] >= 300) { + // error + return false; + } // extract latest version from Github. - preg_match('/"tag_name":"[v](([\d][.][\d][.][\d])(-?\w*))"/', $latest, $latest); - // add latest version to database - if (!empty($latest) && strlen($latest[2]) < 15) { - psm_update_conf('version_update_check', $latest[2]); + $githubInfo = json_decode($latest['exec']); + if (property_exists($githubInfo, 'tag_name') === false) { + // version not found + return false; + } + $tagName = $githubInfo->tag_name; + $latestVersion = str_replace('v', '', $tagName); + // check from old version ... maybe has reason but I don't think so ... + if (empty($latestVersion) === true || strlen($latestVersion) >= 15) { + // weird version + return false; + } + // add latest version to database + psm_update_conf('version_update_check', $latestVersion); } else { - $latest[2] = psm_get_conf('version_update_check'); + $latestVersion = psm_get_conf('version_update_check'); } - if (!empty($latest)) { - $current = psm_get_conf('version'); - return version_compare($latest[2], $current, '>'); - } else { - return false; - } + $current = psm_get_conf('version'); + return version_compare($latestVersion, $current, '>'); } /** From 51dbbf9510b64dab76fcd9b1ae80872d40c81aef Mon Sep 17 00:00:00 2001 From: TimZ99 Date: Sat, 8 Feb 2020 20:57:53 +0100 Subject: [PATCH 2/2] Refactor --- src/includes/functions.inc.php | 39 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 226b620f..f054ff9f 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -555,28 +555,27 @@ namespace { // update last check date psm_update_conf('last_update_check', time()); $latest = psm_curl_get(PSM_UPDATE_URL); - if ($latest['info'] === false || (int)$latest['info']['http_code'] >= 300) { - // error - return false; - } - // extract latest version from Github. - $githubInfo = json_decode($latest['exec']); - if (property_exists($githubInfo, 'tag_name') === false) { - // version not found - return false; - } - $tagName = $githubInfo->tag_name; - $latestVersion = str_replace('v', '', $tagName); - // check from old version ... maybe has reason but I don't think so ... - if (empty($latestVersion) === true || strlen($latestVersion) >= 15) { - // weird version - return false; - + if ($latest['info'] === false || (int)$latest['info']['http_code'] >= 300) { + // error + return false; } - // add latest version to database - psm_update_conf('version_update_check', $latestVersion); + // extract latest version from Github. + $githubInfo = json_decode($latest['exec']); + if (property_exists($githubInfo, 'tag_name') === false) { + // version not found + return false; + } + $tagName = $githubInfo->tag_name; + $latestVersion = str_replace('v', '', $tagName); + // check from old version ... maybe has reason but I don't think so ... + if (empty($latestVersion) === true || strlen($latestVersion) >= 15) { + // weird version + return false; + } + // add latest version to database + psm_update_conf('version_update_check', $latestVersion); } else { - $latestVersion = psm_get_conf('version_update_check'); + $latestVersion = psm_get_conf('version_update_check'); } $current = psm_get_conf('version');