diff --git a/CHANGELOG-v3.2.md b/CHANGELOG-v3.2.md index 57b76a4d2f3..0ad23dd120e 100644 --- a/CHANGELOG-v3.2.md +++ b/CHANGELOG-v3.2.md @@ -44,6 +44,7 @@ - Added the `_special/sitepicker` template. - It’s now possible for plugins and modules to define custom actions on console controllers. - Added a testing framework for Craft and plugins, powered by Codeception. ([#3382](https://github.com/craftcms/cms/pull/3382), [#1485](https://github.com/craftcms/cms/issues/1485), [#944](https://github.com/craftcms/cms/issues/944)) +- Added `craft\base\ApplicationTrait::getInstalledSchemaVersion()`. - Added `craft\base\BlockElementInterface`. - Added `craft\base\Element::EVENT_AFTER_PROPAGATE`. - Added `craft\base\Element::EVENT_REGISTER_PREVIEW_TARGETS`. diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index aa9dbc5a4f0..a33cc25d2ab 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -3,6 +3,7 @@ ## Unreleased ### Added +- Added `craft\base\ApplicationTrait::getInstalledSchemaVersion()`. - Added `craft\services\Matrix::duplicateBlocks()`. ### Changed @@ -12,6 +13,7 @@ - Fixed a bug where Edit Entry pages would show unnecessary page unload warnings in Chrome 75. - Fixed an error that could occur when editing entries on multi-site installs. - Fixed a bug where Matrix blocks weren’t getting duplicated for other sites when creating a new element. ([#4449](https://github.com/craftcms/cms/issues/4449)) +- Fixed a bug where new installs could be missing most project config values. ## 3.2.0-RC1 - 2019-06-25 diff --git a/src/base/ApplicationTrait.php b/src/base/ApplicationTrait.php index ba1c9b74b93..4042f16025d 100644 --- a/src/base/ApplicationTrait.php +++ b/src/base/ApplicationTrait.php @@ -32,6 +32,7 @@ use craft\services\Fields; use craft\services\Globals; use craft\services\Matrix; +use craft\services\ProjectConfig; use craft\services\Sections; use craft\services\Security; use craft\services\Sites; @@ -114,6 +115,7 @@ * @property-read I18N $i18n The internationalization (i18n) component * @property-read Queue|QueueInterface $queue The job queue * @property-read Security $security The security component + * @property-read string $installedSchemaVersion The installed schema version * @property-read View $view The view component * @method AssetManager getAssetManager() Returns the asset manager component. * @method Connection getDb() Returns the database connection component. @@ -259,6 +261,16 @@ public function setIsInstalled($value = true) $this->_isInstalled = $value; } + /** + * Returns the installed schema version. + * + * @return string + */ + public function getInstalledSchemaVersion(): string + { + return $this->getProjectConfig()->get(ProjectConfig::CONFIG_SCHEMA_VERSION_KEY) ?? $this->schemaVersion; + } + /** * Returns whether Craft has been fully initialized. * diff --git a/src/db/SoftDeleteTrait.php b/src/db/SoftDeleteTrait.php index c6516828302..67a97afedc1 100644 --- a/src/db/SoftDeleteTrait.php +++ b/src/db/SoftDeleteTrait.php @@ -84,7 +84,7 @@ public static function find() $query = parent::find(); // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.19', '>=')) { $query->where(['dateDeleted' => null]); } diff --git a/src/elements/db/ElementQuery.php b/src/elements/db/ElementQuery.php index 10995b4c1c7..7111939a724 100644 --- a/src/elements/db/ElementQuery.php +++ b/src/elements/db/ElementQuery.php @@ -1324,7 +1324,7 @@ public function prepare($builder) } // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.0', '>=')) { if ($this->trashed === false) { $this->subQuery->andWhere(['elements.dateDeleted' => null]); @@ -2034,7 +2034,7 @@ private function _applyStructureParams(string $class) ->from([Table::STRUCTURES]) ->where('[[id]] = [[structureelements.structureId]]'); // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.0', '>=')) { $existsQuery->andWhere(['dateDeleted' => null]); } @@ -2176,7 +2176,7 @@ private function _applyStructureParams(string $class) private function _applyRevisionParams() { // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.2.6', '<')) { return; } diff --git a/src/migrations/Install.php b/src/migrations/Install.php index e2bc115f5ea..637b43a2e23 100644 --- a/src/migrations/Install.php +++ b/src/migrations/Install.php @@ -984,9 +984,6 @@ public function insertDefaultData() $generalConfig = Craft::$app->getConfig()->getGeneral(); $projectConfig = Craft::$app->getProjectConfig(); - // Set the schema version so element queries know it's safe to factor in draft/revision params - $projectConfig->set('system.schemaVersion', Craft::$app->schemaVersion); - $applyExistingProjectConfig = false; if ($generalConfig->useProjectConfigFile) { diff --git a/src/records/GlobalSet.php b/src/records/GlobalSet.php index b799ad88b58..2660360b117 100644 --- a/src/records/GlobalSet.php +++ b/src/records/GlobalSet.php @@ -48,7 +48,7 @@ public static function find() $query = parent::find(); // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.19', '>=')) { $query ->where(['exists', (new Query()) diff --git a/src/records/User.php b/src/records/User.php index 3c702369b10..a6b7cdc24e6 100644 --- a/src/records/User.php +++ b/src/records/User.php @@ -68,7 +68,7 @@ public static function find() ->innerJoinWith(['element element']); // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.19', '>=')) { $query->where(['element.dateDeleted' => null]); } diff --git a/src/services/Elements.php b/src/services/Elements.php index 0cc15159d93..18b09ba1cfe 100644 --- a/src/services/Elements.php +++ b/src/services/Elements.php @@ -325,7 +325,7 @@ public function getElementByUri(string $uri, int $siteId = null, bool $enabledOn ]); // todo: remove schema version conditions after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.0', '>=')) { $query->andWhere(['elements.dateDeleted' => null]); } diff --git a/src/services/Fields.php b/src/services/Fields.php index 163daa8ebc7..75d5569a5ae 100644 --- a/src/services/Fields.php +++ b/src/services/Fields.php @@ -1610,7 +1610,7 @@ private function _createFieldQuery(): Query ->orderBy(['fields.name' => SORT_ASC, 'fields.handle' => SORT_ASC]); // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.0', '>=')) { $query->addSelect(['fields.searchable']); } @@ -1634,7 +1634,7 @@ private function _createLayoutQuery(): Query ->from([Table::FIELDLAYOUTS]); // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.0', '>=')) { $query->where(['dateDeleted' => null]); } diff --git a/src/services/Plugins.php b/src/services/Plugins.php index 0c235254ba2..dcf722ce9a7 100644 --- a/src/services/Plugins.php +++ b/src/services/Plugins.php @@ -1239,7 +1239,7 @@ private function _createPluginQuery(): Query ->from([Table::PLUGINS]); // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.19', '>=')) { $query->addSelect(['licensedEdition']); } diff --git a/src/services/Sections.php b/src/services/Sections.php index 91f9f7deb6f..5f018da0bed 100644 --- a/src/services/Sections.php +++ b/src/services/Sections.php @@ -1436,7 +1436,7 @@ private function _createSectionQuery(): Query // todo: remove schema version condition after next beakpoint $condition = null; $joinCondition = '[[structures.id]] = [[sections.structureId]]'; - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.19', '>=')) { $condition = ['sections.dateDeleted' => null]; $joinCondition = [ @@ -1619,7 +1619,7 @@ private function _createEntryTypeQuery() ->from([Table::ENTRYTYPES]); // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.19', '>=')) { $query->where(['dateDeleted' => null]); } diff --git a/src/services/Volumes.php b/src/services/Volumes.php index a0fcd4edc74..b44ea4c2bd8 100644 --- a/src/services/Volumes.php +++ b/src/services/Volumes.php @@ -723,7 +723,7 @@ private function _createVolumeQuery(): Query ->orderBy(['sortOrder' => SORT_ASC]); // todo: remove schema version condition after next beakpoint - $schemaVersion = Craft::$app->getProjectConfig()->get('system.schemaVersion'); + $schemaVersion = Craft::$app->getInstalledSchemaVersion(); if (version_compare($schemaVersion, '3.1.19', '>=')) { $query->where(['dateDeleted' => null]); }