Skip to content

Commit

Permalink
Merge pull request #168 from neos/40-contentrepository
Browse files Browse the repository at this point in the history
TASK: adjustments to standalone ES CR
  • Loading branch information
skurfuerst authored Aug 11, 2022
2 parents 48f4043 + 5e52de3 commit d272333
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
80 changes: 47 additions & 33 deletions Classes/Fusion/XmlSitemapUrlsImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,29 @@
* source code.
*/

use Neos\ContentRepository\Exception\NodeException;
use Neos\ContentRepository\NodeAccess\NodeAccessorManager;
use Neos\ContentRepository\Projection\ContentGraph\NodeInterface;
use Neos\ContentRepository\SharedModel\NodeType\NodeType;
use Neos\ContentRepository\SharedModel\NodeType\NodeTypeManager;
use Neos\ContentRepository\SharedModel\NodeType\NodeTypeConstraintParser;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\Fusion\FusionObjects\AbstractFusionObject;
use Neos\Media\Domain\Model\ImageInterface;
use Neos\ContentRepository\Domain\Model\NodeInterface;

class XmlSitemapUrlsImplementation extends AbstractFusionObject
{
/**
* @Flow\Inject
* @var NodeTypeManager
* @var ContentRepositoryRegistry
*/
protected $nodeTypeManager;
protected $contentRepositoryRegistry;

/**
* @Flow\Inject
* @var NodeAccessorManager
*/
protected $nodeAccessorManager;

/**
* @Flow\Inject
Expand All @@ -38,7 +45,7 @@ class XmlSitemapUrlsImplementation extends AbstractFusionObject
/**
* @var array
*/
protected $assetPropertiesByNodeType;
protected $assetPropertiesByNodeType = null;

/**
* @var bool
Expand Down Expand Up @@ -96,27 +103,26 @@ public function getStartingPoint(): NodeInterface
return $this->startingPoint;
}

/**
* @return void
*/
public function initializeObject()
private function getAssetPropertiesForNodeType(NodeType $nodeType): array
{
if ($this->getIncludeImageUrls()) {
$relevantPropertyTypes = [
'array<Neos\Media\Domain\Model\Asset>' => true,
'Neos\Media\Domain\Model\Asset' => true,
'Neos\Media\Domain\Model\ImageInterface' => true
];
if ($this->assetPropertiesByNodeType[$nodeType->getName()] === null) {
$this->assetPropertiesByNodeType[$nodeType->getName()] = [];
if ($this->getIncludeImageUrls()) {
$relevantPropertyTypes = [
'array<Neos\Media\Domain\Model\Asset>' => true,
'Neos\Media\Domain\Model\Asset' => true,
'Neos\Media\Domain\Model\ImageInterface' => true
];

foreach ($this->nodeTypeManager->getNodeTypes(false) as $nodeType) {
/** @var NodeType $nodeType */
foreach ($nodeType->getProperties() as $propertyName => $propertyConfiguration) {
if (isset($relevantPropertyTypes[$nodeType->getPropertyType($propertyName)])) {
$this->assetPropertiesByNodeType[$nodeType->getName()][] = $propertyName;
}
}
}
}

return $this->assetPropertiesByNodeType[$nodeType->getName()];
}

/**
Expand All @@ -130,7 +136,7 @@ protected function appendItems(array &$items, NodeInterface $node)
if ($this->isDocumentNodeToBeIndexed($node)) {
$item = [
'node' => $node,
'lastModificationDateTime' => $node->getNodeData()->getLastModificationDateTime(),
//'lastModificationDateTime' => $node->getNodeData()->getLastModificationDateTime(),
'priority' => $node->getProperty('xmlSitemapPriority') ?: '',
'images' => [],
];
Expand All @@ -155,22 +161,30 @@ protected function appendItems(array &$items, NodeInterface $node)
*/
protected function resolveImages(NodeInterface $node, array &$item)
{
if (isset($this->assetPropertiesByNodeType[$node->getNodeType()->getName()]) && !empty($this->assetPropertiesByNodeType[$node->getNodeType()->getName()])) {

foreach ($this->assetPropertiesByNodeType[$node->getNodeType()->getName()] as $propertyName) {
if (is_array($node->getProperty($propertyName)) && !empty($node->getProperty($propertyName))) {
foreach ($node->getProperty($propertyName) as $asset) {
if ($asset instanceof ImageInterface) {
$item['images'][$this->persistenceManager->getIdentifierByObject($asset)] = $asset;
}
$assetPropertiesForNodeType = $this->getAssetPropertiesForNodeType($node->getNodeType());

foreach ($assetPropertiesForNodeType as $propertyName) {
if (is_array($node->getProperty($propertyName)) && !empty($node->getProperty($propertyName))) {
foreach ($node->getProperty($propertyName) as $asset) {
if ($asset instanceof ImageInterface) {
$item['images'][$this->persistenceManager->getIdentifierByObject($asset)] = $asset;
}
} elseif ($node->getProperty($propertyName) instanceof ImageInterface) {
$item['images'][$this->persistenceManager->getIdentifierByObject($node->getProperty($propertyName))] = $node->getProperty($propertyName);
}
} elseif ($node->getProperty($propertyName) instanceof ImageInterface) {
$item['images'][$this->persistenceManager->getIdentifierByObject($node->getProperty($propertyName))] = $node->getProperty($propertyName);
}
}

foreach ($node->getChildNodes('Neos.Neos:ContentCollection,Neos.Neos:Content') as $childNode) {
$contentRepository = $this->contentRepositoryRegistry->get($node->getSubgraphIdentity()->contentRepositoryIdentifier);
$nodeTypeConstraintParser = NodeTypeConstraintParser::create($contentRepository->getNodeTypeManager());

$nodeAccessor = $this->nodeAccessorManager->accessorFor($node->getSubgraphIdentity());
$childNodes = $nodeAccessor->findChildNodes(
$node,
$nodeTypeConstraintParser->parseFilterString('Neos.Neos:ContentCollection,Neos.Neos:Content')
);

foreach ($childNodes as $childNode) {
$this->resolveImages($childNode, $item);
}
}
Expand All @@ -185,10 +199,10 @@ protected function resolveImages(NodeInterface $node, array &$item)
*/
protected function isDocumentNodeToBeIndexed(NodeInterface $node): bool
{
return !$node->getNodeType()->isOfType('Neos.Seo:NoindexMixin') && $node->isVisible()
&& ($this->getRenderHiddenInIndex() || !$node->isHiddenInIndex()) && $node->isAccessible()
return !$node->getNodeType()->isOfType('Neos.Seo:NoindexMixin')// TODO?? && $node->isVisible()
&& ($this->getRenderHiddenInIndex())// TODO?? || !$node->isHiddenInIndex()) && $node->isAccessible()
&& $node->getProperty('metaRobotsNoindex') !== true
&& ((string)$node->getProperty('canonicalLink') === '' || substr($node->getProperty('canonicalLink'),7)=== $node->getIdentifier());
&& ((string)$node->getProperty('canonicalLink') === '' || substr($node->getProperty('canonicalLink'), 7) === $node->getNodeAggregateIdentifier()->getValue());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Fusion/XmlSitemap/XmlSitemapUrl.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ prototype(Neos.Seo:XmlSitemap.Url) < prototype(Neos.Fusion:Component) {
renderer = afx`
<url>
<loc @key="loc"><Neos.Neos:NodeUri node={props.node} format="html" absolute={true}/></loc>
<lastmod @key="lastmod">{props.lastModificationDateTime}</lastmod>
<lastmod @key="lastmod" @if.lastModification={props.lastModificationDateTime}>{props.lastModificationDateTime}</lastmod>
<changefreq @key="changefreq" @if.hasChangeFrequency={props.changeFrequency}>{props.changeFrequency}</changefreq>
<priority @key="priority" @if.hasPriority={props.priority}>{props.priority}</priority>
<Neos.Seo:XmlSitemap.ImageUrls @key="images" images={props.images} @if.hasImages={props.images}/>
Expand Down

0 comments on commit d272333

Please sign in to comment.