Skip to content

Commit 8f57073

Browse files
committed
Disable usage column on MySQL installs
Closes #12
1 parent 7f2773f commit 8f57073

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## [Unreleased] 1.0.6
1+
## 1.0.6 - 2020-01-15
22
### Fixed
33
- Fix issue with pgsql when usage column is enabled
4+
- Disable usage column on MySQL installs
45

56
## 1.0.5 - 2019-06-26
67
### Added

src/elements/db/TagQuery.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace ether\tagManager\elements\db;
1010

11+
use Craft;
1112
use ether\tagManager\TagManager;
1213
use yii\db\Expression;
1314

@@ -22,14 +23,17 @@ class TagQuery extends \craft\elements\db\TagQuery
2223

2324
protected function afterPrepare (): bool
2425
{
26+
if (Craft::$app->getDb()->getDriverName() === 'mysql')
27+
return parent::afterPrepare();
28+
2529
if (!TagManager::getInstance()->getSettings()->enableUsage)
2630
return parent::afterPrepare();
2731

2832
if (count($this->query->select) === 1 && strtoupper($this->query->select[0]) === 'COUNT(*)')
2933
return parent::afterPrepare();
3034

3135
$getUsage = new Expression(
32-
'(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]]'
36+
'(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]]'
3337
);
3438

3539
$this->query->addSelect(new Expression('[[subquery.usage]] as [[usage]]'));

src/templates/_settings.twig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
{{ forms.lightswitchField({
44
label: 'Enable Usage'|t('tag-manager'),
5-
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'),
5+
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'),
66
name: 'enableUsage',
7-
on: settings.enableUsage,
7+
on: craft.app.db.driverName == 'pgsql' and settings.enableUsage,
88
first: true,
9+
disabled: craft.app.db.driverName == 'mysql'
910
}) }}

src/translations/en/tag-manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
return [
1010
'Usage' => 'Usage',
1111
'Enable Usage' => 'Enable Usage',
12-
'Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).' =>
13-
'Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).',
12+
'**[PostgreSQL Only]** Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).' =>
13+
'**[PostgreSQL Only]** Will enable the usage column in the CP (has no effect on regular tag queries, may be slow on larger sites).',
1414
];

0 commit comments

Comments
 (0)