cannot loop over children with renamed table

BlogFilter had some hardcoded references to BlogPost table; when you rename this table, e.g. to "News", some joins broke.

fixes #628
This commit is contained in:
Werner M. Krauß 2020-10-28 11:28:23 +01:00
parent 5b14e0b1bd
commit 1fa3b84702
1 changed files with 6 additions and 4 deletions

View File

@ -36,10 +36,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())));
@ -65,10 +66,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())));