Skip to content

Commit

Permalink
getInstalledSchemaVersion()
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jun 26, 2019
1 parent 5613536 commit 6f62cb9
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.2.md
Expand Up @@ -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`.
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG-v3.md
Expand Up @@ -3,6 +3,7 @@
## Unreleased

### Added
- Added `craft\base\ApplicationTrait::getInstalledSchemaVersion()`.
- Added `craft\services\Matrix::duplicateBlocks()`.

### Changed
Expand All @@ -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

Expand Down
12 changes: 12 additions & 0 deletions src/base/ApplicationTrait.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/db/SoftDeleteTrait.php
Expand Up @@ -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]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/elements/db/ElementQuery.php
Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 0 additions & 3 deletions src/migrations/Install.php
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/records/GlobalSet.php
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/records/User.php
Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/Elements.php
Expand Up @@ -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]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/Fields.php
Expand Up @@ -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']);
}
Expand All @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/Plugins.php
Expand Up @@ -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']);
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/Sections.php
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/Volumes.php
Expand Up @@ -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]);
}
Expand Down

0 comments on commit 6f62cb9

Please sign in to comment.