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.
This commit is contained in:
Werner Krauß 2024-05-10 06:05:41 +02:00 committed by GitHub
parent 799cc44b46
commit bad865dc65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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())));