diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index 4fbe7170e3..8ea439baf5 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -191,6 +191,18 @@ public static function health() { 'key' => 'uptodate' ); + if (config::byKey('core::repo::provider') == 'default') { + $branch = config::byKey('core::branch', 'core', 'master'); + $state = update::isCoreBranchValid(); + $return[] = array( + 'name' => __('Branche du core', __FILE__), + 'state' => $state, + 'result' => ($state) ? $branch : $branch . ' (' . __('introuvable', __FILE__) . ')', + 'comment' => ($state) ? '' : update::getCoreBranchInvalidMessage(), + 'key' => 'coreBranch' + ); + } + $state = (config::byKey('enableCron', 'core', 1, true) != 0) ? true : false; $return[] = array( 'name' => __('Cron actif', __FILE__), diff --git a/core/class/update.class.php b/core/class/update.class.php index ffbde4fb6f..cf182fcb88 100644 --- a/core/class/update.class.php +++ b/core/class/update.class.php @@ -493,6 +493,76 @@ public static function getLastAvailableVersion() { return null; } + /** + * Get the list of branches and tags available for the core on the default repository. + * The result is cached for 24h (key core::branch::default::list). + * + * @param bool $_refresh Force a refresh of the cache + * @return array Array containing the 'branchs' and 'tags' keys + */ + public static function getCoreBranchList(bool $_refresh = false) { + $lists = ($_refresh) ? array() : cache::byKey('core::branch::default::list')->getValue(array()); + if (!isset($lists['branchs']) || !is_array($lists['branchs'])) { + $request_http = new com_http('https://api.github.com/repos/jeedom/core/branches'); + $request_http->setHeader(array('User-agent: jeedom')); + try { + $lists['branchs'] = json_decode($request_http->exec(10, 1), true); + } catch (\Exception $e) { + } + cache::set('core::branch::default::list', $lists, 86400); + } + if (!isset($lists['tags']) || !is_array($lists['tags'])) { + $request_http = new com_http('https://api.github.com/repos/jeedom/core/tags'); + $request_http->setHeader(array('User-agent: jeedom')); + try { + $lists['tags'] = json_decode($request_http->exec(10, 1), true); + } catch (\Exception $e) { + } + cache::set('core::branch::default::list', $lists, 86400); + } + return $lists; + } + + /** + * Check that the branch (or tag) configured for the core still exists on the repository. + * Returns true when validity cannot be determined (custom provider or remote list + * unavailable) to avoid false positives. + * + * @return bool + */ + public static function isCoreBranchValid() { + if (config::byKey('core::repo::provider') != 'default') { + return true; + } + $branch = config::byKey('core::branch', 'core', 'master'); + $lists = self::getCoreBranchList(); + if (strpos($branch, 'tag::') === 0) { + $name = substr($branch, strlen('tag::')); + $remoteList = (isset($lists['tags']) && is_array($lists['tags'])) ? $lists['tags'] : array(); + } else { + $name = $branch; + $remoteList = (isset($lists['branchs']) && is_array($lists['branchs'])) ? $lists['branchs'] : array(); + } + if (count($remoteList) == 0) { + return true; + } + foreach ($remoteList as $item) { + if (is_array($item) && isset($item['name']) && $item['name'] == $name) { + return true; + } + } + return false; + } + + /** + * User-facing message shown when the configured core branch no longer exists on the repository. + * + * @return string + */ + public static function getCoreBranchInvalidMessage() { + return __("La branche configurée pour le core n'existe plus sur le dépôt. Allez dans Réglages -> Système -> Mises à jour/Market pour sélectionner une branche valide.", __FILE__); + } + public function checkUpdate() { if ($this->getConfiguration('doNotUpdate') == 1 && $this->getType() != 'core') { log::add(__CLASS__, 'alert', __('Vérification des mises à jour, mise à jour et réinstallation désactivées sur', __FILE__) . ' ' . $this->getLogicalId()); @@ -503,6 +573,11 @@ public function checkUpdate() { return; } if (config::byKey('core::repo::provider') == 'default') { + if (self::isCoreBranchValid()) { + message::removeAll('core', 'core::branch::invalid'); + } else { + message::add('core', self::getCoreBranchInvalidMessage(), '', 'core::branch::invalid'); + } $this->setRemoteVersion(self::getLastAvailableVersion()); } else { $class = 'repo_' . config::byKey('core::repo::provider'); diff --git a/desktop/php/administration.php b/desktop/php/administration.php index f226834255..7b16039abb 100644 --- a/desktop/php/administration.php +++ b/desktop/php/administration.php @@ -1822,25 +1822,7 @@ getValue(array()); - if (!isset($lists['branchs']) || !is_array($lists['branchs'])) { - $request_http = new com_http('https://api.github.com/repos/jeedom/core/branches'); - $request_http->setHeader(array('User-agent: jeedom')); - try { - $lists['branchs'] = json_decode($request_http->exec(10, 1), true); - } catch (\Exception $e) { - } - cache::set('core::branch::default::list', $lists, 86400); - } - if (!isset($lists['tags']) || !is_array($lists['tags'])) { - $request_http = new com_http('https://api.github.com/repos/jeedom/core/tags'); - $request_http->setHeader(array('User-agent: jeedom')); - try { - $lists['tags'] = json_decode($request_http->exec(10, 1), true); - } catch (\Exception $e) { - } - cache::set('core::branch::default::list', $lists, 86400); - } + $lists = update::getCoreBranchList(); if (isset($lists['branchs']) && is_array($lists['branchs'])) { echo ''; foreach ($lists['branchs'] as $branch) {