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..49e081d55 100644 --- a/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php +++ b/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php @@ -7,7 +7,7 @@ use Afup\Site\Corporate\Feuille; use AppBundle\Association\Model\Repository\CompanyMemberRepository; use AppBundle\Event\Model\Repository\TalkRepository; -use AppBundle\Event\Model\Talk; +use AppBundle\Event\Talk\PublishedTalkRepository; use AppBundle\Site\Entity\Repository\ArticleRepository; use AppBundle\Site\Entity\Repository\FeuilleRepository; use AppBundle\Twig\ViewRenderer; @@ -21,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, ) {} @@ -90,12 +91,15 @@ private function news(): array return $news; } + /** + * @return list + */ private function talks(): array { $talks = []; - $talkList = $this->talkRepository->getAllPastTalks(new \DateTime()->setTime(29, 59, 59)); + $talkIds = $this->publishedTalkRepository->getIdsEndedBefore(new \DateTimeImmutable()->setTime(23, 59, 59)); + $talkList = $talkIds === [] ? [] : $this->talkRepository->findList($talkIds); - /** @var Talk $talk */ foreach ($talkList as $talk) { $url = $this->generateUrl( 'talks_show', diff --git a/sources/AppBundle/Event/Model/Repository/TalkRepository.php b/sources/AppBundle/Event/Model/Repository/TalkRepository.php index 967add9b4..295e7ca7d 100644 --- a/sources/AppBundle/Event/Model/Repository/TalkRepository.php +++ b/sources/AppBundle/Event/Model/Repository/TalkRepository.php @@ -380,19 +380,6 @@ public function getScheduledTalksByEvent(int $eventId): CollectionInterface return $query->query($this->getCollection(new HydratorSingleObject())); } - public function getAllPastTalks(\DateTime $dateTime) - { - $query = $this->getPreparedQuery( - ' - SELECT talk.* - FROM afup_sessions AS talk - LEFT JOIN afup_forum_planning afp ON talk.session_id = afp.id_session - WHERE afp.fin <= :date_fin', - )->setParams(['date_fin' => $dateTime->format('U')]); - - return $query->query($this->getCollection(new HydratorSingleObject())); - } - /** * @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 49bc304bc..f1de09adf 100644 --- a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php +++ b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php @@ -13,7 +13,7 @@ use AppBundle\Event\Model\Repository\SpeakerRepository; use AppBundle\Event\Model\Repository\TalkRepository; use AppBundle\Event\Model\Speaker; -use AppBundle\Event\Model\Talk; +use AppBundle\Event\Talk\PublishedTalkRepository; use AppBundle\Site\Entity\Repository\FeuilleRepository; use AppBundle\Site\Entity\Repository\ArticleRepository; use Presta\SitemapBundle\Event\SitemapPopulateEvent; @@ -29,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, @@ -55,14 +56,10 @@ public function populate(SitemapPopulateEvent $event): void public function registerTalksUrls(UrlContainerInterface $urls): void { - /** @var Talk[] $talks */ - $talks = $this->talkRepository->getAllPastTalks(new \DateTime()); + $talkIds = $this->publishedTalkRepository->getIdsEndedBefore(new \DateTimeImmutable()); + $talks = $talkIds === [] ? [] : $this->talkRepository->findList($talkIds); foreach ($talks as $talk) { - if (!$talk->isDisplayedOnHistory()) { - continue; - } - $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