Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/class/jeedom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__),
Expand Down
75 changes: 75 additions & 0 deletions core/class/update.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commentaire à mettre en anglais + respect du format PHPDoc

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
*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commentaire à mettre en anglais + respect du format PHPDoc

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());
Expand All @@ -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');
Expand Down
20 changes: 1 addition & 19 deletions desktop/php/administration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1822,25 +1822,7 @@
</optgroup>
<?php
if (config::byKey('core::repo::provider') == 'default') {
$lists = 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);
}
$lists = update::getCoreBranchList();
if (isset($lists['branchs']) && is_array($lists['branchs'])) {
echo '<optgroup label="{{Branches (Pas de support)}}">';
foreach ($lists['branchs'] as $branch) {
Expand Down
Loading