Skip to content

Commit

Permalink
Fix sitemap include (#141)
Browse files Browse the repository at this point in the history
* fix: sitemap include

---------

Co-authored-by: Marijan Klaric <[email protected]>
Co-authored-by: Florian ALEXANDRE <[email protected]>
  • Loading branch information
3 people authored Aug 31, 2023
1 parent 3c08a04 commit ebcb7dd
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions bundle/Core/Sitemap/QueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ public function __invoke(): Query
$config = $this->configResolver->getParameter('sitemap_includes', 'nova_ezseo');
$criterions = array_merge(
$criterions,
$this->getCriterionsForConfig(
$this->getCriterionsForIncludeConfig(
$config['contentTypeIdentifiers'],
$config['locations'],
$config['subtrees'],
false
)
);

Expand Down Expand Up @@ -142,4 +141,53 @@ function ($criterion) {

return $criterions;
}

private function getCriterionsForIncludeConfig(
array $contentTypeIdentifiers,
array $locationIds,
array $subtreeLocationsId
) {
$contentTypeService = $this->repository->getContentTypeService();
$criterions = [];

$validContentTypeIdentifiers = [];
foreach ($contentTypeIdentifiers as $contentTypeIdentifier) {
try {
$contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
} catch (NotFoundException $exception) {
continue;
}
$validContentTypeIdentifiers[] = $contentTypeIdentifier;
}
if (count($validContentTypeIdentifiers) > 0) {
$criterions[] = new Criterion\ContentTypeIdentifier($validContentTypeIdentifiers);
}

$subtreePaths = [];
foreach ($subtreeLocationsId as $locationId) {
$includedLocation = $this->getLocation($locationId);
if (null === $includedLocation) {
continue;
}
$subtreePaths[] = $includedLocation->pathString;
}
if (count($subtreePaths) > 0) {
$criterions[] = new Criterion\Subtree($subtreePaths);
}

$validLocationIds = [];
foreach ($locationIds as $locationId) {
$includedLocation = $this->getLocation($locationId);
if (null === $includedLocation) {
continue;
}
$validLocationIds[] = $locationId;
}

if (count($validLocationIds) > 0) {
$criterions[] = new Criterion\LocationId($validLocationIds);
}

return $criterions;
}
}

0 comments on commit ebcb7dd

Please sign in to comment.