Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when plugin defines multiple PluginInterface classes #12226

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

justinbeaty
Copy link
Contributor

I have a composer plugin that defines multiple PluginInterface classes in composer.json as mentioned in the docs.

However, there is a bug when upgrading between versions of the plugin when there are multiple classes defined.

For example, assume this is the composer.json in version 1.0.0.

{
    "name": "my/plugin",
    "version": "1.0.0",
    "autoload": {
        "psr-4": {
            "MyNamespace\\": "src/"
        }
    },
    "extra": {
        "class": [
            "MyNamespace\\FirstPlugin",
            "MyNamespace\\SecondPlugin",
            "MyNamespace\\ThirdPlugin"
        ]
    }
}

And then in 2.0.0, we consolidate the functionality into one single class:

{
    "name": "my/plugin",
    "version": "2.0.0",
    "autoload": {
        "psr-4": {
            "MyNamespace\\": "src/"
        }
    },
    "extra": {
        "class": [
            "MyNamespace\\ConsolidatedPlugin"
        ]
    }
}

When we run composer update, the 1.0.0 package is activated before it's removed, but only a reference to ThirdPlugin will be kept in $this->registeredPlugins[$package->getName()], and so only ThirdPlugin is deactivated.

Thus FirstPlugin and SecondPlugin are still called, which will cause an error if those classes aren't self-contained and depend on functionality removed in 2.0.0.

Hopefully the explanation is clear, but I can create a reproduction demo tomorrow if you'd like. I also haven't run unit tests or phpstan yet, but will wait for the workflows.

@Seldaek Seldaek added this to the 2.2 milestone Dec 10, 2024
@Seldaek Seldaek merged commit 2365b78 into composer:2.2 Dec 10, 2024
18 of 19 checks passed
@Seldaek
Copy link
Member

Seldaek commented Dec 10, 2024

Thanks, I guess nobody else ever used the ability to define multiple classes? :)

@Seldaek
Copy link
Member

Seldaek commented Dec 10, 2024

See also 5cb9733 for main branch

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.

2 participants