Skip to content

[6.x] Keep plugin state consistent within a request - #20795

Open
riasvdv wants to merge 2 commits into
6.xfrom
rias/plugin-lifecycle
Open

riasvdv wants to merge 2 commits into
6.xfrom
rias/plugin-lifecycle

Conversation

@riasvdv

@riasvdv riasvdv commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Description

Plugin state lives in the plugins table, project config and memory. Changing it more than once in a request left them out of step.

 enablePlugin($handle)
   project config enabled = true
+  plugin is loaded, so getPlugin() returns it
 installPlugin($handle)
-  storedPluginInfo = [id, enabled]
+  storedPluginInfo = same shape as a loaded plugin
 getPluginInfo()['isEnabled']
-  whether the plugin was loaded at boot
+  isPluginEnabled()

Evidence

  • Before: disabling or uninstalling a plugin enabled earlier in the request threw, and isPluginUpdatePending() hit a missing schemaVersion key after an install.
    After: PluginLifecycleTest covers each case, and the tests fail on the old code.

riasvdv and others added 2 commits November 17, 2026 15:08
Plugins load once per request, so a plugin enabled or installed since then
isn't in getPlugin(). That broke two things that worked in Craft 5:

- Disabling or uninstalling a plugin enabled earlier in the same request
  threw InvalidPluginException. Both now create the plugin's instance when
  it's enabled but wasn't loaded. A forced uninstall of a disabled plugin
  still gets no instance, as before.
- installPlugin() stored only the plugin's ID and enabled flag, so
  isPluginUpdatePending() hit an undefined schemaVersion key. Installing now
  builds the stored info the same way loadPlugins() does.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1e8d1-9981-7090-9108-69125aec9ad4
getPluginInfo()['isEnabled'] checked whether the plugin was loaded at boot,
while isPluginEnabled() and the MCP capability read the stored enabled flag.
It now uses isPluginEnabled(), so the plugin commands and the control panel
see the same answer, and its editions and settings flags come from the
plugin even when it was enabled after plugins loaded.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1e8d1-9981-7090-9108-69125aec9ad4
@github-actions

Copy link
Copy Markdown

📚 Storybook previews

@craftcms/ui — open Storybook

No changed components detected in this Storybook.

resources/js — open Storybook

No changed components detected in this Storybook.

This branch has not been deployed

No deployments
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.

1 participant