Skip to content

Support subplugins of non-core plugins. - #4

Open
micaherne wants to merge 1 commit into
moodle:mainfrom
University-of-Strathclyde-LTE-Team:non-core-subplugin-type-support
Open

micaherne wants to merge 1 commit into
moodle:mainfrom
University-of-Strathclyde-LTE-Team:non-core-subplugin-type-support

Conversation

@micaherne

Copy link
Copy Markdown

Hi, this is a patch to add support for subplugins of non-core plugins. The use case I have is this: I have mod_peerwork, and a custom subplugin for it - peerworkcalculator_maemarkcf - and currently there is no way to use composer to build the Moodle codebase with these two plugins as requires. There are various third-party plugins that support subplugins so this is not a one-off case.

The patch basically reads the subplugin types from the subplugins.json file once the parent package has been installed. This is not ideal as it requires composer install to be run twice but it's literally not possible to support doing it in one go due to the composer architecture. The patch does alert you to this with a message at the end. This seems preferable to not being able to use composer at all in this scenario, and it should be more or less invisible to anyone who doesn't have a subplugin of a non-core plugin. It did however mean changing an unknown package type from a hard fail to a warning.

It's probably worth mentioning that running it twice is a fairly normal requirement at the moment due to a common edge case. Where a plugin doesn't declare its dependency on Moodle in its composer.json - and none of the ones I have seen so far do - and the package name is before "moodle/moodle" alphabetically, the package will be installed before Moodle and immediately overwritten. On the second run of composer install or update the install location is checked and it is re-installed as it's no longer there.

A further gotcha along the same lines with the patch is that the subplugin must declare its dependency on the parent plugin otherwise the same sort of thing will happen. If it's alphabetically before the parent plugin then the composer command will need to be run again as the parent plugin's installation will wipe out the subplugin's.

I hope this makes some kind of sense!

@davidpesce

Copy link
Copy Markdown

Thanks for this. Registry operator's view: it fixes a real gap and the approach is the right one.

Context from camp (camp-registry.org): every listed subplugin of a third-party parent is published as a Composer package of type moodle-<prefix>, so today the installer throws on all of them. The registry currently recognises 31 such families with 98 listed members (customcert elements, lifecycle steps and triggers, tool_certificate elements, the MuTMS families and so on). Only two members have releases so far, but the number grows as authors publish, and #1 shows the static-table route does not scale. Reading db/subplugins.json from the installed parent is the sustainable answer.

Three suggestions, none of which change the approach:

  1. The two-pass install is probably avoidable for packages that declare their parent. initLocations() runs once in the installer's constructor, so a parent installed during this run is not seen until the next one. But since v1.2.2 the download manager installs packages one at a time in dependency order, so when the subplugin's turn comes its parent is already on disk if the subplugin requires it. If getInstallPath() re-read the providers on an unknown type instead of falling through, well-declared packages would install in one pass, and the "run again" message would only fire for packages that do not declare their parent. camp will emit require on the parent package for its family members, so registry-served packages would take the single-pass path.

  2. CONTAINER_TEMPLATES limits the search to installed mod, editor, tool and local packages. Any installed moodle-* package can carry a db/subplugins.json, and the full path table already exists in MoodleData. Iterating every installed package whose type the installer knows would cover the rest at no cost.

  3. On the first pass an unknown-type package lands under vendor/ via the parent installer and is moved on the second. That is acceptable given that a hard failure would abort the whole transaction, but it is worth a sentence in the end-of-run message so nobody wonders about the stray vendor/ copy.

The subplugins.json handling looks right to me for both spellings: subplugintypes is parent-relative and plugintypes is dirroot-relative, and the patch treats them accordingly.

@davidpesce

Copy link
Copy Markdown

Following up on the requirement mentioned above, so the mapping is on record where HQ can see it. camp's packages.json now links packages to the other camp packages they need: the parent package for a subplugin of a third-party parent, and each $plugin->dependencies entry that names a plugin camp serves. The constraint is the exact list of the dependency's served versions whose $plugin->version at the tag meets the declared minimum, regenerated at every publish. Dependencies Moodle bundles are omitted; ones camp does not serve are omitted and logged rather than written as something Composer cannot satisfy.

This is camp's translation of the author's version.php declaration into Composer's grammar, not a proposal for how plugins should declare things. If HQ defines a convention for this, camp will follow it; the linking pass is behind a switch for that reason.

@micaherne

micaherne commented Sep 22, 2026 •

Copy link
Copy Markdown
Author

Thanks for getting back so quickly on this @davidpesce! On the suggestions:

  1. This is an interesting idea, and it made me go back and look at my understanding of the path calculation workflow (which turned out to be wrong). The logic is correct in a way and I confirmed that the package location actually is calculated on the fly just before it's installed. (I thought it was all calculated at the point where Composer calculates the dependency graph, when all it has is the metadata.) Where it falls down is that we can't actually see the downloaded packages until the end of the process. This is because we're using the Composer\InstalledVersions class, which only reads the installed.php file that is generated at the very end of the install or update process. To make it work in one pass, in addition to having the subplugin declare a dependency on the parent, we would have to access composer's "live memory" via $composer->getRepositoryManager()->getLocalRepository(). Unfortunately this isn't available to us in the getData() method of the data provider. The fix would probably be to pass the Composer instance as a method parameter but that would change the interface so might not be acceptable. I'd be happy to rework the patch if someone from HQ can confirm that that interface change would be ok.

  2. That's not correct. Yes a plugin of any type can have a subplugins.json if it wants, but the only ones Moodle will even look at are those four: https://github.com/moodle/moodle/blob/v5.3.0-beta/public/lib/classes/component.php#L73

  3. This is also a good idea but I'm not sure how we would determine that a package had been reinstalled somewhere else in that run. It wouldn't make sense to show this unless it had as it basically only affects Moodles where there is a separate third-party subplugin of a third-party plugin. If I had to make up a statistic I'd guess that that's fewer than 1% of installations.

Your point about how you've translated the version.php into composer.json is interesting too, with respect to subplugins. I was once told on the Moodle dev chat by someone at HQ that subplugins should not declare their dependency on the parent plugin as it was already implied. It was years ago and may have changed since then, and I'm not quite sure what the reasoning was - presumably to remove any complications from Moodle's own dependency graph resolver or something like that. Anyway it may be that the composer.json has to diverge from the version.php in that case.

@adamjenkins

Copy link
Copy Markdown

+1 from me, and I'd love to see this merged as soon as possible.

I'm already using it. Today I tested this branch on a Moodle site, installing the two subplugins of my VR room activity (mod_vrroom): a vrroomruntime run mode and a vrroomenv room pack. With v1.2.2 both failed with "unknown plugin type". With this branch the installer read the subplugin types from mod_vrroom's db/subplugins.json and everything installed into the right place. It worked beautifully.

Thanks Michael for the patch. Please merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants