Commit 18528406 authored by Dominique Feyer's avatar Dominique Feyer

TASK: Replace TYPO3.JobQueue by Flowpack.JobQueue 1.0

parent fc241908
<?php <?php
namespace Ttree\Neos\Sitemap\Domain\Model; namespace Ttree\Neos\Sitemap\Domain\Model;
use Flowpack\JobQueue\Common\Job\JobManager;
use Ttree\Neos\Sitemap\Job\BuildRequestJob; use Ttree\Neos\Sitemap\Job\BuildRequestJob;
use TYPO3\Flow\Annotations as Flow; use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Exception; use TYPO3\Flow\Exception;
use TYPO3\Jobqueue\Common\Job\JobManager;
/** /**
* @api * @api
...@@ -112,4 +112,4 @@ class SitemapDefinition { ...@@ -112,4 +112,4 @@ class SitemapDefinition {
$this->jobManager->queue($this->getPreset()['queueName'], $job); $this->jobManager->queue($this->getPreset()['queueName'], $job);
} }
} }
\ No newline at end of file
<?php <?php
namespace Ttree\Neos\Sitemap\Job; namespace Ttree\Neos\Sitemap\Job;
use Flowpack\JobQueue\Common\Job\JobInterface;
use Flowpack\JobQueue\Common\Queue\Message;
use Flowpack\JobQueue\Common\Queue\QueueInterface;
use Ttree\Neos\Sitemap\Domain\Model\SitemapDefinition; use Ttree\Neos\Sitemap\Domain\Model\SitemapDefinition;
use Ttree\Neos\Sitemap\Service\SitemapBuilderInterface; use Ttree\Neos\Sitemap\Service\SitemapBuilderInterface;
use TYPO3\Flow\Annotations as Flow; use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Log\SystemLoggerInterface; use TYPO3\Flow\Log\SystemLoggerInterface;
use TYPO3\Flow\Utility\Algorithms; use TYPO3\Flow\Utility\Algorithms;
use TYPO3\Flow\Utility\Files; use TYPO3\Flow\Utility\Files;
use TYPO3\Jobqueue\Common\Job\JobInterface;
use TYPO3\Jobqueue\Common\Queue\Message;
use TYPO3\Jobqueue\Common\Queue\QueueInterface;
/** /**
* Build Requested Job * Build Requested Job
......
...@@ -5,7 +5,6 @@ use Tackk\Cartographer\ChangeFrequency; ...@@ -5,7 +5,6 @@ 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\EelEvaluatorInterface;
use TYPO3\Eel\FlowQuery\FlowQuery;
use TYPO3\Eel\Utility; 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;
...@@ -25,7 +24,8 @@ use TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface; ...@@ -25,7 +24,8 @@ use TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface;
* @Flow\Scope("singleton") * @Flow\Scope("singleton")
* @api * @api
*/ */
class SitemapBuilder implements SitemapBuilderInterface { class SitemapBuilder implements SitemapBuilderInterface
{
/** /**
* @var ContextFactoryInterface * @var ContextFactoryInterface
...@@ -61,7 +61,8 @@ class SitemapBuilder implements SitemapBuilderInterface { ...@@ -61,7 +61,8 @@ class SitemapBuilder implements SitemapBuilderInterface {
* @param SitemapDefinition $definiton * @param SitemapDefinition $definiton
* @return string * @return string
*/ */
public function build(SitemapDefinition $definiton) { public function build(SitemapDefinition $definiton)
{
$preset = $definiton->getPreset(); $preset = $definiton->getPreset();
$processedUri = []; $processedUri = [];
$sitemap = new Sitemap(); $sitemap = new Sitemap();
...@@ -70,20 +71,20 @@ class SitemapBuilder implements SitemapBuilderInterface { ...@@ -70,20 +71,20 @@ class SitemapBuilder implements SitemapBuilderInterface {
$controllerContext = $this->createControllerContext($definiton->getBaseUrl()); $controllerContext = $this->createControllerContext($definiton->getBaseUrl());
foreach ($preset['includes'] as $queryLabel => $query) { foreach ($preset['includes'] as $queryLabel => $query) {
$nodes = Utility::evaluateEelExpression($query, $this->eelEvaluator, array('node' => $context->getRootNode())); $nodes = Utility::evaluateEelExpression($query, $this->eelEvaluator, ['node' => $context->getRootNode()]);
/** @var NodeInterface $node */ /** @var NodeInterface $node */
foreach ($nodes as $node) { foreach ($nodes as $node) {
if ($this->needToSkipNode($preset, $node)) { if ($this->needToSkipNode($preset, $node)) {
continue; 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])) {
continue; continue;
} }
$lastPublicationDateTime = $node->getNodeData()->getLastPublicationDateTime() ?: $node->getNodeData()->getLastModificationDateTime(); $lastPublicationDateTime = $node->getNodeData()->getLastPublicationDateTime() ?: $node->getNodeData()->getLastModificationDateTime();
$sitemap->add($uri, $lastPublicationDateTime ? $lastPublicationDateTime->format('Y-m-d') : null, ChangeFrequency::WEEKLY, 1.0); $sitemap->add($uri, $lastPublicationDateTime ? $lastPublicationDateTime->format('Y-m-d') : null, ChangeFrequency::WEEKLY, 1.0);
$processedUri[$hash] = TRUE; $processedUri[$hash] = true;
} }
} }
...@@ -95,27 +96,29 @@ class SitemapBuilder implements SitemapBuilderInterface { ...@@ -95,27 +96,29 @@ class SitemapBuilder implements SitemapBuilderInterface {
* @param NodeInterface $node * @param NodeInterface $node
* @return boolean * @return boolean
*/ */
protected function needToSkipNode(array $preset, NodeInterface $node) { protected function needToSkipNode(array $preset, NodeInterface $node)
{
if (trim($node->getProperty('uriPathSegment')) === '') { if (trim($node->getProperty('uriPathSegment')) === '') {
return TRUE; return true;
} }
$skipNodeTypes = Arrays::getValueByPath($preset, 'skipNodeTypes') ?: []; $skipNodeTypes = Arrays::getValueByPath($preset, 'skipNodeTypes') ?: [];
foreach ($skipNodeTypes as $nodeType => $nodeTypeStatus) { foreach ($skipNodeTypes as $nodeType => $nodeTypeStatus) {
if ($nodeTypeStatus !== TRUE) { if ($nodeTypeStatus !== true) {
continue; continue;
} }
if ($node->getNodeType()->isOfType($nodeType) === TRUE) { if ($node->getNodeType()->isOfType($nodeType) === true) {
return TRUE; return true;
} }
} }
return FALSE; return false;
} }
/** /**
* @param string $baseUrl * @param string $baseUrl
* @return ControllerContext * @return ControllerContext
*/ */
protected function createControllerContext($baseUrl) { protected function createControllerContext($baseUrl)
{
$httpRequest = Request::create(new Uri($baseUrl)); $httpRequest = Request::create(new Uri($baseUrl));
$response = new Response(); $response = new Response();
$arguments = new Arguments([]); $arguments = new Arguments([]);
...@@ -130,21 +133,22 @@ class SitemapBuilder implements SitemapBuilderInterface { ...@@ -130,21 +133,22 @@ class SitemapBuilder implements SitemapBuilderInterface {
* @param array $languageIdentifiers * @param array $languageIdentifiers
* @return \TYPO3\TYPO3CR\Domain\Service\Context * @return \TYPO3\TYPO3CR\Domain\Service\Context
*/ */
protected function createContext($workspaceName, $siteNodeName, array $languageIdentifiers = NULL) { protected function createContext($workspaceName, $siteNodeName, array $languageIdentifiers = null)
{
$site = $this->siteRepository->findOneByNodeName($siteNodeName); $site = $this->siteRepository->findOneByNodeName($siteNodeName);
$contextProperties = array( $contextProperties = [
'workspaceName' => $workspaceName, 'workspaceName' => $workspaceName,
'currentSite' => $site, 'currentSite' => $site,
'invisibleContentShown' => TRUE, 'invisibleContentShown' => true,
'inaccessibleContentShown' => TRUE 'inaccessibleContentShown' => true
); ];
if ($languageIdentifiers !== NULL) { if ($languageIdentifiers !== null) {
$contextProperties = array_merge($contextProperties, array( $contextProperties = array_merge($contextProperties, [
'dimensions' => array('language' => $languageIdentifiers) 'dimensions' => ['language' => $languageIdentifiers]
)); ]);
} }
return $this->contextFactory->create($contextProperties); return $this->contextFactory->create($contextProperties);
} }
} }
\ No newline at end of file
...@@ -8,5 +8,5 @@ Ttree: ...@@ -8,5 +8,5 @@ Ttree:
'AllPages': "${q(node).find('[instanceof TYPO3.Neos.NodeTypes:Page]')}" 'AllPages': "${q(node).find('[instanceof TYPO3.Neos.NodeTypes:Page]')}"
skipNodeTypes: skipNodeTypes:
'TYPO3.Neos:Shortcut': TRUE 'TYPO3.Neos:Shortcut': TRUE
queueName: 'Default' queueName: 'Ttree.Neos.Sitemap.Default'
path: '%FLOW_PATH_DATA%/Web/sitemap.xml' path: '%FLOW_PATH_DATA%/Web/sitemap.xml'
\ No newline at end of file
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
"type": "typo3-flow-package", "type": "typo3-flow-package",
"description": "Add description here", "description": "Add description here",
"require": { "require": {
"typo3/neos": "*", "typo3/neos": "^2.2",
"typo3/jobqueue-common": "*", "typo3/jobqueue-common": "^1.0.0",
"tackk/cartographer": "^1.1" "tackk/cartographer": "^1.1.0"
}, },
"suggest": { "suggest": {
"typo3/jobqueue-beanstalkd": "Use Beanstalkd for Job Queue handling" "typo3/jobqueue-beanstalkd": "Use Beanstalkd for Job Queue handling"
...@@ -15,4 +15,4 @@ ...@@ -15,4 +15,4 @@
"Ttree\\Neos\\Sitemap\\": "Classes" "Ttree\\Neos\\Sitemap\\": "Classes"
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment