From c2c3c255463d43d841e4406f58fdcf7c40531305 Mon Sep 17 00:00:00 2001 From: Xavier Leune Date: Tue, 17 Nov 2026 15:35:11 +0100 Subject: [PATCH] =?UTF-8?q?Retire=20les=20talks=20non=20publi=C3=A9s=20du?= =?UTF-8?q?=20plan=20du=20site?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le plan du site listait tous les talks dont le créneau était passé, y compris les cliniques, les présentations des speakers et les talks non planifiés : leur page répond 404 (ShowAction exige isDisplayedOnHistory()). La date de coupure utilisait en outre setTime(29, 59, 59), soit le lendemain à 5 h 59. La récupération des talks publiés est factorisée dans TalkRepository::getPublishedTalks() (talks terminés, visibles dans l'historique, dédoublonnés par identifiant), qui remplace getAllPastTalks() et sert désormais de source commune au plan du site et au sitemap XML. La coupure du plan du site passe à 23:59:59. Un step Behat vérifie que chaque lien /talks/{id}-{slug} du plan du site répond 200. --- phpstan-baseline.php | 18 --------- .../Website/Global/HtmlSitemapAction.php | 11 +++--- .../Event/Model/Repository/TalkRepository.php | 27 ++++++++++++-- .../Subscriber/SitemapXmlSubscriber.php | 10 +---- tests/behat/bootstrap/FeatureContext.php | 37 +++++++++++++++++++ .../features/PublicSite/Sitemaps.feature | 8 ++++ 6 files changed, 75 insertions(+), 36 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 9bd71bd97..24aff86db 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -3733,12 +3733,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/CompanyPublicProfile/ListAction.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#', - 'identifier' => 'foreach.nonIterable', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php', -]; $ignoreErrors[] = [ 'message' => '#^Cannot call method getCompanyName\\(\\) on mixed\\.$#', 'identifier' => 'method.nonObject', @@ -3775,12 +3769,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Controller\\\\Website\\\\Global\\\\HtmlSitemapAction\\:\\:talks\\(\\) return type has no value type specified in iterable type array\\.$#', - 'identifier' => 'missingType.iterableValue', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php', -]; $ignoreErrors[] = [ 'message' => '#^Cannot access offset \'careers_page_url\' on mixed\\.$#', 'identifier' => 'offsetAccess.nonOffsetAccessible', @@ -5461,12 +5449,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TalkRepository.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TalkRepository\\:\\:getAllPastTalks\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TalkRepository.php', -]; $ignoreErrors[] = [ 'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TalkRepository\\:\\:getAllTalksAndRatingsForUser\\(\\) return type with generic interface CCMBenchmark\\\\Ting\\\\Repository\\\\CollectionInterface does not specify its types\\: T$#', 'identifier' => 'missingType.generics', diff --git a/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php b/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php index b9a6ee722..c3aaade21 100644 --- a/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php +++ b/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php @@ -7,7 +7,6 @@ use Afup\Site\Corporate\Feuille; use AppBundle\Association\Model\Repository\CompanyMemberRepository; use AppBundle\Event\Model\Repository\TalkRepository; -use AppBundle\Event\Model\Talk; use AppBundle\Site\Entity\Repository\ArticleRepository; use AppBundle\Site\Entity\Repository\FeuilleRepository; use AppBundle\Twig\ViewRenderer; @@ -90,16 +89,18 @@ private function news(): array return $news; } + /** + * @return list + */ private function talks(): array { $talks = []; - $talkList = $this->talkRepository->getAllPastTalks(new \DateTime()->setTime(29, 59, 59)); + $talkList = $this->talkRepository->getPublishedTalks(new \DateTimeImmutable()->setTime(23, 59, 59)); - /** @var Talk $talk */ - foreach ($talkList as $talk) { + foreach ($talkList as $talkId => $talk) { $url = $this->generateUrl( 'talks_show', - ['id' => $talk->getId(), 'slug' => $talk->getSlug()], + ['id' => $talkId, 'slug' => $talk->getSlug()], ); $talks[] = [ diff --git a/sources/AppBundle/Event/Model/Repository/TalkRepository.php b/sources/AppBundle/Event/Model/Repository/TalkRepository.php index ef8d029ae..0f0474ae8 100644 --- a/sources/AppBundle/Event/Model/Repository/TalkRepository.php +++ b/sources/AppBundle/Event/Model/Repository/TalkRepository.php @@ -380,17 +380,36 @@ public function getScheduledTalksByEvent(int $eventId): CollectionInterface return $query->query($this->getCollection(new HydratorSingleObject())); } - public function getAllPastTalks(\DateTime $dateTime) + /** + * Talks publiés : terminés avant la date donnée et visibles dans l'historique + * (ni clinique, ni présentation des speakers, et planifiés), indexés par + * identifiant pour qu'un talk planifié sur plusieurs créneaux n'apparaisse qu'une fois. + * + * Source commune du plan du site et du sitemap XML : chaque talk renvoyé a une page + * `talks_show` qui répond 200. + * + * @return array + */ + public function getPublishedTalks(\DateTimeInterface $endedBefore): array { $query = $this->getPreparedQuery( ' SELECT talk.* FROM afup_sessions AS talk - LEFT JOIN afup_forum_planning afp ON talk.session_id = afp.id_session + INNER JOIN afup_forum_planning afp ON talk.session_id = afp.id_session WHERE afp.fin <= :date_fin', - )->setParams(['date_fin' => $dateTime->format('U')]); + )->setParams(['date_fin' => $endedBefore->format('U')]); + + $publishedTalks = []; + /** @var Talk $talk */ + foreach ($query->query($this->getCollection(new HydratorSingleObject())) as $talk) { + $talkId = $talk->getId(); + if ($talkId !== null && $talk->isDisplayedOnHistory()) { + $publishedTalks[$talkId] = $talk; + } + } - return $query->query($this->getCollection(new HydratorSingleObject())); + return $publishedTalks; } /** diff --git a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php index 49bc304bc..af77b9c16 100644 --- a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php +++ b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php @@ -13,7 +13,6 @@ use AppBundle\Event\Model\Repository\SpeakerRepository; use AppBundle\Event\Model\Repository\TalkRepository; use AppBundle\Event\Model\Speaker; -use AppBundle\Event\Model\Talk; use AppBundle\Site\Entity\Repository\FeuilleRepository; use AppBundle\Site\Entity\Repository\ArticleRepository; use Presta\SitemapBundle\Event\SitemapPopulateEvent; @@ -55,14 +54,7 @@ public function populate(SitemapPopulateEvent $event): void public function registerTalksUrls(UrlContainerInterface $urls): void { - /** @var Talk[] $talks */ - $talks = $this->talkRepository->getAllPastTalks(new \DateTime()); - - foreach ($talks as $talk) { - if (!$talk->isDisplayedOnHistory()) { - continue; - } - + foreach ($this->talkRepository->getPublishedTalks(new \DateTimeImmutable()) as $talk) { $url = new UrlConcrete( $this->urlGenerator->generate( 'talks_show', diff --git a/tests/behat/bootstrap/FeatureContext.php b/tests/behat/bootstrap/FeatureContext.php index 4b96c2a1e..df9703d0d 100644 --- a/tests/behat/bootstrap/FeatureContext.php +++ b/tests/behat/bootstrap/FeatureContext.php @@ -327,4 +327,41 @@ public function openMenu(string $text): void $node->click(); } + + #[Then('/^every link matching "(?P(?:[^"]|\\")*)" should respond with status (?P\d+)$/')] + public function assertEveryLinkMatchingRespondsWithStatus(string $pattern, int $code): void + { + $session = $this->minkContext->getSession(); + + $urls = []; + foreach ($session->getPage()->findAll('css', 'a[href]') as $link) { + $href = (string) $link->getAttribute('href'); + if (preg_match($pattern, $href)) { + $urls[$href] = true; + } + } + + if ($urls === []) { + throw new ExpectationException( + sprintf('No link matching "%s" was found', $pattern), + $session->getDriver(), + ); + } + + $failures = []; + foreach (array_keys($urls) as $url) { + $this->minkContext->visitPath($url); + $status = $session->getStatusCode(); + if ($status !== $code) { + $failures[] = sprintf('%s (%d)', $url, $status); + } + } + + if ($failures !== []) { + throw new ExpectationException( + sprintf('%d link(s) matching "%s" did not respond with status %d: %s', count($failures), $pattern, $code, implode(', ', $failures)), + $session->getDriver(), + ); + } + } } diff --git a/tests/behat/features/PublicSite/Sitemaps.feature b/tests/behat/features/PublicSite/Sitemaps.feature index b982edecb..f3b0f9938 100644 --- a/tests/behat/features/PublicSite/Sitemaps.feature +++ b/tests/behat/features/PublicSite/Sitemaps.feature @@ -36,3 +36,11 @@ Feature: Site Public - Sitemaps Scenario: On accède sitemap default Given I am on "/sitemap.default.xml" And the response should contain "https://apachephptest:80/home" + + @reloadDbWithTestData + Scenario: Le plan du site ne lie que des talks publiés + Given I am on "/plan-du-site" + Then the response status code should be 200 + And the response should contain "/talks/1-jouons-tous-ensemble-a-un-petit-jeu" + And the response should not contain "/talks/4-une-conf-pour-voter" + And every link matching "#^/talks/\d+-[^/]+$#" should respond with status 200