From be9008b0d8fa60a5b37a8b5c5b515b4d9b160de5 Mon Sep 17 00:00:00 2001 From: bencroker Date: Mon, 5 Aug 2024 14:24:41 +0200 Subject: [PATCH] Use column aliases in inner joins --- CHANGELOG.md | 6 ++++++ composer.json | 2 +- src/helpers/DiagnosticsHelper.php | 22 +++++++++++----------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2e37ad3..451e9269 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release Notes for Blitz +## 5.6.2 - 2024-08-05 + +### Fixed + +- Fixed a bug that could throw an exception when viewing tracked entries in the Blitz Diagnostics utility when the database tables have a prefix. + ## 5.6.1 - 2024-08-05 ### Fixed diff --git a/composer.json b/composer.json index f4e42594..9ca1712c 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "putyourlightson/craft-blitz", "description": "Intelligent static page caching for creating lightning-fast sites.", - "version": "5.6.1", + "version": "5.6.2", "type": "craft-plugin", "homepage": "https://putyourlightson.com/plugins/blitz", "license": "proprietary", diff --git a/src/helpers/DiagnosticsHelper.php b/src/helpers/DiagnosticsHelper.php index 951be18e..ac937bd0 100644 --- a/src/helpers/DiagnosticsHelper.php +++ b/src/helpers/DiagnosticsHelper.php @@ -251,8 +251,8 @@ public static function getElementsQuery(int $siteId, string $elementType, ?int $ { $condition = [ 'and', - [CacheRecord::tableName() . '.siteId' => $siteId], - [Table::ELEMENTS_SITES . '.siteId' => $siteId], + ['caches.siteId' => $siteId], + ['elementsites.siteId' => $siteId], ['type' => $elementType], ['elements_owners.ownerId' => null], ]; @@ -264,9 +264,9 @@ public static function getElementsQuery(int $siteId, string $elementType, ?int $ return ElementCacheRecord::find() ->from(['elementcaches' => ElementCacheRecord::tableName()]) ->select(['elementcaches.elementId', 'elementexpirydates.expiryDate', 'count(*) as count', 'title']) - ->innerJoinWith('cache') - ->innerJoinWith('element') - ->innerJoinWith('elementSite') + ->innerJoinWith('cache caches') + ->innerJoinWith('element elements') + ->innerJoinWith('elementSite elementsites') ->leftJoin(['elementexpirydates' => ElementExpiryDateRecord::tableName()], '[[elementexpirydates.elementId]] = [[elementcaches.elementId]]') ->leftJoin(['elements_owners' => Table::ELEMENTS_OWNERS], '[[elementcaches.elementId]] = [[elements_owners.elementId]]') ->where($condition) @@ -278,8 +278,8 @@ public static function getNestedElementsQuery(int $siteId, string $elementType, { $condition = [ 'and', - [CacheRecord::tableName() . '.siteId' => $siteId], - [Table::ELEMENTS_SITES . '.siteId' => $siteId], + ['caches.siteId' => $siteId], + ['elementsites.siteId' => $siteId], ['type' => $elementType], ['not', ['elements_owners.ownerId' => null]], ]; @@ -290,10 +290,10 @@ public static function getNestedElementsQuery(int $siteId, string $elementType, return ElementCacheRecord::find() ->from(['elementcaches' => ElementCacheRecord::tableName()]) - ->select(['elementcaches.elementId', 'elementexpirydates.expiryDate', 'count(*) as count', Table::ELEMENTS_SITES . '.title', 'sortOrder', 'ownerTitle' => 'elements_owners_sites.title', 'entryType' => 'entrytypes.name']) - ->innerJoinWith('cache') - ->innerJoinWith('element') - ->innerJoinWith('elementSite') + ->select(['elementcaches.elementId', 'elementexpirydates.expiryDate', 'count(*) as count', 'elementsites.title', 'sortOrder', 'ownerTitle' => 'elements_owners_sites.title', 'entryType' => 'entrytypes.name']) + ->innerJoinWith('cache caches') + ->innerJoinWith('element elements') + ->innerJoinWith('elementSite elementsites') ->leftJoin(['elementexpirydates' => ElementExpiryDateRecord::tableName()], '[[elementexpirydates.elementId]] = [[elementcaches.elementId]]') ->leftJoin(['elements_owners' => Table::ELEMENTS_OWNERS], '[[elementcaches.elementId]] = [[elements_owners.elementId]]') ->leftJoin(['elements_owners_sites' => Table::ELEMENTS_SITES], '[[elements_owners.ownerId]] = [[elements_owners_sites.elementId]]')