diff --git a/CHANGELOG.md b/CHANGELOG.md index f547f60..2e1d939 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ -## [Unreleased] 1.0.6 +## 1.0.6 - 2020-01-15 ### Fixed - Fix issue with pgsql when usage column is enabled +- Disable usage column on MySQL installs ## 1.0.5 - 2019-06-26 ### Added diff --git a/src/elements/db/TagQuery.php b/src/elements/db/TagQuery.php index 8d856a9..bceaddf 100644 --- a/src/elements/db/TagQuery.php +++ b/src/elements/db/TagQuery.php @@ -8,6 +8,7 @@ namespace ether\tagManager\elements\db; +use Craft; use ether\tagManager\TagManager; use yii\db\Expression; @@ -22,6 +23,9 @@ class TagQuery extends \craft\elements\db\TagQuery protected function afterPrepare (): bool { + if (Craft::$app->getDb()->getDriverName() === 'mysql') + return parent::afterPrepare(); + if (!TagManager::getInstance()->getSettings()->enableUsage) return parent::afterPrepare(); @@ -29,7 +33,7 @@ protected function afterPrepare (): bool return parent::afterPrepare(); $getUsage = new Expression( - '(SELECT COUNT(*) FROM (SELECT [[r.sourceId]], [[r.sourceSiteId]] FROM {{%relations}} r WHERE [[r.targetId]] = [[elements.id]] GROUP BY [[r.sourceId]], [[r.sourceSiteId]]) as usage) as [[usage]]' + '(SELECT COUNT(*) FROM (SELECT [[r.sourceId]], [[r.sourceSiteId]] FROM {{%relations}} r WHERE [[r.targetId]] = [[elements.id]] GROUP BY [[r.sourceId]], [[r.sourceSiteId]]) as [[usage]]) as [[usage]]' ); $this->query->addSelect(new Expression('[[subquery.usage]] as [[usage]]')); diff --git a/src/templates/_settings.twig b/src/templates/_settings.twig index b702c8c..2dd567c 100644 --- a/src/templates/_settings.twig +++ b/src/templates/_settings.twig @@ -2,8 +2,9 @@ {{ forms.lightswitchField({ label: 'Enable Usage'|t('tag-manager'), - instructions: 'Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).'|t('tag-manager'), + instructions: '**[PostgreSQL Only]** Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).'|t('tag-manager'), name: 'enableUsage', - on: settings.enableUsage, + on: craft.app.db.driverName == 'pgsql' and settings.enableUsage, first: true, + disabled: craft.app.db.driverName == 'mysql' }) }} \ No newline at end of file diff --git a/src/translations/en/tag-manager.php b/src/translations/en/tag-manager.php index 1fc5c58..c23affe 100644 --- a/src/translations/en/tag-manager.php +++ b/src/translations/en/tag-manager.php @@ -9,6 +9,6 @@ return [ 'Usage' => 'Usage', 'Enable Usage' => 'Enable Usage', - 'Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).' => - 'Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).', + '**[PostgreSQL Only]** Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).' => + '**[PostgreSQL Only]** Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).', ]; \ No newline at end of file