Skip to content

Commit 9055fa9

Browse files
committed
[FEATURE] allow indexing only live workspace
1 parent 31de58d commit 9055fa9

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Command/NodeIndexCommandController.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,28 @@ class NodeIndexCommandController extends CommandController {
9292
*/
9393
protected $logger;
9494

95+
/**
96+
* @Flow\Inject
97+
* @var \TYPO3\Flow\Configuration\ConfigurationManager
98+
*/
99+
protected $configurationManager;
100+
101+
/**
102+
* @var array
103+
*/
104+
protected $settings;
105+
106+
/**
107+
* Called by the Flow object framework after creating the object and resolving all dependencies.
108+
*
109+
* @param integer $cause Creation cause
110+
*/
111+
public function initializeObject($cause) {
112+
if ($cause === \TYPO3\Flow\Object\ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
113+
$this->settings = $this->configurationManager->getConfiguration(\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.TYPO3CR.Search');
114+
}
115+
}
116+
95117
/**
96118
* Show the mapping which would be sent to the ElasticSearch server
97119
*
@@ -160,6 +182,10 @@ public function buildCommand($limit = NULL, $update = FALSE, $workspace = NULL)
160182
$this->indexedNodes = 0;
161183
$this->countedIndexedNodes = 0;
162184

185+
if ($workspace === NULL && $this->settings['indexAllWorkspaces'] === FALSE) {
186+
$workspace = 'live';
187+
}
188+
163189
if ($workspace === NULL) {
164190
foreach ($this->workspaceRepository->findAll() as $workspace) {
165191
$this->indexWorkspace($workspace->getName());

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Indexer/NodeIndexer.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ public function getIndex() {
120120
public function indexNode(NodeInterface $node, $targetWorkspaceName = NULL) {
121121
$contextPath = $node->getContextPath();
122122

123+
if ($this->settings['indexAllWorkspaces'] === FALSE) {
124+
// we are only supposed to index the live workspace.
125+
// We need to check the workspace at two occasions; checking the
126+
// $targetWorkspaceName and the workspace name of the node's context as fallback
127+
if ($targetWorkspaceName !== NULL && $targetWorkspaceName !== 'live') {
128+
return;
129+
}
130+
131+
if ($targetWorkspaceName === NULL && $node->getContext()->getWorkspaceName() !== 'live') {
132+
return;
133+
}
134+
}
135+
136+
123137
if ($targetWorkspaceName !== NULL) {
124138
$contextPath = str_replace($node->getContext()->getWorkspace()->getName(), $targetWorkspaceName, $contextPath);
125139
}
@@ -325,6 +339,12 @@ protected function isFulltextRoot(NodeInterface $node) {
325339
* @return string
326340
*/
327341
public function removeNode(NodeInterface $node) {
342+
if ($this->settings['indexAllWorkspaces'] === FALSE) {
343+
if ($node->getContext()->getWorkspaceName() !== 'live') {
344+
return;
345+
}
346+
}
347+
328348
// TODO: handle deletion from the fulltext index as well
329349
$identifier = sha1($node->getContextPath());
330350

Configuration/Settings.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ TYPO3:
22
TYPO3CR:
33
Search:
44

5+
# API. If set to FALSE, only index the "live" workspace and not user workspaces.
6+
# If you only index the live workspace, Search will not work for your editors in the user workspaces.
7+
# Furthermore, if you heavily rely on Search for collecting content, this might be strange for editors to
8+
# work with -- as unpublished changes are not indexed right away.
9+
indexAllWorkspaces: true
10+
511
elasticSearch:
612

713
# API. name of the ElasticSearch index to use. Will create many indices prefixed by this indexName.

0 commit comments

Comments
 (0)