FEATURE: Respect further root line cases

Respect the following situations during indexing:
- Page is not reachable due to broken root line.
- Page is not reachable due to being below a recycler.
This commit is contained in:
Daniel Siepmann 2017-08-15 09:21:04 +02:00
parent 416e49026e
commit 040206c95d
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
4 changed files with 85 additions and 7 deletions

View file

@ -258,18 +258,27 @@ class TcaTableService
* Checks whether the given record was blacklisted by root line. * Checks whether the given record was blacklisted by root line.
* This can be configured by typoscript as whole root lines can be black listed. * This can be configured by typoscript as whole root lines can be black listed.
* *
* Also further TYPO3 mechanics are taken into account. Does a valid root
* line exist, is page inside a recycler, is inherited start- endtime
* excluded, etc.
*
* @param array &$record * @param array &$record
* @return bool * @return bool
*/ */
protected function isRecordBlacklistedByRootline(array &$record) protected function isRecordBlacklistedByRootline(array &$record)
{ {
// If no rootline exists, the record is on a unreachable page and therefore blacklisted. $pageUid = $record['pid'];
if ($record['pid'] == 0) { if ($this->tableName === 'pages') {
return false; $pageUid = $record['uid'];
} }
$rootline = $this->objectManager->get(RootlineUtility::class, $record['pid'])->get(); try {
if (!isset($rootline[0])) { $rootline = $this->objectManager->get(RootlineUtility::class, $pageUid)->get();
} catch (\RuntimeException $e) {
$this->logger->notice(
sprintf('Could not fetch rootline for page %u, because: %s', $pageUid, $e->getMessage()),
[$record, $e]
);
return true; return true;
} }
@ -278,12 +287,29 @@ class TcaTableService
if ($this->isBlackListedRootLineConfigured() if ($this->isBlackListedRootLineConfigured()
&& in_array($pageInRootLine['uid'], $this->getBlackListedRootLine()) && in_array($pageInRootLine['uid'], $this->getBlackListedRootLine())
) { ) {
$this->logger->info(
sprintf(
'Record %u is black listed due to configured root line configuration of page %u.',
$record['uid'],
$pageInRootLine['uid']
),
[$record, $pageInRootLine]
);
return true; return true;
} }
if ($pageInRootLine['extendToSubpages'] && ( if ($pageInRootLine['extendToSubpages'] && (
($pageInRootLine['endtime'] > 0 && $pageInRootLine['endtime'] <= time()) ($pageInRootLine['endtime'] > 0 && $pageInRootLine['endtime'] <= time())
|| ($pageInRootLine['starttime'] > 0 && $pageInRootLine['starttime'] >= time()) || ($pageInRootLine['starttime'] > 0 && $pageInRootLine['starttime'] >= time())
)) { )) {
$this->logger->info(
sprintf(
'Record %u is black listed due to configured timing of parent page %u.',
$record['uid'],
$pageInRootLine['uid']
),
[$record, $pageInRootLine]
);
return true; return true;
} }
} }

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<!-- DISABLED PAGES -->
<pages>
<uid>3</uid>
<pid>2</pid>
<title>Some disabled page due broken root line</title>
</pages>
<pages>
<uid>4</uid>
<pid>3</pid>
<title>Some disabled page due to parent pages root line being broken</title>
</pages>
<!-- ENABLED PAGES -->
<pages>
<uid>6</uid>
<pid>1</pid>
<title>Some enabled page due valid root line</title>
</pages>
</dataset>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<!-- DISABLED PAGES -->
<pages>
<uid>2</uid>
<pid>1</pid>
<title>Some disabled page due being recycler</title>
<doktype>255</doktype>
</pages>
<pages>
<uid>3</uid>
<pid>2</pid>
<title>Some disabled page due to parent page being recycler</title>
</pages>
<!-- ENABLED PAGES -->
<pages>
<uid>6</uid>
<pid>1</pid>
<title>Some enabled page due to no be below recycler</title>
</pages>
</dataset>

View file

@ -64,10 +64,12 @@ class PagesIndexerTest extends AbstractFunctionalTestCase
/** /**
* @test * @test
* @dataProvider rootLineDataSets
* @param string $dataSetPath
*/ */
public function inheritedTimingIsRespectedDuringIndexing() public function rootLineIsRespectedDuringIndexing($dataSetPath)
{ {
$this->importDataSet('Tests/Functional/Fixtures/Indexing/PagesIndexer/InheritedTiming.xml'); $this->importDataSet($dataSetPath);
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class); $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class);
$tableName = 'pages'; $tableName = 'pages';
@ -90,4 +92,13 @@ class PagesIndexerTest extends AbstractFunctionalTestCase
$this->inject($indexer, 'connection', $connection); $this->inject($indexer, 'connection', $connection);
$indexer->indexAllDocuments(); $indexer->indexAllDocuments();
} }
public function rootLineDataSets()
{
return [
'Broken root line' => ['Tests/Functional/Fixtures/Indexing/PagesIndexer/BrokenRootLine.xml'],
'Recycler doktype' => ['Tests/Functional/Fixtures/Indexing/PagesIndexer/Recycler.xml'],
'Extended timing to sub pages' => ['Tests/Functional/Fixtures/Indexing/PagesIndexer/InheritedTiming.xml'],
];
}
} }