diff --git a/app/config/services.yml b/app/config/services.yml index 837558121..a69739745 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -640,7 +640,7 @@ services: tags: - {name: form.type} - AppBundle\Subscriber\TalksSitemapSubscriber: + AppBundle\Subscriber\TalksAndNewsSitemapSubscriber: arguments: - "@router" - "@ting" diff --git a/sources/AppBundle/Controller/HtmlSitemapController.php b/sources/AppBundle/Controller/HtmlSitemapController.php index 50dc3f2f1..fae85fae1 100644 --- a/sources/AppBundle/Controller/HtmlSitemapController.php +++ b/sources/AppBundle/Controller/HtmlSitemapController.php @@ -79,25 +79,20 @@ private function members(): array private function news(): array { - $itemPerPage = 100; - $page = 1; - $repository = $this->get('ting')->get(ArticleRepository::class); $news = []; - do { - $newsList = $repository->findPublishedNews($page++, $itemPerPage, []); - foreach ($newsList as $newsItem) { - $url = $this->urlGenerator->generate('news_display', [ - 'code' => $newsItem->getSlug(), - ]); - - $news[] = [ - 'name' => $newsItem->getTitle(), - 'url' => $url - ]; - } - } while (count($newsList) >= $itemPerPage); + $newsList = $repository->findAllPublishedNews(); + foreach ($newsList as $newsItem) { + $url = $this->urlGenerator->generate('news_display', [ + 'code' => $newsItem->getSlug(), + ]); + + $news[] = [ + 'name' => $newsItem->getTitle(), + 'url' => $url + ]; + } return $news; } diff --git a/sources/AppBundle/Site/Model/Repository/ArticleRepository.php b/sources/AppBundle/Site/Model/Repository/ArticleRepository.php index 9740fbb9a..8dcffbcb7 100644 --- a/sources/AppBundle/Site/Model/Repository/ArticleRepository.php +++ b/sources/AppBundle/Site/Model/Repository/ArticleRepository.php @@ -85,6 +85,15 @@ public function findPublishedNews($page, $itemsPerPage, array $filters) return $query->query($this->getCollection(new HydratorSingleObject())); } + public function findAllPublishedNews(array $filters = []) + { + list($sql, $params) = $this->getSqlPublishedNews($filters); + + return $this->getPreparedQuery($sql) + ->setParams($params) + ->query($this->getCollection(new HydratorSingleObject())); + } + public function findPrevious(Article $article) { if (null === ($publishedAt = $article->getPublishedAt())) { diff --git a/sources/AppBundle/Subscriber/TalksSitemapSubscriber.php b/sources/AppBundle/Subscriber/TalksAndNewsSitemapSubscriber.php similarity index 67% rename from sources/AppBundle/Subscriber/TalksSitemapSubscriber.php rename to sources/AppBundle/Subscriber/TalksAndNewsSitemapSubscriber.php index b1877fc4d..0ce2ca21b 100644 --- a/sources/AppBundle/Subscriber/TalksSitemapSubscriber.php +++ b/sources/AppBundle/Subscriber/TalksAndNewsSitemapSubscriber.php @@ -4,6 +4,8 @@ use AppBundle\Event\Model\Repository\TalkRepository; use AppBundle\Event\Model\Talk; +use AppBundle\Site\Model\Article; +use AppBundle\Site\Model\Repository\ArticleRepository; use CCMBenchmark\TingBundle\Repository\RepositoryFactory; use Presta\SitemapBundle\Event\SitemapPopulateEvent; use Presta\SitemapBundle\Service\UrlContainerInterface; @@ -11,7 +13,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -class TalksSitemapSubscriber implements EventSubscriberInterface +class TalksAndNewsSitemapSubscriber implements EventSubscriberInterface { /** @var RepositoryFactory */ private $ting; @@ -35,6 +37,7 @@ public static function getSubscribedEvents() public function populate(SitemapPopulateEvent $event) { $this->registerTalksUrls($event->getUrlContainer()); + $this->registerNewsUrls($event->getUrlContainer()); } public function registerTalksUrls(UrlContainerInterface $urls) @@ -58,4 +61,24 @@ public function registerTalksUrls(UrlContainerInterface $urls) } } } + + public function registerNewsUrls(UrlContainerInterface $urls) + { + $news = $this->ting->get(ArticleRepository::class)->findAllPublishedNews(); + + /** @var Article $article */ + foreach ($news as $article) { + $urls->addUrl( + new UrlConcrete( + $this->urlGenerator->generate( + 'news_display', + ['code' => $article->getSlug(),], + UrlGeneratorInterface::ABSOLUTE_URL + ), + $article->getPublishedAt() + ), + 'news' + ); + } + } }