Skip to content

Commit

Permalink
Merge 868374a into b5c3eeb
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed May 17, 2023
2 parents b5c3eeb + 868374a commit 5cc8055
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php
Expand Up @@ -70,6 +70,11 @@ class ContentSitemapProvider implements SitemapProviderInterface
*/
protected $alias;

/**
* @var int
*/
protected $pageSize;

/**
* @param string $kernelEnvironment Inject parameter "kernel.environment" here
* @param class-string<T> $contentRichEntityClass Classname that is used in the route table
Expand All @@ -89,11 +94,12 @@ public function __construct(
$this->contentRichEntityClass = $contentRichEntityClass;
$this->routeClass = $routeClass;
$this->alias = $alias;
$this->pageSize = self::PAGE_SIZE;
}

public function build($page, $scheme, $host): array
{
$limit = self::PAGE_SIZE;
$limit = $this->pageSize;
$offset = (int) (($page - 1) * $limit);

$portalInformations = $this->webspaceManager->findPortalInformationsByHostIncludingSubdomains(
Expand Down Expand Up @@ -162,7 +168,7 @@ public function getMaxPage($scheme, $host): int
->getQuery()
->getSingleScalarResult();

return (int) \ceil($amount / self::PAGE_SIZE);
return (int) \ceil($amount / $this->pageSize);
} catch (NoResultException|NonUniqueResultException $e) { // @codeCoverageIgnore
// TODO FIXME add testcase for this
return 0; // @codeCoverageIgnore
Expand Down Expand Up @@ -216,7 +222,7 @@ protected function createRoutesQueryBuilder(): QueryBuilder
return $queryBuilder
->from($this->contentRichEntityClass, self::CONTENT_RICH_ENTITY_ALIAS)
->innerJoin(self::CONTENT_RICH_ENTITY_ALIAS . '.dimensionContents', self::LOCALIZED_DIMENSION_CONTENT_ALIAS)
->innerJoin($this->routeClass, self::ROUTE_ALIAS, Join::WITH, self::ROUTE_ALIAS . '.entityId = ' . self::CONTENT_RICH_ENTITY_ALIAS . '.' . $this->getEntityIdField())
->innerJoin($this->routeClass, self::ROUTE_ALIAS, Join::WITH, self::ROUTE_ALIAS . '.entityId = ' . self::CONTENT_RICH_ENTITY_ALIAS . '.' . $this->getEntityIdField() . ' AND ' . self::ROUTE_ALIAS . '.locale = ' . self::LOCALIZED_DIMENSION_CONTENT_ALIAS . '.locale')
->where(self::LOCALIZED_DIMENSION_CONTENT_ALIAS . '.stage = :stage')
->andWhere(self::ROUTE_ALIAS . '.entityClass = :entityClass')
->andWhere(self::ROUTE_ALIAS . '.history = :history')
Expand Down
Expand Up @@ -18,6 +18,7 @@
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\ExampleDimensionContent;
use Sulu\Bundle\ContentBundle\Tests\Traits\AssertSnapshotTrait;
use Sulu\Bundle\ContentBundle\Tests\Traits\CreateExampleTrait;
use Sulu\Bundle\ContentBundle\Tests\Traits\SetGetPrivatePropertyTrait;
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;
use Sulu\Bundle\WebsiteBundle\Sitemap\Sitemap;
use Sulu\Bundle\WebsiteBundle\Sitemap\SitemapAlternateLink;
Expand All @@ -27,6 +28,7 @@ class ContentSitemapProviderTest extends SuluTestCase
{
use AssertSnapshotTrait;
use CreateExampleTrait;
use SetGetPrivatePropertyTrait;

public const SCHEME = 'https';
public const HOST = 'localhost';
Expand Down Expand Up @@ -151,6 +153,9 @@ public function testCreateSitemap(): void

public function testGetMaxPage(): void
{
// set page-size to 5 to check if the query behind it is correct
$this->setPrivateProperty($this->contentSitemapProvider, 'pageSize', 5);

$this->assertSame(1, $this->contentSitemapProvider->getMaxPage(static::SCHEME, static::HOST));
}

Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Expand Up @@ -29,3 +29,5 @@ parameters:
- message: "#^Method Sulu\\\\Bundle\\\\ContentBundle\\\\Content\\\\Infrastructure\\\\Sulu\\\\Structure\\\\ContentDocument\\:\\:getStructure\\(\\) should return Sulu\\\\Component\\\\Content\\\\Document\\\\Structure\\\\StructureInterface but returns null\\.$#"
count: 1
path: Content/Infrastructure/Sulu/Structure/ContentDocument.php
bootstrapFiles:
- %currentWorkingDirectory%/Tests/Application/Kernel.php

0 comments on commit 5cc8055

Please sign in to comment.