From 6cd2a3210c2649b8a3bebcb8a39a1a12218286f0 Mon Sep 17 00:00:00 2001 From: Martin Price Date: Thu, 24 Apr 2025 19:18:01 +0100 Subject: [PATCH 1/2] Issue #456: Fix check for latest release --- commands/download.bee.inc | 41 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/commands/download.bee.inc b/commands/download.bee.inc index 5f2a049..1eeef51 100644 --- a/commands/download.bee.inc +++ b/commands/download.bee.inc @@ -502,8 +502,7 @@ function download_bee_get_project_info($project, $organization, $release = '', $ // Check that a valid latest release exists. For GitHub to count a // release as 'latest' it must be published (i.e. not draft) and not a // pre-release. - $defined_release_url = "https://github.com/$organization/$project/releases/latest"; - if (download_bee_check_url_exists($defined_release_url)) { + if (download_bee_check_latest_release_exists($project, $organization)) { $final_option = 'latest'; } else { @@ -1331,3 +1330,41 @@ function download_bee_check_url_exists($url) { // Return the result. return $return_code == 200; } + +/** + * Check whether a latest release exists. + * + * @param string $project + * The project to check for. + * @param string $organization + * The organization to check for. + * + * @return bool + * TRUE if a latest release exists; FALSE if not. + */ +function download_bee_check_latest_release_exists($project, $organization) { + + $url = "https://github.com/$organization/$project/releases/latest"; + // Initiate the curl request. + $curl_handle = curl_init($url); + + // Compile the options for the curl request. + // Set the user agent string. + curl_setopt($curl_handle, CURLOPT_USERAGENT, BEE_USERAGENT); + // Allow curl to follow redirects. + curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, TRUE); + // Specify that we don't need the body of the response. + curl_setopt($curl_handle, CURLOPT_NOBODY, TRUE); + + // Execute the curl request. + curl_exec($curl_handle); + + // Get the URL that the latest release URL diverts to. + $effective_url = curl_getinfo($curl_handle, CURLINFO_EFFECTIVE_URL); + + // Close the curl request. + curl_close($curl_handle); + + $no_latest_release_url = "https://github.com/$organization/$project/releases"; + return $effective_url != $no_latest_release_url; +} From 6e8e735d4cb278bb969654014ec061aacea80894 Mon Sep 17 00:00:00 2001 From: Martin Price Date: Thu, 24 Apr 2025 19:19:16 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f66fc9..f464a4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project follows the which is based on the major version of Backdrop CMS with a semantic version system for each contributed module, theme and layout. -## [Unreleased] - 2025-04-21 +## [Unreleased] - 2025-04-24 ### Added - An option for the `db-import` command to allow import from newer MariaDB