Skip to content

Commit 258e062

Browse files
committed
Deprecate methods in page repository and declare and use new ones
1 parent db5b7bc commit 258e062

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

src/Repository/PageRepository.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,42 @@ public function existsOneByChannelAndSlug(ChannelInterface $channel, ?string $lo
4949
return $count > 0;
5050
}
5151

52-
public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool
52+
public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug): bool
53+
{
54+
$queryBuilder = $this->createQueryBuilderExistOne($channel, $locale, $slug);
55+
$queryBuilder
56+
->andWhere('p.enabled = true')
57+
;
58+
59+
$count = (int) $queryBuilder
60+
->getQuery()
61+
->getSingleScalarResult()
62+
;
63+
64+
return $count > 0;
65+
}
66+
67+
/**
68+
* @throws NonUniqueResultException
69+
*/
70+
public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode): ?PageInterface
71+
{
72+
return $this->createQueryBuilder('p')
73+
->leftJoin('p.translations', 'translation')
74+
->innerJoin('p.channels', 'channels')
75+
->where('translation.locale = :localeCode')
76+
->andWhere('translation.slug = :slug')
77+
->andWhere('channels.code = :channelCode')
78+
->andWhere('p.enabled = true')
79+
->setParameter('localeCode', $localeCode)
80+
->setParameter('slug', $slug)
81+
->setParameter('channelCode', $channelCode)
82+
->getQuery()
83+
->getOneOrNullResult()
84+
;
85+
}
86+
87+
public function existsOneEnabledAndPublishedByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool
5388
{
5489
$queryBuilder = $this->createQueryBuilderExistOne($channel, $locale, $slug);
5590
$queryBuilder
@@ -70,7 +105,7 @@ public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?str
70105
/**
71106
* @throws NonUniqueResultException
72107
*/
73-
public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode, DateTimeInterface $dateTime): ?PageInterface
108+
public function findOneEnabledAndPublishedBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode, DateTimeInterface $dateTime): ?PageInterface
74109
{
75110
return $this->createQueryBuilder('p')
76111
->leftJoin('p.translations', 'translation')

src/Repository/PageRepositoryInterface.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ public function createListQueryBuilder(string $localeCode): QueryBuilder;
2525

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

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

30-
public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode, DateTimeInterface $dateTime): ?PageInterface;
31+
/** @deprecated Use findOneEnabledAndPublishedBySlugAndChannelCode */
32+
public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode): ?PageInterface;
33+
34+
public function existsOneEnabledAndPublishedByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool;
35+
36+
public function findOneEnabledAndPublishedBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode, DateTimeInterface $dateTime): ?PageInterface;
3137
}

src/Resources/config/routing/shop.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ monsieurbiz_cms_page_show:
77
_sylius:
88
template: "@MonsieurBizSyliusCmsPagePlugin/Shop/Page/show.html.twig"
99
repository:
10-
method: findOneEnabledBySlugAndChannelCode
10+
method: findOneEnabledAndPublishedBySlugAndChannelCode
1111
arguments:
1212
- $slug
1313
- "expr:service('sylius.context.locale').getLocaleCode()"

src/Routing/PageSlugConditionChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(
5959
public function isPageSlug(string $slug): bool
6060
{
6161
try {
62-
return $this->pageRepository->existsOneEnabledByChannelAndSlug(
62+
return $this->pageRepository->existsOneEnabledAndPublishedByChannelAndSlug(
6363
$this->channelContext->getChannel(),
6464
$this->localeContext->getLocaleCode(),
6565
$slug,

0 commit comments

Comments
 (0)