[3.0] Shows which mod added each integration hook - #9700
Open
albertlast wants to merge 1 commit into
Open
albertlast wants to merge 1 commit into
albertlast wants to merge 1 commit into
Conversation
The hooks list tells an admin that a function is attached to a hook, but not where it came from, so working out which mod is responsible for one means reading mod files. Each installed package is asked which hooks its package-info.xml registers, and the list gains a column naming the package that added each entry. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Mathias Albert <mathiaspapealbert@hotmail.com>
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.
Description
Admin → Maintenance → Hooks lists every function attached to every hook, with its file and its status. What it never says is which mod put it there.
That is the question an admin actually has. Something on the forum misbehaves, the list shows forty entries across a dozen hooks, and finding out which mod owns the one that looks suspicious means opening mod files, or uninstalling mods one at a time. The information exists — every package says what it hooks in its
package-info.xml— it just isn't shown anywhere.This adds an "Added By" column naming the package that registered each entry, sortable, so the hooks belonging to one mod can be grouped together:
my_mod_load_themeother_mod_buttonssome_leftover_functionHow it works:
PackageUtils::getHookOwners()walks the installed packages, reads the hooks each one registers in itspackage-info.xml, and builds the entry exactly asIntegrationHook::add()stores it, so the two can be matched. A hook a mod registered from its own code, and SMF's own hooks, have no owner and are shown as "Not from a package" rather than being blamed on anything.Notes on the decisions in it:
SMF_VERSIONis3.0 Alpha 5-dev, which does not match a package'sfor="3.0 - 3.0.99", so the hooks of a perfectly normal mod went unattributed. Entries from a block that never ran match no stored hook, so keeping them costs nothing.package-info.xml. That is much less work than what the page already does, which is to scan every file inSources/and parse out the functions each one defines.Related: #8808 adds an
id_packagecolumn to a dedicated hooks table and carries it into this list's data, but does not display it. This is the admin-facing half, it works onrelease-3.0as it stands today, and if that PR lands the lookup here can be replaced by reading that column.Testing
tests/Unit/PackageUtilsTest.phpcovers the reading of the hooks out of apackage-info.xml: the entry built for a plain function, for a file plus function, for an instantiated class, hooks added by an upgrade block, blocks for other SMF versions, and reverse hooks.Verified in the Docker environment as well, with a package installed that registers three hooks, one of them disabled and one an object. All three are attributed to the mod, a hook belonging to no package shows "Not from a package", sorting by the new column groups them, and nothing new appears in
log_errors.Issues References (Fixes|Related|Closes)
Related: #8808, #9695
🤖 Generated with Claude Code