Skip to content

Commit 2906755

Browse files
committed
[BUGFIX] Node publishing does not trigger indexing
Nodes being published are not indexed, because the signals in Node are never emitted during publishing. In addition the node coming from the PublishingService (through an additional signal) never has the target workspace assigned, so it is passed to the indexing as separate information.
1 parent f729753 commit 2906755

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,24 @@ public function getIndex() {
163163
* index this node, and add it to the current bulk request.
164164
*
165165
* @param Node $node
166-
* @throws \Exception
166+
* @param string $targetWorkspaceName In case this is triggered during publishing, a workspace name will be passed in
167167
* @return void
168+
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\IndexingException
168169
*/
169-
public function indexNode(Node $node) {
170-
$contextPathHash = sha1($node->getContextPath());
170+
public function indexNode(Node $node, $targetWorkspaceName = NULL) {
171+
$contextPath = $node->getContextPath();
172+
if ($targetWorkspaceName !== NULL) {
173+
$contextPath = str_replace($node->getWorkspace()->getName(), $targetWorkspaceName, $contextPath);
174+
}
175+
$contextPathHash = sha1($contextPath);
171176
$nodeType = $node->getNodeType();
172177

173178
$mappingType = $this->getIndex()->findType(NodeTypeMappingBuilder::convertNodeTypeNameToMappingName($nodeType));
174179

175180
if ($node->isRemoved()) {
176181
// TODO: handle deletion from the fulltext index as well
177182
$mappingType->deleteDocumentById($contextPathHash);
178-
$this->logger->log(sprintf('NodeIndexer: Removed node %s from index (node flagged as removed). ID: %s', $node->getContextPath(), $contextPathHash), LOG_DEBUG, NULL, 'ElasticSearch (CR)');
183+
$this->logger->log(sprintf('NodeIndexer: Removed node %s from index (node flagged as removed). ID: %s', $contextPath, $contextPathHash), LOG_DEBUG, NULL, 'ElasticSearch (CR)');
179184

180185
return;
181186
}
@@ -229,6 +234,9 @@ public function indexNode(Node $node) {
229234
);
230235

231236
$documentData = $document->getData();
237+
if ($targetWorkspaceName !== NULL) {
238+
$documentData['__workspace'] = $targetWorkspaceName;
239+
}
232240

233241
if ($fulltextIndexingEnabledForNode === TRUE) {
234242
if ($this->isFulltextRoot($node)) {
@@ -273,7 +281,7 @@ public function indexNode(Node $node) {
273281
$this->updateFulltext($node, $fulltextIndexOfNode);
274282
}
275283

276-
$this->logger->log(sprintf('NodeIndexer: Added / updated node %s. ID: %s', $node->getContextPath(), $contextPathHash), LOG_DEBUG, NULL, 'ElasticSearch (CR)');
284+
$this->logger->log(sprintf('NodeIndexer: Added / updated node %s. ID: %s', $contextPath, $contextPathHash), LOG_DEBUG, NULL, 'ElasticSearch (CR)');
277285
}
278286

279287
/**

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class NodeIndexingManager {
3333
*/
3434
protected $nodesToBeRemoved;
3535

36+
/**
37+
* @var array
38+
*/
39+
protected $targetWorkspaceNamesForNodesToBeIndexed = array();
40+
3641
/**
3742
* the indexing batch size (from the settings)
3843
*
@@ -65,11 +70,13 @@ public function injectSettings(array $settings) {
6570
* Schedule a node for indexing
6671
*
6772
* @param Node $node
73+
* @param mixed $targetWorkspace In case this is triggered during publishing, a Workspace will be passed in
6874
* @return void
6975
*/
70-
public function indexNode(Node $node) {
76+
public function indexNode(Node $node, $targetWorkspace) {
7177
$this->nodesToBeRemoved->detach($node);
7278
$this->nodesToBeIndexed->attach($node);
79+
$this->targetWorkspaceNamesForNodesToBeIndexed[$node->getContextPath()] = $targetWorkspace instanceof \TYPO3\TYPO3CR\Domain\Model\Workspace ? $targetWorkspace->getName() : NULL;
7380

7481
$this->flushQueuesIfNeeded();
7582
}
@@ -105,8 +112,9 @@ protected function flushQueuesIfNeeded() {
105112
* @return void
106113
*/
107114
public function flushQueues() {
115+
/** @var \TYPO3\TYPO3CR\Domain\Model\NodeInterface $nodeToBeIndexed */
108116
foreach ($this->nodesToBeIndexed as $nodeToBeIndexed) {
109-
$this->nodeIndexer->indexNode($nodeToBeIndexed);
117+
$this->nodeIndexer->indexNode($nodeToBeIndexed, $this->targetWorkspaceNamesForNodesToBeIndexed[$nodeToBeIndexed->getContextPath()]);
110118
}
111119

112120
foreach ($this->nodesToBeRemoved as $nodeToBeRemoved) {
@@ -115,5 +123,6 @@ public function flushQueues() {
115123
$this->nodeIndexer->flush();
116124
$this->nodesToBeIndexed = new \SplObjectStorage();
117125
$this->nodesToBeRemoved = new \SplObjectStorage();
126+
$this->targetWorkspaceNamesForNodesToBeIndexed = array();
118127
}
119128
}

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Package.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function registerIndexingSlots(Bootstrap $bootstrap) {
4646
$bootstrap->getSignalSlotDispatcher()->connect('TYPO3\TYPO3CR\Domain\Model\Node', 'nodeAdded', 'Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexingManager', 'indexNode');
4747
$bootstrap->getSignalSlotDispatcher()->connect('TYPO3\TYPO3CR\Domain\Model\Node', 'nodeUpdated', 'Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexingManager', 'indexNode');
4848
$bootstrap->getSignalSlotDispatcher()->connect('TYPO3\TYPO3CR\Domain\Model\Node', 'nodeRemoved', 'Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexingManager', 'removeNode');
49+
$bootstrap->getSignalSlotDispatcher()->connect('TYPO3\Neos\Service\PublishingService', 'nodePublished', 'Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexingManager', 'indexNode', FALSE);
4950
$bootstrap->getSignalSlotDispatcher()->connect('TYPO3\Flow\Persistence\Doctrine\PersistenceManager', 'allObjectsPersisted', 'Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexingManager', 'flushQueues');
5051
}
5152
}

0 commit comments

Comments
 (0)