Skip to content

Commit

Permalink
(dev/core#3660) Ensure that rebuildMenuAndCaches has current mixins+c…
Browse files Browse the repository at this point in the history
…lassloaders

Overview
--------

This fixes an issue in transitioning from `hook_managed` to `mixin/mgd-php@1`, wherein
managed-entities are briefly deleted (but later recreated).

Steps to Reproduce
------------------

1. (Web) Install an extension with a revision that uses `hook_managed`
2. (CLI) Switch the extension to a revision that uses `mixin/mgd-php@1`
3. (CLI) View contents of `civicrm_managed`
4. (Web) Run `civicrm/menu/rebuild`
5. (CLI) View contents of `civicrm_managed`
6. (Web) Run `civicrm/menu/rebuild`
7. (CLI) View contents of `civicrm_managed`

Before
------

While processing step 4 (`civicrm/menu/rebuild`), it fails to run the hooks for `mgd-php`.

Consequently, the list of managed-entities is lost and will disappear at step 5.

After
-----

While processing step 4 (`civicrm/menu/rebuild`), it activates the hooks for `mgd-php`.

Technical Details
------------------

When processing `civicrm/menu/rebuild`, there are a couple big substeps:

* `Civi\Core\Container::boot()` - During this process, it loads extensions. As usual,
  this reads cached metadata, sets up classloaders, sets up mixins/hooks, etc.
* `CRM_Core_Invoke::rebuildMenuAndCaches()` - During this process, it clears
  out caches and rebuilds several things (menus, managed-entities, etc).

The problem is this:

* The cache used during `boot()` has stale metadata (specifically,
  `civicrm_cache` has old values of `mixinScan` and `mixinBoot`).
  So it doesn't setup any new mixins/hooks.
* Then `rebuildMenuAndCaches()` depends on the mixins/hooks that are already setup.
  While the function does clear persistent caches, it assumes that the
  PHP runtime environment is up-to-spec. But it's not -- becuase our hooks
  were based on the caches.

The patch uses the same `refresh()` mechanism as the extension-administration subsystem (which
has to reset the classloaders+mixins after enabling or disabling an extension).
  • Loading branch information
totten committed Jun 17, 2022
1 parent 89bb1a2 commit c24dd7d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CRM/Core/Invoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ public static function rebuildMenuAndCaches(bool $triggerRebuild = FALSE, bool $
$config = CRM_Core_Config::singleton();
$config->clearModuleList();

// dev/core#3660 - Activate any new classloaders/mixins/etc before re-hydrating any data-structures.
CRM_Extension_System::singleton()->getClassLoader()->refresh();
CRM_Extension_System::singleton()->getMixinLoader()->run(TRUE);

// also cleanup all caches
$config->cleanupCaches($sessionReset || CRM_Utils_Request::retrieve('sessionReset', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));

Expand Down

0 comments on commit c24dd7d

Please sign in to comment.