Skip to content

Commit

Permalink
Craft now ensures that installed schema versions match the schema ver…
Browse files Browse the repository at this point in the history
…sions in `project.yaml` before syncing project config changes.
  • Loading branch information
andris-sevcenko committed Jan 24, 2019
1 parent 6733f86 commit b785163
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Changed
- URLs are no longer allowed in a user’s first or last names.
- Craft now ensures that installed schema versions match the schema versions in `project.yaml` before syncing project config changes.

### Fixed
- Fixed a bug where `site` translations were falling back to English if the translated message was identical to the source message. ([#3692](https://github.com/craftcms/cms/issues/3692))
Expand Down
14 changes: 10 additions & 4 deletions src/services/ProjectConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,8 @@ public function getPendingChangeSummary(): array

/**
* Returns whether all schema versions stored in the config are compatible with the actual codebase.
* The schemas must match exactly to avoid unpredictable behavior that can occur when running migrations
* and applying project config changes at the same time.
*
* @return bool
*/
Expand All @@ -659,19 +661,23 @@ public function getAreConfigSchemaVersionsCompatible(): bool
return true;
}

$configSchemaVersion = (string)$this->get(self::CONFIG_SCHEMA_VERSION_KEY, true);
$incomingSchema = (string)$this->get(self::CONFIG_SCHEMA_VERSION_KEY, true);
$existingSchema = (string)Craft::$app->schemaVersion;

if (version_compare((string)Craft::$app->schemaVersion, $configSchemaVersion, '<')) {
// Compare existing Craft schema version with the one that is being applied.
if (version_compare($existingSchema, $incomingSchema, '=')) {
return false;
}

$plugins = Craft::$app->getPlugins()->getAllPlugins();

foreach ($plugins as $plugin) {
/** @var Plugin $plugin */
$configSchemaVersion = (string)$this->get(Plugins::CONFIG_PLUGINS_KEY . '.' . $plugin->handle . '.schemaVersion', true);
$incomingSchema = (string)$this->get(Plugins::CONFIG_PLUGINS_KEY . '.' . $plugin->handle . '.schemaVersion', true);
$existingSchema = (string)$plugin->schemaVersion;

if (version_compare((string)$plugin->schemaVersion, $configSchemaVersion, '<')) {
// Compare existing plugin schema version with the one that is being applied.
if (version_compare($existingSchema, $incomingSchema, '=')) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/_special/incompatibleconfigs.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{% set title = "Unable to apply project.yaml changes"|t('app') %}

{% block message %}
<p>{{ 'Your `project.yaml` file was created for more recent versions of Craft and/or plugins than what’s currently installed.'|t('app')|md(inlineOnly=true) }}</p>
<p>{{ 'Your `project.yaml` file was created for different versions of Craft and/or plugins than what’s currently installed.'|t('app')|md(inlineOnly=true) }}</p>
<p>{{ 'Try running `composer install` from your terminal to resolve.'|t('app')|md(inlineOnly=true) }}</p>
{% endblock %}

0 comments on commit b785163

Please sign in to comment.