[1.x] fix(extension manager): repair major-update detection and constraint relaxation - #4948
Open
karl-bullock wants to merge 1 commit into
Open
[1.x] fix(extension manager): repair major-update detection and constraint relaxation#4948karl-bullock wants to merge 1 commit into
karl-bullock wants to merge 1 commit into
Conversation
…laxation
Two independent defects stop a major update from ever completing.
CheckForUpdatesHandler skipped every package that is not an installed
extension. flarum/core is not one, so it was dropped on every run, even
though surfacing a new major of it is the stated purpose of the first
composer outdated call, and both LastUpdateCheck::getNewMajorVersion() and
the admin frontend read a flarum/core entry back out of that list.
ComposerJson::require('*', '*') tested Util::nameToId($packageName), which
in the wildcard branch is always the literal '*'. That never resolves to an
extension, so every iteration continued and no constraint was ever relaxed,
while nameToId() emitted a warning per require entry. Test $p, the package
being iterated, and skip platform requirements with no vendor segment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #4947 to
1.x. Both defects are present on this branch verbatim, and this is the branch where they have a user-visible consequence, because it is the code a forum runs while upgrading from 1.8 to 2.0.The two defects
1.
flarum/coreis filtered out of the update check.CheckForUpdatesHandler::handle()skips every package that is not an installed extension.flarum/coreis not one, so it is dropped on every run,updates.installednever contains it,LastUpdateCheck::getNewMajorVersion()returns null, andMajorUpdateHandlerthrowsNoNewMajorVersionExceptionbefore doing any work. Over the API that is a409 no_new_major_version.The surrounding code is written to expect core in that list: the docblock above says the first
composer outdatedcall is made so major updates are visible and "That includes flarum/core itself",getNewMajorVersion()searches the list forflarum/core, and on the frontendControlSectionState.formatCoreUpdate()filters the same list forflarum/coreand builds a pseudo-extension from it forMajorUpdaterto render.2.
ComposerJson::require('*', '*')never relaxes anything. The wildcard branch testsUtil::nameToId($packageName), and there$packageNameis always the literal*, which never resolves to an extension. Every iterationcontinues, so no constraint is changed, andnameToId()emits anUndefined array key 1warning per require entry. Measured on a forum with extensions pinned to^1.8: 18 warnings, 0 constraints changed.The second is masked by the first, so fixing either alone is not enough. With only the detection fix, a major update would run
composer updatewithflarum/corepinned to the new major while every extension stayed on its 1.8 constraint, which cannot resolve.strpos()is used rather thanstr_contains()to stay within this branch's>=7.3 || ^8.0support.End to end on a real forum
Flarum 1.8.19, extension manager enabled, every extension pinned to
^1.8,flarum/package-managerat^1.0,minimum-stability: beta, PHP 8.4.24, Composer 2.10.2, MariaDB. The extension'ssrc/was replaced with this branch, and a genuineMajorUpdatewas run withdryRun = false.Before, on stock
1.x:After, with this branch:
So the forum completed 1.8.19 to 2.0.0-rc.5 through the extension manager's own code path and came back up.
One thing I hit that is not addressed here
After Composer finished writing
vendor/, the still-running PHP process fatalled:The update itself had already succeeded on disk, and the forum was healthy once migrations were run from a fresh process. The cause is that
ComposerAdapterruns Composer in-process, and a 1.x to 2.x upgrade replacessymfony/consoleunderneath the very process executing it, so the new class no longer matches the interface already loaded. That means theFlarumUpdatedevent and anything after it inMajorUpdateHandler::handle()do not run.I have deliberately not touched that here, since it is a separate design question and this PR is already doing two things. Flagging it because these fixes are what make that code path reachable in the first place. Happy to open it separately if it is useful.
Note on reach
This extension does have a workflow on this branch,
.github/workflows/flarum-extension-manager-backend.yml, but it setsenable_backend_testing: false, so its suite does not run in CI. I have not proposed changing that here. If you do enable it, note that the fixture inSetupComposer.phppinsflarum/coreto1.0.0, which newer Composer refuses to install over published security advisories. This branch pinscomposer:2.2, which predates that check, so it would not bite today.Since the last 1.x release of
flarum/package-managerwas v1.0.8 in March, this only reaches people upgrading from 1.8 if a further 1.0.x is tagged before 2.0.0 stable. That is entirely your call, but it is the reason I opened the backport rather than leaving it at #4947.One note on the commit message: it uses the scope
package manager, taken from the directory name. The extension publishes asflarum/extension-managerand titles itself Extension Manager, so the PR title has been corrected to match. I cannot amend the published commit from here.