From e3132ff59dff732d5f1b02eb801ec6d3a69a5821 Mon Sep 17 00:00:00 2001 From: Xavier Leune Date: Tue, 17 Nov 2026 15:35:11 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Retire=20les=20talks=20non=20publi=C3=A9s?= =?UTF-8?q?=20du=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 3a68ab9eb..0d113b170 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -3673,12 +3673,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', @@ -3715,12 +3709,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', @@ -5287,12 +5275,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 967add9b4..d75d79ccc 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 cd61bdd11..8628a08c2 100644 --- a/tests/behat/bootstrap/FeatureContext.php +++ b/tests/behat/bootstrap/FeatureContext.php @@ -446,4 +446,41 @@ private function findJsonLd(string $type): ?array return $found; } + + #[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 4a421021c..16fec0aba 100644 --- a/tests/behat/features/PublicSite/Sitemaps.feature +++ b/tests/behat/features/PublicSite/Sitemaps.feature @@ -37,3 +37,11 @@ Feature: Site Public - Sitemaps Given I am on "/sitemap.default.xml" And the response should contain "https://apachephptest:80/" And the response should not 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 From 9957eb1e1b2f5f8831131de8de484d210ff26f6d Mon Sep 17 00:00:00 2001 From: Xavier Leune Date: Fri, 20 Nov 2026 15:21:51 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Passe=20la=20requ=C3=AAte=20des=20talks=20p?= =?UTF-8?q?ubli=C3=A9s=20en=20DBAL=20suivant=20l'ADR-002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Website/Global/HtmlSitemapAction.php | 9 ++-- .../Event/Model/Repository/TalkRepository.php | 32 ------------- .../Event/Talk/PublishedTalkRepository.php | 47 +++++++++++++++++++ .../Subscriber/SitemapXmlSubscriber.php | 7 ++- 4 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 sources/AppBundle/Event/Talk/PublishedTalkRepository.php diff --git a/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php b/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php index c3aaade21..49e081d55 100644 --- a/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php +++ b/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php @@ -7,6 +7,7 @@ use Afup\Site\Corporate\Feuille; use AppBundle\Association\Model\Repository\CompanyMemberRepository; use AppBundle\Event\Model\Repository\TalkRepository; +use AppBundle\Event\Talk\PublishedTalkRepository; use AppBundle\Site\Entity\Repository\ArticleRepository; use AppBundle\Site\Entity\Repository\FeuilleRepository; use AppBundle\Twig\ViewRenderer; @@ -20,6 +21,7 @@ public function __construct( private readonly CompanyMemberRepository $companyMemberRepository, private readonly ArticleRepository $articleRepository, private readonly TalkRepository $talkRepository, + private readonly PublishedTalkRepository $publishedTalkRepository, private readonly FeuilleRepository $feuilleRepository, ) {} @@ -95,12 +97,13 @@ private function news(): array private function talks(): array { $talks = []; - $talkList = $this->talkRepository->getPublishedTalks(new \DateTimeImmutable()->setTime(23, 59, 59)); + $talkIds = $this->publishedTalkRepository->getIdsEndedBefore(new \DateTimeImmutable()->setTime(23, 59, 59)); + $talkList = $talkIds === [] ? [] : $this->talkRepository->findList($talkIds); - foreach ($talkList as $talkId => $talk) { + foreach ($talkList as $talk) { $url = $this->generateUrl( 'talks_show', - ['id' => $talkId, 'slug' => $talk->getSlug()], + ['id' => $talk->getId(), 'slug' => $talk->getSlug()], ); $talks[] = [ diff --git a/sources/AppBundle/Event/Model/Repository/TalkRepository.php b/sources/AppBundle/Event/Model/Repository/TalkRepository.php index d75d79ccc..295e7ca7d 100644 --- a/sources/AppBundle/Event/Model/Repository/TalkRepository.php +++ b/sources/AppBundle/Event/Model/Repository/TalkRepository.php @@ -380,38 +380,6 @@ public function getScheduledTalksByEvent(int $eventId): CollectionInterface return $query->query($this->getCollection(new HydratorSingleObject())); } - /** - * 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 - INNER JOIN afup_forum_planning afp ON talk.session_id = afp.id_session - WHERE afp.fin <= :date_fin', - )->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 $publishedTalks; - } - /** * @param array $talkIds * @return CollectionInterface diff --git a/sources/AppBundle/Event/Talk/PublishedTalkRepository.php b/sources/AppBundle/Event/Talk/PublishedTalkRepository.php new file mode 100644 index 000000000..51cd49a30 --- /dev/null +++ b/sources/AppBundle/Event/Talk/PublishedTalkRepository.php @@ -0,0 +1,47 @@ + + */ + public function getIdsEndedBefore(\DateTimeInterface $endedBefore): array + { + $qb = $this->connection->createQueryBuilder(); + + $ids = $qb + ->select('DISTINCT talk.session_id') + ->from('afup_sessions', 'talk') + ->innerJoin('talk', 'afup_forum_planning', 'planning', 'planning.id_session = talk.session_id') + ->where('planning.fin <= :endedBefore') + ->andWhere('talk.plannifie = 1') + ->andWhere($qb->expr()->notIn('talk.genre', ':hiddenTypes')) + ->orderBy('talk.session_id') + ->setParameter('endedBefore', $endedBefore->getTimestamp()) + ->setParameter('hiddenTypes', [Talk::TYPE_CLINIC, Talk::TYPE_SPEAKER_INTRODUCTIONS], ArrayParameterType::INTEGER) + ->executeQuery() + ->fetchFirstColumn(); + + Assert::allIntegerish($ids); + + return array_map(intval(...), $ids); + } +} diff --git a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php index af77b9c16..f1de09adf 100644 --- a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php +++ b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php @@ -13,6 +13,7 @@ use AppBundle\Event\Model\Repository\SpeakerRepository; use AppBundle\Event\Model\Repository\TalkRepository; use AppBundle\Event\Model\Speaker; +use AppBundle\Event\Talk\PublishedTalkRepository; use AppBundle\Site\Entity\Repository\FeuilleRepository; use AppBundle\Site\Entity\Repository\ArticleRepository; use Presta\SitemapBundle\Event\SitemapPopulateEvent; @@ -28,6 +29,7 @@ class SitemapXmlSubscriber implements EventSubscriberInterface public function __construct( private readonly UrlGeneratorInterface $urlGenerator, private readonly TalkRepository $talkRepository, + private readonly PublishedTalkRepository $publishedTalkRepository, private readonly SpeakerRepository $speakerRepository, private readonly EventRepository $eventRepository, private readonly ArticleRepository $articleRepository, @@ -54,7 +56,10 @@ public function populate(SitemapPopulateEvent $event): void public function registerTalksUrls(UrlContainerInterface $urls): void { - foreach ($this->talkRepository->getPublishedTalks(new \DateTimeImmutable()) as $talk) { + $talkIds = $this->publishedTalkRepository->getIdsEndedBefore(new \DateTimeImmutable()); + $talks = $talkIds === [] ? [] : $this->talkRepository->findList($talkIds); + + foreach ($talks as $talk) { $url = new UrlConcrete( $this->urlGenerator->generate( 'talks_show',