Skip to content

Fix release download failure when allow_url_fopen is disabled#8127

Merged
DawoudIO merged 3 commits intomasterfrom
copilot/fix-upgrade-download-error
Mar 3, 2026
Merged

Fix release download failure when allow_url_fopen is disabled#8127
DawoudIO merged 3 commits intomasterfrom
copilot/fix-upgrade-download-error

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

Servers with allow_url_fopen = Off (common on shared hosting) fail to download upgrade ZIPs via file_get_contents(), producing "no suitable wrapper could be found". Since cURL is already a declared ChurchCRM prerequisite, it's the correct transport to use here.

Changes

  • src/ChurchCRM/dto/ChurchCRMReleaseManager.phpdownloadRelease() now uses cURL as the primary download method:
    • SSL verification enabled (CURLOPT_SSL_VERIFYPEER, CURLOPT_SSL_VERIFYHOST)
    • Follows redirects (CURLOPT_FOLLOWLOCATION) — needed for GitHub's release asset CDN
    • 300s timeout appropriate for large ZIP payloads
    • Captures curl_errno() + curl_error() + HTTP status code for actionable failure logs
    • Falls back to file_get_contents only if curl_init is somehow unavailable
    • Existing 3-attempt retry loop with backoff is unchanged
// Before — fails silently when allow_url_fopen=Off
$downloadContent = @file_get_contents($url);

// After — works regardless of allow_url_fopen
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
$result = curl_exec($ch);
Original prompt

This section details on the original issue you should resolve

<issue_title>Upgrade to 7.0 error</issue_title>
<issue_description>Using "new release" feature, ChurchCRM throwing error:
Error making API Call to: /admin/api/upgrade/download-latest-release
Error text: Failed to download latest release
Log attached.

260302_release_upgrade_error.log

Collected Value Title Data
Page Name /admin/system/upgrade
Screen Size 1080x1920
Window Size 793x1606
Page Size 1171x1606
Platform Information Linux cccat740.hostpapavps.net 4.18.0-553.58.1.el8_10.x86_64 #1 SMP Wed Jun 25 06:37:46 EDT 2025 x86_64
PHP Version 8.4.18
SQL Version 10.11.16-MariaDB
ChurchCRM Version 6.8.1
Reporting Browser Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0
Prerequisite Status Missing Prerequisites: ["PHP iconv","FileInfo Extension for image manipulation"]
</issue_description>

<agent_instructions>Review the logs and recommend a fix </agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: DawoudIO <554959+DawoudIO@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix upgrade to latest release error in ChurchCRM Fix release download failure when allow_url_fopen is disabled Mar 2, 2026
@DawoudIO DawoudIO requested a review from Copilot March 2, 2026 21:08
@DawoudIO DawoudIO marked this pull request as ready for review March 2, 2026 21:08
@DawoudIO DawoudIO requested a review from a team as a code owner March 2, 2026 21:08
@DawoudIO DawoudIO requested review from DAcodedBEAT, DawoudIO, MrClever, bigtigerku, grayeul and respencer and removed request for a team March 2, 2026 21:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the upgrade ZIP download logic to work on hosts where allow_url_fopen is disabled by switching the primary transport from file_get_contents() to cURL (with improved logging and retry behavior), ensuring the release download step succeeds in common shared-hosting configurations.

Changes:

  • Use cURL as the primary download mechanism for GitHub release assets (SSL verification, redirects, timeout, actionable error details).
  • Keep existing retry loop/backoff while improving error propagation to logs/exceptions.
  • Retain file_get_contents() as a fallback when cURL is unavailable.

Comment on lines +253 to +256
if (function_exists('curl_init')) {
// Use cURL for download (works even when allow_url_fopen is disabled)
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

function_exists('curl_init') doesn’t guarantee curl_init($url) returns a valid CurlHandle. If curl_init returns false (e.g., malformed/empty URL), the subsequent curl_setopt calls will raise a TypeError and bypass the retry/exception flow. Handle the false return explicitly (set an error message and either retry or fall back to file_get_contents).

Copilot uses AI. Check for mistakes.
@DawoudIO DawoudIO added this to the 7.0.1 milestone Mar 3, 2026
Guard against curl_init() returning false (e.g. malformed URL) before
passing the handle to curl_setopt(), which would raise a TypeError in
PHP 8 and bypass the retry/exception flow.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@DawoudIO
Copy link
Contributor

DawoudIO commented Mar 3, 2026

Addressed the Copilot reviewer feedback in c1633ba: added an explicit $ch === false check after curl_init(). If initialization fails (e.g. malformed URL), the error message is set and the loop falls through to retry naturally — no TypeError from passing false to curl_setopt().

@DawoudIO DawoudIO merged commit 4f1c3c1 into master Mar 3, 2026
12 checks passed
@DawoudIO DawoudIO deleted the copilot/fix-upgrade-download-error branch March 3, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade to 7.0 error

3 participants