Skip to content

Commit

Permalink
FIX Don't hardcode table name (#629)
Browse files Browse the repository at this point in the history
BlogFilter had some hardcoded references to BlogPost table; when you rename this table, e.g. to "News", some joins broke.
  • Loading branch information
wernerkrauss authored May 10, 2024
1 parent 799cc44 commit bad865d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Model/BlogFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ public function stageChildren($showAll = false)
$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())));

Expand All @@ -64,10 +65,11 @@ public function liveChildren($showAll = false, $onlyDeletedFromStage = false)
$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())));

Expand Down

0 comments on commit bad865d

Please sign in to comment.