Commit fc241908 authored by Dominique Feyer's avatar Dominique Feyer
Browse files

[TASK] Use EEL query to select documents

parent d7b93ccb
Loading
Loading
Loading
Loading
+17 −12
Original line number Original line Diff line number Diff line
@@ -4,7 +4,9 @@ namespace Ttree\Neos\Sitemap\Service;
use Tackk\Cartographer\ChangeFrequency;
use Tackk\Cartographer\ChangeFrequency;
use Tackk\Cartographer\Sitemap;
use Tackk\Cartographer\Sitemap;
use Ttree\Neos\Sitemap\Domain\Model\SitemapDefinition;
use Ttree\Neos\Sitemap\Domain\Model\SitemapDefinition;
use TYPO3\Eel\EelEvaluatorInterface;
use TYPO3\Eel\FlowQuery\FlowQuery;
use TYPO3\Eel\FlowQuery\FlowQuery;
use TYPO3\Eel\Utility;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Http\Request;
use TYPO3\Flow\Http\Request;
use TYPO3\Flow\Http\Response;
use TYPO3\Flow\Http\Response;
@@ -13,6 +15,7 @@ use TYPO3\Flow\Mvc\ActionRequest;
use TYPO3\Flow\Mvc\Controller\Arguments;
use TYPO3\Flow\Mvc\Controller\Arguments;
use TYPO3\Flow\Mvc\Controller\ControllerContext;
use TYPO3\Flow\Mvc\Controller\ControllerContext;
use TYPO3\Flow\Mvc\Routing\UriBuilder;
use TYPO3\Flow\Mvc\Routing\UriBuilder;
use TYPO3\Flow\Utility\Arrays;
use TYPO3\Neos\Domain\Repository\SiteRepository;
use TYPO3\Neos\Domain\Repository\SiteRepository;
use TYPO3\Neos\Service\LinkingService;
use TYPO3\Neos\Service\LinkingService;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
@@ -48,6 +51,12 @@ class SitemapBuilder implements SitemapBuilderInterface {
     */
     */
    protected $uriBuilder;
    protected $uriBuilder;


    /**
     * @Flow\Inject
     * @var EelEvaluatorInterface
     */
    protected $eelEvaluator;

    /**
    /**
     * @param SitemapDefinition $definiton
     * @param SitemapDefinition $definiton
     * @return string
     * @return string
@@ -60,19 +69,13 @@ class SitemapBuilder implements SitemapBuilderInterface {
        $context = $this->createContext('live', $definiton->getSiteNodeName());
        $context = $this->createContext('live', $definiton->getSiteNodeName());
        $controllerContext = $this->createControllerContext($definiton->getBaseUrl());
        $controllerContext = $this->createControllerContext($definiton->getBaseUrl());


        foreach ($preset['include'] as $nodeType => $nodeTypeStatus) {
        foreach ($preset['includes'] as $queryLabel => $query) {
            if ($nodeTypeStatus !== TRUE) {
            $nodes = Utility::evaluateEelExpression($query, $this->eelEvaluator, array('node' => $context->getRootNode()));
                continue;
            }
            $flowQuery = new FlowQuery(array($context->getRootNode()));
            /** @var NodeInterface $node */
            /** @var NodeInterface $node */
            foreach ($flowQuery->find(sprintf('[instanceof %s]', $nodeType)) as $node) {
            foreach ($nodes as $node) {
                if ($this->needToSkipNode($preset, $node)) {
                if ($this->needToSkipNode($preset, $node)) {
                    continue;
                    continue;
                }
                }
                if (trim($node->getProperty('uriPathSegment')) === '') {
                    continue;
                }
                $uri = $this->linkingService->createNodeUri($controllerContext, $node, NULL, 'html', TRUE);
                $uri = $this->linkingService->createNodeUri($controllerContext, $node, NULL, 'html', TRUE);
                $hash = md5($uri);
                $hash = md5($uri);
                if (isset($processedUri[$hash])) {
                if (isset($processedUri[$hash])) {
@@ -93,8 +96,11 @@ class SitemapBuilder implements SitemapBuilderInterface {
     * @return boolean
     * @return boolean
     */
     */
    protected function needToSkipNode(array $preset, NodeInterface $node) {
    protected function needToSkipNode(array $preset, NodeInterface $node) {
        if (isset($preset['skip']) && is_array($preset['skip'])) {
        if (trim($node->getProperty('uriPathSegment')) === '') {
            foreach ($preset['skip'] as $nodeType => $nodeTypeStatus) {
            return TRUE;
        }
        $skipNodeTypes = Arrays::getValueByPath($preset, 'skipNodeTypes') ?: [];
        foreach ($skipNodeTypes as $nodeType => $nodeTypeStatus) {
            if ($nodeTypeStatus !== TRUE) {
            if ($nodeTypeStatus !== TRUE) {
                continue;
                continue;
            }
            }
@@ -102,7 +108,6 @@ class SitemapBuilder implements SitemapBuilderInterface {
                return TRUE;
                return TRUE;
            }
            }
        }
        }
        }
        return FALSE;
        return FALSE;
    }
    }


+4 −4
Original line number Original line Diff line number Diff line
@@ -3,10 +3,10 @@ Ttree:
    Sitemap:
    Sitemap:
      presets:
      presets:
        default:
        default:
          include:
          type: 'normal'
            'TYPO3.Neos.NodeTypes:Page': TRUE
          includes:
          skip:
            'AllPages': "${q(node).find('[instanceof TYPO3.Neos.NodeTypes:Page]')}"
          skipNodeTypes:
            'TYPO3.Neos:Shortcut': TRUE
            'TYPO3.Neos:Shortcut': TRUE
          type: 'single'
          queueName: 'Default'
          queueName: 'Default'
          path: '%FLOW_PATH_DATA%/Web/sitemap.xml'
          path: '%FLOW_PATH_DATA%/Web/sitemap.xml'
 No newline at end of file