Fix hook_civicrm_permission upgrade failure. Defer system-flush to 'upgrade.finish' phase. #19346
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
port of PR #19345 to 5.34 / master
This addresses a recently reported upgrade failure. It moves a particular upgrade task (clearing all Drupal/Backdrop/etc caches) to address a previously latent discrepancy and prevent a cascade of premature interactions between modules.
Before
The upgrader executes Drupal/Backdrop cache-clear (
$userSystem->flush()
) indoIncrementalUpgradeFinish()
, which is part ofupgrade.main
phase and which runs several times (after every incremental version-update).During the
upgrade.main
phase, the pre-condition and invariant-condition is that the Civi schema is mismatched/unsuitable for executing most Civi logic. It is not until the end of the last incremental step that we reach the post-condition where schema is up-to-date and where most Civi logic can run safely.Depending on the UF/modules/configuration,
$userSystem->flush()
has open-ended side-effects -- causing different third-party code to execute mid-upgrade. In the reported error, it kicks off a cascade that involves D7, Features, Panopoly, D7's permission subsystem, Civi's permission subsystem, and then any modules/extensions that tie into Civi's permission subsystem (at which point it balks per a9033ca).The cascade caused by
$userSystem->flush()
is essentially chaotic (dependent on UF/modules/extensions/configurations). Of course, we don't care as long as the chaos stays over on the UF/CMS side... but if it circles back to the Civi side, then we're asking for trouble... because the invariant-condition ofupgrade.main
means that we cannot run most Civi logic reliably.After
The upgrader executes Drupal/Backdrop cache-clear (
$userSystem->flush()
) indoFinish()
as part of theupgrade.finish
phase (ie after the schema is up-to-date). During theupgrade.finish
phase, it is safe to run a wider range of Civi logic, so we are less sensitive to the chaotic cascade.Comments
$userSystem->flush()
will fire less often (e.g. 1x duringupgrade.finish
instead of 10x duringupgrade.main
). It'll be curious to see if this makes upgrades faster.$userSystem->flush()
was originally introduced circa v4.3 with https://issues.civicrm.org/jira/browse/CRM-11823 and d8a4acc. At the time, 4.3'sdrupal/civicrm.module
had started to make critical use of D7'shook_theme_registry_alter
(cacheable data), so upgrades needed to clear the D7 theme cache. That particular issue is now obsolete (MINIMUM_UPGRADABLE_VERSION
is now 4.4), but it's interesting as to spot-check this patch with a real use-case. I think this checks out -- the incremental schema updates for Civi should not require rebuilding D7's theme-registry for every point-release (5.10.alpha1
,5.10.beta1
,5.10.0
,5.11.alpha1
, ...). Rather, it makes more sense to rebuild D7's theme-registry one time.