mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-26 07:16:11 +01:00
Merge pull request #81 from Codappix/feature/support-timing-inheritance-for-pages
FEATURE: Respect inherited start- and endtime for pages
This commit is contained in:
commit
3bb875d99a
5 changed files with 176 additions and 13 deletions
|
@ -24,6 +24,8 @@ use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
|
||||||
use Codappix\SearchCore\Domain\Index\IndexingException;
|
use Codappix\SearchCore\Domain\Index\IndexingException;
|
||||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use TYPO3\CMS\Core\Utility\RootlineUtility;
|
||||||
|
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulate logik related to TCA configuration.
|
* Encapsulate logik related to TCA configuration.
|
||||||
|
@ -47,15 +49,20 @@ class TcaTableService
|
||||||
*/
|
*/
|
||||||
protected $configuration;
|
protected $configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var RelationResolver
|
||||||
|
*/
|
||||||
|
protected $relationResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \TYPO3\CMS\Core\Log\Logger
|
* @var \TYPO3\CMS\Core\Log\Logger
|
||||||
*/
|
*/
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var RelationResolver
|
* @var ObjectManagerInterface
|
||||||
*/
|
*/
|
||||||
protected $relationResolver;
|
protected $objectManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject log manager to get concrete logger from it.
|
* Inject log manager to get concrete logger from it.
|
||||||
|
@ -67,6 +74,14 @@ class TcaTableService
|
||||||
$this->logger = $logManager->getLogger(__CLASS__);
|
$this->logger = $logManager->getLogger(__CLASS__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ObjectManagerInterface $objectManager
|
||||||
|
*/
|
||||||
|
public function injectObjectManager(ObjectManagerInterface $objectManager)
|
||||||
|
{
|
||||||
|
$this->objectManager = $objectManager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $tableName
|
* @param string $tableName
|
||||||
* @param ConfigurationContainerInterface $configuration
|
* @param ConfigurationContainerInterface $configuration
|
||||||
|
@ -243,26 +258,59 @@ 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.
|
||||||
*
|
*
|
||||||
* NOTE: Does not support pages yet. We have to add a switch once we
|
* Also further TYPO3 mechanics are taken into account. Does a valid root
|
||||||
* support them to use uid instead.
|
* 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'];
|
||||||
$rootline = BackendUtility::BEgetRootLine($record['pid']);
|
if ($this->tableName === 'pages') {
|
||||||
if (!isset($rootline[0])) {
|
$pageUid = $record['uid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check configured black list if present.
|
|
||||||
if ($this->isBlackListedRootLineConfigured()) {
|
|
||||||
foreach ($rootline as $pageInRootLine) {
|
foreach ($rootline as $pageInRootLine) {
|
||||||
if (in_array($pageInRootLine['uid'], $this->getBlackListedRootLine())) {
|
// Check configured black list if present.
|
||||||
|
if ($this->isBlackListedRootLineConfigured()
|
||||||
|
&& 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'] && (
|
||||||
|
($pageInRootLine['endtime'] > 0 && $pageInRootLine['endtime'] <= 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<dataset>
|
||||||
|
<!-- DISABLED PAGES -->
|
||||||
|
<pages>
|
||||||
|
<uid>2</uid>
|
||||||
|
<pid>1</pid>
|
||||||
|
<title>Some disabled page due to timing</title>
|
||||||
|
<endtime>1502186635</endtime>
|
||||||
|
<extendToSubpages>1</extendToSubpages>
|
||||||
|
</pages>
|
||||||
|
<pages>
|
||||||
|
<uid>3</uid>
|
||||||
|
<pid>2</pid>
|
||||||
|
<title>Some disabled page due to inherited timing</title>
|
||||||
|
</pages>
|
||||||
|
<pages>
|
||||||
|
<uid>4</uid>
|
||||||
|
<pid>1</pid>
|
||||||
|
<title>Some disabled page due to timing</title>
|
||||||
|
<starttime>2147483647</starttime>
|
||||||
|
<extendToSubpages>1</extendToSubpages>
|
||||||
|
</pages>
|
||||||
|
<pages>
|
||||||
|
<uid>5</uid>
|
||||||
|
<pid>4</pid>
|
||||||
|
<title>Some disabled page due to inherited timing</title>
|
||||||
|
</pages>
|
||||||
|
<!-- ENABLED PAGES -->
|
||||||
|
<pages>
|
||||||
|
<uid>6</uid>
|
||||||
|
<pid>1</pid>
|
||||||
|
<title>Some enabled page due to no be below inherited disabled timing</title>
|
||||||
|
</pages>
|
||||||
|
</dataset>
|
21
Tests/Functional/Fixtures/Indexing/PagesIndexer/Recycler.xml
Normal file
21
Tests/Functional/Fixtures/Indexing/PagesIndexer/Recycler.xml
Normal 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>
|
|
@ -61,4 +61,44 @@ class PagesIndexerTest extends AbstractFunctionalTestCase
|
||||||
$this->inject($indexer, 'connection', $connection);
|
$this->inject($indexer, 'connection', $connection);
|
||||||
$indexer->indexAllDocuments();
|
$indexer->indexAllDocuments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @dataProvider rootLineDataSets
|
||||||
|
* @param string $dataSetPath
|
||||||
|
*/
|
||||||
|
public function rootLineIsRespectedDuringIndexing($dataSetPath)
|
||||||
|
{
|
||||||
|
$this->importDataSet($dataSetPath);
|
||||||
|
|
||||||
|
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class);
|
||||||
|
$tableName = 'pages';
|
||||||
|
|
||||||
|
$connection = $this->getMockBuilder(Elasticsearch::class)
|
||||||
|
->setMethods(['addDocuments'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$connection->expects($this->once())
|
||||||
|
->method('addDocuments')
|
||||||
|
->with(
|
||||||
|
$this->stringContains($tableName),
|
||||||
|
$this->callback(function ($documents) {
|
||||||
|
return count($documents) === 2;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
$indexer = $objectManager->get(IndexerFactory::class)->getIndexer($tableName);
|
||||||
|
$this->inject($indexer, 'connection', $connection);
|
||||||
|
$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'],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue