From bad865dc65fcf4cd95289c6127c11aea4f394f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Werner=20Krau=C3=9F?= Date: Fri, 10 May 2024 06:05:41 +0200 Subject: [PATCH] FIX Don't hardcode table name (#629) BlogFilter had some hardcoded references to BlogPost table; when you rename this table, e.g. to "News", some joins broke. --- src/Model/BlogFilter.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Model/BlogFilter.php b/src/Model/BlogFilter.php index 62e5801..fe2e642 100644 --- a/src/Model/BlogFilter.php +++ b/src/Model/BlogFilter.php @@ -35,10 +35,11 @@ class BlogFilter extends Lumberjack $stage = '_' . $stage; } + $blogPostTable = DataObject::getSchema()->tableName(BlogPost::class); $dataQuery = $staged->dataQuery() ->innerJoin( - DataObject::getSchema()->tableName(BlogPost::class), - sprintf('"BlogPost%s"."ID" = "SiteTree%s"."ID"', $stage, $stage) + $blogPostTable, + sprintf('"' . $blogPostTable . '%s"."ID" = "SiteTree%s"."ID"', $stage, $stage) ) ->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now()))); @@ -64,10 +65,11 @@ class BlogFilter extends Lumberjack $staged = parent::liveChildren($showAll, $onlyDeletedFromStage); if (!$this->shouldFilter() && $this->isBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) { + $blogPostTable = DataObject::getSchema()->tableName(BlogPost::class); $dataQuery = $staged->dataQuery() ->innerJoin( - DataObject::getSchema()->tableName(BlogPost::class), - '"BlogPost_Live"."ID" = "SiteTree_Live"."ID"' + $blogPostTable, + '"' . $blogPostTable . '_Live"."ID" = "SiteTree_Live"."ID"' ) ->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now())));