diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php index 717a038f7..b98a746f9 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php @@ -372,7 +372,6 @@ protected function setDefaultValues() $this->setEmpty('general.tags_separator', ' '); $this->setEmpty('updates.check_updates', true); - $this->setEmpty('updates.check_updates_branch', 'latest'); $this->setEmpty('updates.check_updates_interval', 86400); $this->setEmpty('feed.rss_permalinks', true); diff --git a/application/front/controller/admin/ServerController.php b/application/front/controller/admin/ServerController.php index 9be5ea772..8978b9764 100644 --- a/application/front/controller/admin/ServerController.php +++ b/application/front/controller/admin/ServerController.php @@ -36,7 +36,7 @@ public function index(Request $request, Response $response): Response } $currentVersion = ApplicationUtils::getVersion('./shaarli_version.php'); - $currentVersion = $currentVersion === 'dev' ? $currentVersion : 'v' . $currentVersion; + $currentVersion = ApplicationUtils::isDevVersion($currentVersion) ? $currentVersion : 'v' . $currentVersion; $phpEol = new \DateTimeImmutable(ApplicationUtils::getPhpEol(PHP_VERSION)); $permissions = array_merge( diff --git a/application/helper/ApplicationUtils.php b/application/helper/ApplicationUtils.php index d875f2b8c..6d13fa19f 100644 --- a/application/helper/ApplicationUtils.php +++ b/application/helper/ApplicationUtils.php @@ -19,7 +19,7 @@ class ApplicationUtils public static $GITHUB_URL = 'https://github.com/shaarli/Shaarli'; public static $GIT_RAW_URL = 'https://raw.githubusercontent.com/shaarli/Shaarli'; - public static $GIT_BRANCHES = ['latest', 'stable']; + public static $RELEASE_BRANCH = 'release'; private static $VERSION_START_TAG = ''; @@ -89,7 +89,6 @@ public static function getVersion($remote, $timeout = 2) * @param int $checkInterval the minimum interval between update checks (in seconds * @param bool $enableCheck whether to check for new versions * @param bool $isLoggedIn whether the user is logged in - * @param string $branch check update for the given branch * * @throws Exception an invalid branch has been set for update checks * @@ -100,13 +99,12 @@ public static function checkUpdate( $updateFile, $checkInterval, $enableCheck, - $isLoggedIn, - $branch = 'stable' + $isLoggedIn ) { // Do not check versions for visitors // Do not check if the user doesn't want to // Do not check with dev version - if (!$isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') { + if (!$isLoggedIn || empty($enableCheck) || self::isDevVersion($currentVersion)) { return false; } @@ -120,16 +118,10 @@ public static function checkUpdate( return false; } - if (!in_array($branch, self::$GIT_BRANCHES)) { - throw new Exception( - 'Invalid branch selected for updates: "' . $branch . '"' - ); - } - // Late Static Binding allows overriding within tests // See http://php.net/manual/en/language.oop5.late-static-bindings.php $latestVersion = static::getVersion( - self::$GIT_RAW_URL . '/' . $branch . '/' . self::$VERSION_FILE + self::$GIT_RAW_URL . '/' . self::$RELEASE_BRANCH . '/' . self::$VERSION_FILE ); if (!$latestVersion) { @@ -189,11 +181,11 @@ public static function checkResourcePermissions(ConfigManager $conf, bool $minim // Check script and template directories are readable foreach ( [ - 'application', - 'inc', - 'plugins', - $rainTplDir, - $rainTplDir . '/' . $conf->get('resource.theme'), + 'application', + 'inc', + 'plugins', + $rainTplDir, + $rainTplDir . '/' . $conf->get('resource.theme'), ] as $path ) { if (!is_readable(realpath($path))) { @@ -208,10 +200,10 @@ public static function checkResourcePermissions(ConfigManager $conf, bool $minim ]; } else { $folders = [ - $conf->get('resource.thumbnails_cache'), - $conf->get('resource.data_dir'), - $conf->get('resource.page_cache'), - $conf->get('resource.raintpl_tmp'), + $conf->get('resource.thumbnails_cache'), + $conf->get('resource.data_dir'), + $conf->get('resource.page_cache'), + $conf->get('resource.raintpl_tmp'), ]; } @@ -231,12 +223,12 @@ public static function checkResourcePermissions(ConfigManager $conf, bool $minim // Check configuration files are readable and writable foreach ( [ - $conf->getConfigFileExt(), - $conf->get('resource.datastore'), - $conf->get('resource.ban_file'), - $conf->get('resource.log'), - $conf->get('resource.update_check'), - ] as $path + $conf->getConfigFileExt(), + $conf->get('resource.datastore'), + $conf->get('resource.ban_file'), + $conf->get('resource.log'), + $conf->get('resource.update_check'), + ] as $path ) { if (!is_string($path) || !is_file(realpath($path))) { # the file may not exist yet @@ -334,4 +326,11 @@ public static function getPhpEol(string $fullVersion): string '8.2' => '2025-12-08', ][$matches[1]] ?? (new \DateTime('+2 year'))->format('Y-m-d'); } + + public static function isDevVersion(string $version): bool + { + return strpos($version, 'dev') !== false + || preg_match('/[a-f0-9]{7}/', $version) === 1 + ; + } } diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index bf0ae3263..3f9e550c5 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -103,8 +103,7 @@ private function initialize() $this->conf->get('resource.update_check'), $this->conf->get('updates.check_updates_interval'), $this->conf->get('updates.check_updates'), - $this->isLoggedIn, - $this->conf->get('updates.check_updates_branch') + $this->isLoggedIn ); $this->tpl->assign('newVersion', escape($version)); $this->tpl->assign('versionError', ''); diff --git a/application/updater/Updater.php b/application/updater/Updater.php index 11b6c0514..a9ea65621 100644 --- a/application/updater/Updater.php +++ b/application/updater/Updater.php @@ -172,6 +172,15 @@ public function updateMethodMigrateExistingNotesUrl(): bool return true; } + public function updateMethodRemoveSettingRemoteBranch(): bool + { + if ($this->conf->exists('updates.check_updates_branch')) { + $this->conf->remove('updates.check_updates_branch', true, true); + } + + return true; + } + public function setBasePath(string $basePath): self { $this->basePath = $basePath; diff --git a/doc/md/Shaarli-configuration.md b/doc/md/Shaarli-configuration.md index a7cfb2181..89206daf4 100644 --- a/doc/md/Shaarli-configuration.md +++ b/doc/md/Shaarli-configuration.md @@ -58,11 +58,9 @@ Some settings can be configured directly from a web browser by accesing the `Too "page_cache": "pagecache" }, "general": { - "check_updates": true, "rss_permalinks": true, "links_per_page": 20, "default_private_links": true, - "check_updates_branch": "stable", "check_updates_interval": 86400, "download_max_size": 4194304, "download_timeout": 30, @@ -88,7 +86,6 @@ Some settings can be configured directly from a web browser by accesing the `Too "formatter": "markdown", "updates": { "check_updates": true, - "check_updates_branch": "stable", "check_updates_interval": 86400 }, "feed": { @@ -207,7 +204,6 @@ Must be an associative array: `translation domain => translation path`. ### Updates - **check_updates**: Enable or disable update check to the git repository. -- **check_updates_branch**: Git branch used to check updates (e.g. `stable` or `master`). - **check_updates_interval**: Look for new version every N seconds (default: every day). ### Privacy diff --git a/tests/helper/ApplicationUtilsTest.php b/tests/helper/ApplicationUtilsTest.php index 1b4f82045..f23960ef8 100644 --- a/tests/helper/ApplicationUtilsTest.php +++ b/tests/helper/ApplicationUtilsTest.php @@ -142,17 +142,6 @@ public function testCheckUpdateNewVersionUnavailable() $this->assertFalse($version); } - /** - * Test update checks - invalid Git branch - */ - public function testCheckUpdateInvalidGitBranch() - { - $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/Invalid branch selected for updates/'); - - ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable'); - } - /** * Shaarli is up-to-date */ @@ -379,6 +368,17 @@ public function testCheckUpdateDev() ); } + /** + * Check update with a short git object name as curent version (Docker build). + * It should always return false. + */ + public function testCheckUpdateDevHash() + { + $this->assertFalse( + ApplicationUtils::checkUpdate('abc123d', self::$testUpdateFile, 100, true, true) + ); + } + /** * Basic test of getPhpExtensionsRequirement() */ diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php index b04dc3039..d0b655988 100644 --- a/tests/utils/config/configJson.json.php +++ b/tests/utils/config/configJson.json.php @@ -63,7 +63,6 @@ }, "updates": { "check_updates": false, - "check_updates_branch": "stable", "check_updates_interval": 86400 }, "feed": {