Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
) {}

Expand Down Expand Up @@ -90,12 +91,15 @@ private function news(): array
return $news;
}

/**
* @return list<array{name: string, url: string}>
*/
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',
Expand Down
13 changes: 0 additions & 13 deletions sources/AppBundle/Event/Model/Repository/TalkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> $talkIds
* @return CollectionInterface<Talk>
Expand Down
47 changes: 47 additions & 0 deletions sources/AppBundle/Event/Talk/PublishedTalkRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Talk;

use AppBundle\Event\Model\Talk;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Webmozart\Assert\Assert;

final readonly class PublishedTalkRepository
{
public function __construct(private Connection $connection) {}

/**
* Identifiants des talks publiés : terminés avant la date donnée et visibles dans l'historique
* (planifiés, ni clinique, ni présentation des speakers, cf. Talk::isDisplayedOnHistory()).
* Un talk planifié sur plusieurs créneaux n'apparaît 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 list<int>
*/
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);
}
}
11 changes: 4 additions & 7 deletions sources/AppBundle/Subscriber/SitemapXmlSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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',
Expand Down
37 changes: 37 additions & 0 deletions tests/behat/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,41 @@ private function findJsonLd(string $type): ?array

return $found;
}

#[Then('/^every link matching "(?P<pattern>(?:[^"]|\\")*)" should respond with status (?P<code>\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(),
);
}
}
}
8 changes: 8 additions & 0 deletions tests/behat/features/PublicSite/Sitemaps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ Feature: Site Public - Sitemaps
Given I am on "/sitemap.default.xml"
And the response should contain "<loc>https://apachephptest:80/</loc>"
And the response should not contain "<loc>https://apachephptest:80/home</loc>"

@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
Loading