Skip to content

Commit

Permalink
Merge pull request #1338 from bolt/bugfix/empty-viewless-api
Browse files Browse the repository at this point in the history
API works if no viewless CTs exist
  • Loading branch information
bobdenotter authored Apr 29, 2020
2 parents 979fa8f + 7772255 commit 411b735
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Api/Extensions/ContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,25 @@ private function filterUnpublishedViewlessContent(QueryBuilder $queryBuilder): v
{
$rootAlias = $queryBuilder->getRootAliases()[0];
$queryBuilder->andWhere(sprintf('%s.status = :status', $rootAlias));
$queryBuilder->andWhere(sprintf('%s.contentType NOT IN (:cts)', $rootAlias));
$queryBuilder->setParameter('status', Statuses::PUBLISHED);
$queryBuilder->setParameter('cts', $this->viewlessContentTypes);

//todo: Fix this when https://github.com/doctrine/orm/issues/3835 closed.
if (! empty($this->viewlessContentTypes)) {
$queryBuilder->andWhere(sprintf('%s.contentType NOT IN (:cts)', $rootAlias));
$queryBuilder->setParameter('cts', $this->viewlessContentTypes);
}
}

private function filterUnpublishedViewlessFields(QueryBuilder $queryBuilder): void
{
$rootAlias = $queryBuilder->getRootAliases()[0];
$queryBuilder->join($rootAlias . '.content', 'c', Join::WITH, 'c.status = :status AND c.contentType NOT IN (:cts)');
$queryBuilder->join($rootAlias . '.content', 'c', Join::WITH, 'c.status = :status');
$queryBuilder->setParameter('status', Statuses::PUBLISHED);
$queryBuilder->setParameter('cts', $this->viewlessContentTypes);

//todo: Fix this when https://github.com/doctrine/orm/issues/3835 closed.
if (! empty($this->viewlessContentTypes)) {
$queryBuilder->andWhere('c.contentType NOT IN (:cts)');
$queryBuilder->setParameter('cts', $this->viewlessContentTypes);
}
}
}

0 comments on commit 411b735

Please sign in to comment.