Skip to content

Commit

Permalink
Don't instantiate plugins until it's time to install them
Browse files Browse the repository at this point in the history
Fixes #15506
  • Loading branch information
brandonkelly committed Aug 12, 2024
1 parent cca8d12 commit 4a8907c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fixed an error that could occur if a new element was saved recursively. ([#15517](https://github.com/craftcms/cms/issues/15517))
- Fixed a bug where plugins were being instantiated at the beginning of Craft installation requests, rather than after Craft was installed. ([#15506](https://github.com/craftcms/cms/issues/15506))

## 4.11.1 - 2024-08-07

Expand Down
14 changes: 6 additions & 8 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use craft\models\Site;
use craft\services\ProjectConfig;
use craft\web\Response;
use ReflectionClass;

/**
* Installation Migration
Expand Down Expand Up @@ -1194,21 +1195,18 @@ private function _validateProjectConfig(string &$error = null): bool
// and that they have the same schema as project.yaml
foreach ($pluginConfigs as $handle => $pluginConfig) {
try {
$plugin = $pluginsService->createPlugin($handle);
$pluginInfo = $pluginsService->getPluginInfo($handle);
} catch (InvalidPluginException) {
$error = "The “{$handle}” plugin is not Composer-installed, but project.yaml expects it to be.";
return false;
}

if (!$plugin) {
$error = "{$handle}” is not a valid plugin.";
return false;
}

$pluginRef = new ReflectionClass($pluginInfo['class']);
$schemaVersion = $pluginRef->getProperty('schemaVersion')->getDefaultValue();
$expectedSchemaVersion = $pluginConfig['schemaVersion'] ?? null;

if ($plugin->schemaVersion && $expectedSchemaVersion && $plugin->schemaVersion != $expectedSchemaVersion) {
$error = "$plugin->name is installed with schema version $plugin->schemaVersion, but project.yaml expects $expectedSchemaVersion.";
if ($schemaVersion && $expectedSchemaVersion && $schemaVersion != $expectedSchemaVersion) {
$error = "{$pluginInfo['name']} is installed with schema version $schemaVersion, but project.yaml expects $expectedSchemaVersion.";
return false;
}
}
Expand Down

0 comments on commit 4a8907c

Please sign in to comment.