(dev/core#3660) CRM_Extension_ClassLoader - Defend against redundant refreshes #23900
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.
Overview
This is a follow-up to #23824 (c24dd7d) which addresses a regressive edge-case.
Steps to Reproduce
wmf-civicrm
which (a) callsSystem.flush
(rebuildMenuAndCaches()
)during
hook_install
-- and then (b) loads some class from the same extension.Before
Crashes on loading the class
CRM_Foo_Helper
After
Loads the class
CRM_Foo_Helper
.Comments
(1) To see what's happening, consider
CRM_Extension_Manager_Module::onPreInstall()
. This registers the new classloader and then fireshook_install
which eventually firesrebuildMenuAndCaches()
. With c24dd7d, this resets the classloader again. But the extension isn't fully installed yet - so it forgets about the new extension.(2) Is it safe to have some (temporarily) sticky items? Ish. You might say: "Ah, but what if we need to remove an extension? Won't this static variable retain stale things?" Doesn't matter. In PHP, classloading is a one-way-street. (You cannot unload.) So you'll still have old classes in memory, regardless of whether the
ClassLoader
has some old metadata about where to find classes.(3) I'm on the fence about whether this patch is a good idea. Calling
System.flush
explicitly in this context seems like an invitation to trouble. OTOH, it worked before #23824, so it can be called a regression.