Commit 18528406 authored by Dominique Feyer's avatar Dominique Feyer

TASK: Replace TYPO3.JobQueue by Flowpack.JobQueue 1.0

parent fc241908
<?php
namespace Ttree\Neos\Sitemap\Domain\Model;
use Flowpack\JobQueue\Common\Job\JobManager;
use Ttree\Neos\Sitemap\Job\BuildRequestJob;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Exception;
use TYPO3\Jobqueue\Common\Job\JobManager;
/**
* @api
......@@ -112,4 +112,4 @@ class SitemapDefinition {
$this->jobManager->queue($this->getPreset()['queueName'], $job);
}
}
\ No newline at end of file
}
<?php
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\Service\SitemapBuilderInterface;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Log\SystemLoggerInterface;
use TYPO3\Flow\Utility\Algorithms;
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
......
......@@ -5,7 +5,6 @@ use Tackk\Cartographer\ChangeFrequency;
use Tackk\Cartographer\Sitemap;
use Ttree\Neos\Sitemap\Domain\Model\SitemapDefinition;
use TYPO3\Eel\EelEvaluatorInterface;
use TYPO3\Eel\FlowQuery\FlowQuery;
use TYPO3\Eel\Utility;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Http\Request;
......@@ -25,7 +24,8 @@ use TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface;
* @Flow\Scope("singleton")
* @api
*/
class SitemapBuilder implements SitemapBuilderInterface {
class SitemapBuilder implements SitemapBuilderInterface
{
/**
* @var ContextFactoryInterface
......@@ -61,7 +61,8 @@ class SitemapBuilder implements SitemapBuilderInterface {
* @param SitemapDefinition $definiton
* @return string
*/
public function build(SitemapDefinition $definiton) {
public function build(SitemapDefinition $definiton)
{
$preset = $definiton->getPreset();
$processedUri = [];
$sitemap = new Sitemap();
......@@ -70,20 +71,20 @@ class SitemapBuilder implements SitemapBuilderInterface {
$controllerContext = $this->createControllerContext($definiton->getBaseUrl());
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 */
foreach ($nodes as $node) {
if ($this->needToSkipNode($preset, $node)) {
continue;
}
$uri = $this->linkingService->createNodeUri($controllerContext, $node, NULL, 'html', TRUE);
$uri = $this->linkingService->createNodeUri($controllerContext, $node, null, 'html', true);
$hash = md5($uri);
if (isset($processedUri[$hash])) {
continue;
}
$lastPublicationDateTime = $node->getNodeData()->getLastPublicationDateTime() ?: $node->getNodeData()->getLastModificationDateTime();
$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 {
* @param NodeInterface $node
* @return boolean
*/
protected function needToSkipNode(array $preset, NodeInterface $node) {
protected function needToSkipNode(array $preset, NodeInterface $node)
{
if (trim($node->getProperty('uriPathSegment')) === '') {
return TRUE;
return true;
}
$skipNodeTypes = Arrays::getValueByPath($preset, 'skipNodeTypes') ?: [];
foreach ($skipNodeTypes as $nodeType => $nodeTypeStatus) {
if ($nodeTypeStatus !== TRUE) {
if ($nodeTypeStatus !== true) {
continue;
}
if ($node->getNodeType()->isOfType($nodeType) === TRUE) {
return TRUE;
if ($node->getNodeType()->isOfType($nodeType) === true) {
return true;
}
}
return FALSE;
return false;
}
/**
* @param string $baseUrl
* @return ControllerContext
*/
protected function createControllerContext($baseUrl) {
protected function createControllerContext($baseUrl)
{
$httpRequest = Request::create(new Uri($baseUrl));
$response = new Response();
$arguments = new Arguments([]);
......@@ -130,21 +133,22 @@ class SitemapBuilder implements SitemapBuilderInterface {
* @param array $languageIdentifiers
* @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);
$contextProperties = array(
$contextProperties = [
'workspaceName' => $workspaceName,
'currentSite' => $site,
'invisibleContentShown' => TRUE,
'inaccessibleContentShown' => TRUE
);
if ($languageIdentifiers !== NULL) {
$contextProperties = array_merge($contextProperties, array(
'dimensions' => array('language' => $languageIdentifiers)
));
'invisibleContentShown' => true,
'inaccessibleContentShown' => true
];
if ($languageIdentifiers !== null) {
$contextProperties = array_merge($contextProperties, [
'dimensions' => ['language' => $languageIdentifiers]
]);
}
return $this->contextFactory->create($contextProperties);
}
}
\ No newline at end of file
}
......@@ -8,5 +8,5 @@ Ttree:
'AllPages': "${q(node).find('[instanceof TYPO3.Neos.NodeTypes:Page]')}"
skipNodeTypes:
'TYPO3.Neos:Shortcut': TRUE
queueName: 'Default'
path: '%FLOW_PATH_DATA%/Web/sitemap.xml'
\ No newline at end of file
queueName: 'Ttree.Neos.Sitemap.Default'
path: '%FLOW_PATH_DATA%/Web/sitemap.xml'
......@@ -3,9 +3,9 @@
"type": "typo3-flow-package",
"description": "Add description here",
"require": {
"typo3/neos": "*",
"typo3/jobqueue-common": "*",
"tackk/cartographer": "^1.1"
"typo3/neos": "^2.2",
"typo3/jobqueue-common": "^1.0.0",
"tackk/cartographer": "^1.1.0"
},
"suggest": {
"typo3/jobqueue-beanstalkd": "Use Beanstalkd for Job Queue handling"
......@@ -15,4 +15,4 @@
"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