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

Plugin minVersionRequired does not get triggered when updating #7191

Closed
BenParizek opened this issue Nov 27, 2020 · 3 comments
Closed

Plugin minVersionRequired does not get triggered when updating #7191

BenParizek opened this issue Nov 27, 2020 · 3 comments
Labels

Comments

@BenParizek
Copy link
Contributor

Description

I'm trying to use the minVersionRequired setting however it doesn't appear to get recognized. I'm testing in an upgrade from Craft 2 to Craft 3. The initial upgrade of the Craft db goes fine. And then, when I hit the upgrade button the second time to trigger the plugin updates

The upgrade appears to hit this line in craft\services\Plugins and return false and the minVersionRequired never gets checked:

if (!Craft::$app->getIsInMaintenanceMode() && $this->hasPluginVersionNumberChanged($plugin) && !$this->doesPluginRequireDatabaseUpdate($plugin)) {

In my test, this conditional's parts resolve to the following values:

Statement Value
!Craft::$app->getIsInMaintenanceMode() true
$this->hasPluginVersionNumberChanged($plugin) true
!$this->doesPluginRequireDatabaseUpdate($plugin) false

And, in checking the doesPluginRequireDatabaseUpdate statement the plugin in question does return two different schema versions, so $this->doesPluginRequireDatabaseUpdate($plugin) does correctly evaluate to true before it gets negated.

Changing !$this->doesPluginRequireDatabaseUpdate($plugin) (with the Not operator) to $this->doesPluginRequireDatabaseUpdate($plugin) (without the Not operator) resolves the conditional as I'd expect it, as the plugin has a new version and new schema version, and throws the expected HttpException informing the user they need to upgrade to a particular version of the plugin in question before triggering the migrations for the current version of the plugin that is present during the migration.

Steps to reproduce

  1. Prepare a Craft 2 db with a custom plugin
  2. Prepare a Craft 3 install with a newer version of the custom plugin that uses the minVersionRequired setting to match a version of the plugin between what is on the Craft 2 site and the latest version on the Craft 3 site
  3. Trigger the db migration from the Craft 3 /admin URL

Additional info

  • Craft version: 3.6.x
  • PHP version: 7.4
  • Database driver & version: mysql
  • Plugins & versions: various
@BenParizek BenParizek added the bug label Nov 27, 2020
@BenParizek
Copy link
Contributor Author

I believe one other scenario could trigger this issue. I'm not sure if the situation matters. But just to note it here.

If the first plugin being updated does not have a minVersionRequired and throws an error, the update process will be halted and Craft will be put into maintenance mode. Then, if the user tries refreshing the page to continue the migration process, Craft::$app->getIsInMaintenanceMode() will return true and this condition for the minVersionRequired check will return false and skip the minVersionRequired check for all plugins that come after the initial plugin or condition that triggered maintenance mode.

@brandonkelly
Copy link
Member

Thanks for pointing that out! Fixed for the next release.

@brandonkelly
Copy link
Member

Craft 3.5.17 is out now with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants