Skip to content

Commit

Permalink
Deprecate methods in page repository and declare and use new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Dec 3, 2024
1 parent db5b7bc commit 258e062
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
39 changes: 37 additions & 2 deletions src/Repository/PageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,42 @@ public function existsOneByChannelAndSlug(ChannelInterface $channel, ?string $lo
return $count > 0;
}

public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool
public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug): bool
{
$queryBuilder = $this->createQueryBuilderExistOne($channel, $locale, $slug);
$queryBuilder
->andWhere('p.enabled = true')
;

$count = (int) $queryBuilder
->getQuery()
->getSingleScalarResult()
;

return $count > 0;
}

/**
* @throws NonUniqueResultException
*/
public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode): ?PageInterface
{
return $this->createQueryBuilder('p')
->leftJoin('p.translations', 'translation')
->innerJoin('p.channels', 'channels')
->where('translation.locale = :localeCode')
->andWhere('translation.slug = :slug')
->andWhere('channels.code = :channelCode')
->andWhere('p.enabled = true')
->setParameter('localeCode', $localeCode)
->setParameter('slug', $slug)
->setParameter('channelCode', $channelCode)
->getQuery()
->getOneOrNullResult()
;
}

public function existsOneEnabledAndPublishedByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool
{
$queryBuilder = $this->createQueryBuilderExistOne($channel, $locale, $slug);
$queryBuilder
Expand All @@ -70,7 +105,7 @@ public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?str
/**
* @throws NonUniqueResultException
*/
public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode, DateTimeInterface $dateTime): ?PageInterface
public function findOneEnabledAndPublishedBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode, DateTimeInterface $dateTime): ?PageInterface
{
return $this->createQueryBuilder('p')
->leftJoin('p.translations', 'translation')
Expand Down
10 changes: 8 additions & 2 deletions src/Repository/PageRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public function createListQueryBuilder(string $localeCode): QueryBuilder;

public function existsOneByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, array $excludedPages = []): bool;

public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool;
/** @deprecated Use existsOneEnabledAndPublishedByChannelAndSlug */
public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug): bool;

public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode, DateTimeInterface $dateTime): ?PageInterface;
/** @deprecated Use findOneEnabledAndPublishedBySlugAndChannelCode */
public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode): ?PageInterface;

public function existsOneEnabledAndPublishedByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool;

public function findOneEnabledAndPublishedBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode, DateTimeInterface $dateTime): ?PageInterface;
}
2 changes: 1 addition & 1 deletion src/Resources/config/routing/shop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ monsieurbiz_cms_page_show:
_sylius:
template: "@MonsieurBizSyliusCmsPagePlugin/Shop/Page/show.html.twig"
repository:
method: findOneEnabledBySlugAndChannelCode
method: findOneEnabledAndPublishedBySlugAndChannelCode
arguments:
- $slug
- "expr:service('sylius.context.locale').getLocaleCode()"
Expand Down
2 changes: 1 addition & 1 deletion src/Routing/PageSlugConditionChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(
public function isPageSlug(string $slug): bool
{
try {
return $this->pageRepository->existsOneEnabledByChannelAndSlug(
return $this->pageRepository->existsOneEnabledAndPublishedByChannelAndSlug(
$this->channelContext->getChannel(),
$this->localeContext->getLocaleCode(),
$slug,
Expand Down

0 comments on commit 258e062

Please sign in to comment.