Skip to content

Commit 7115321

Browse files
committed
BUGFIX: Correctly use node identifier in fake nodes
When a "fake" node was needed, it was assigned the persistence object identifier as node identifier. This leads to mismatches in fulltext indexing (at least.) Now both identifiers are in the job payload and used as needed.
1 parent 7baaa96 commit 7115321

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

Classes/Domain/Service/FakeNodeDataFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FakeNodeDataFactory
2626
protected $nodeTypeManager;
2727

2828
/**
29-
* Thie creates a NodeData instance from the given payload
29+
* This creates a "fake" removed NodeData instance from the given payload
3030
*
3131
* @param array $payload
3232
* @return NodeData
@@ -40,7 +40,7 @@ public function createFromPayload(array $payload)
4040
if (!isset($payload['path']) || empty($payload['path'])) {
4141
throw new Exception('Unable to create fake node data, missing path value', 1508448008);
4242
}
43-
if (!isset($payload['nodeIdentifier']) || empty($payload['nodeIdentifier'])) {
43+
if (!isset($payload['identifier']) || empty($payload['identifier'])) {
4444
throw new Exception('Unable to create fake node data, missing identifier value', 1508448009);
4545
}
4646
if (!isset($payload['nodeType']) || empty($payload['nodeType'])) {
@@ -52,7 +52,7 @@ public function createFromPayload(array $payload)
5252
throw new Exception('Unable to create fake node data, workspace not found', 1508448028);
5353
}
5454

55-
$nodeData = new NodeData($payload['path'], $workspace, $payload['nodeIdentifier'], isset($payload['dimensions']) ? $payload['dimensions'] : null);
55+
$nodeData = new NodeData($payload['path'], $workspace, $payload['identifier'], isset($payload['dimensions']) ? $payload['dimensions'] : null);
5656
try {
5757
$nodeData->setNodeType($this->nodeTypeManager->getNodeType($payload['nodeType']));
5858
} catch (NodeTypeNotFoundException $e) {

Classes/Indexer/NodeIndexer.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,8 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null)
4545

4646
return;
4747
}
48-
$indexingJob = new IndexingJob($this->indexNamePostfix, $targetWorkspaceName, [
49-
[
50-
'nodeIdentifier' => $this->persistenceManager->getIdentifierByObject($node->getNodeData()),
51-
'dimensions' => $node->getDimensions(),
52-
'workspace' => $node->getWorkspace()->getName(),
53-
'nodeType' => $node->getNodeType()->getName(),
54-
'path' => $node->getPath(),
55-
]
56-
]);
48+
49+
$indexingJob = new IndexingJob($this->indexNamePostfix, $targetWorkspaceName, $this->nodeAsArray($node));
5750
$this->jobManager->queue(NodeIndexQueueCommandController::LIVE_QUEUE_NAME, $indexingJob);
5851
}
5952

@@ -68,15 +61,28 @@ public function removeNode(NodeInterface $node, $targetWorkspaceName = null)
6861

6962
return;
7063
}
71-
$removalJob = new RemovalJob($this->indexNamePostfix, $targetWorkspaceName, [
64+
65+
$removalJob = new RemovalJob($this->indexNamePostfix, $targetWorkspaceName, $this->nodeAsArray($node));
66+
$this->jobManager->queue(NodeIndexQueueCommandController::LIVE_QUEUE_NAME, $removalJob);
67+
}
68+
69+
/**
70+
* Returns an array of data from the node for use as job payload.
71+
*
72+
* @param NodeInterface $node
73+
* @return array
74+
*/
75+
protected function nodeAsArray(NodeInterface $node)
76+
{
77+
return [
7278
[
73-
'nodeIdentifier' => $this->persistenceManager->getIdentifierByObject($node->getNodeData()),
79+
'persistenceObjectIdentifier' => $this->persistenceManager->getIdentifierByObject($node->getNodeData()),
80+
'identifier' => $node->getIdentifier(),
7481
'dimensions' => $node->getDimensions(),
7582
'workspace' => $node->getWorkspace()->getName(),
7683
'nodeType' => $node->getNodeType()->getName(),
77-
'path' => $node->getPath(),
84+
'path' => $node->getPath()
7885
]
79-
]);
80-
$this->jobManager->queue(NodeIndexQueueCommandController::LIVE_QUEUE_NAME, $removalJob);
86+
];
8187
}
8288
}

Classes/IndexingJob.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public function execute(QueueInterface $queue, Message $message)
2626
$startTime = microtime(true);
2727
foreach ($this->nodes as $node) {
2828
/** @var NodeData $nodeData */
29-
$nodeData = $this->nodeDataRepository->findByIdentifier($node['nodeIdentifier']);
29+
$nodeData = $this->nodeDataRepository->findByIdentifier($node['persistenceObjectIdentifier']);
3030

3131
// Skip this iteration if the nodedata can not be fetched (deleted node)
3232
if (!$nodeData instanceof NodeData) {
33-
$this->log(sprintf('action=indexing step=failed node=%s message="Node data could not be loaded"', $node['nodeIdentifier']), \LOG_ERR);
33+
$this->log(sprintf('action=indexing step=failed node=%s message="Node data could not be loaded"', $node['identifier']), \LOG_ERR);
3434
continue;
3535
}
3636

@@ -44,7 +44,7 @@ public function execute(QueueInterface $queue, Message $message)
4444

4545
// Skip this iteration if the node can not be fetched from the current context
4646
if (!$currentNode instanceof NodeInterface) {
47-
$this->log(sprintf('action=indexing step=failed node=%s message="Node could not be processed"', $node['nodeIdentifier']));
47+
$this->log(sprintf('action=indexing step=failed node=%s message="Node could not be processed"', $node['identifier']));
4848
continue;
4949
}
5050

Classes/RemovalJob.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public function execute(QueueInterface $queue, Message $message)
2727
$startTime = microtime(true);
2828
foreach ($this->nodes as $node) {
2929
/** @var NodeData $nodeData */
30-
$nodeData = $this->nodeDataRepository->findByIdentifier($node['nodeIdentifier']);
30+
$nodeData = $this->nodeDataRepository->findByIdentifier($node['persistenceObjectIdentifier']);
3131

3232
// Skip this iteration if the nodedata can not be fetched (deleted node)
3333
if (!$nodeData instanceof NodeData) {
3434
try {
3535
$nodeData = $this->fakeNodeDataFactory->createFromPayload($node);
3636
} catch (Exception $exception) {
37-
$this->log(sprintf('action=removal step=failed node=%s message="Node data could not be loaded or faked"', $node['nodeIdentifier']), \LOG_CRIT);
37+
$this->log(sprintf('action=removal step=failed node=%s message="Node data could not be loaded or faked"', $node['identifier']), \LOG_CRIT);
3838
$this->_logger->logException($exception);
3939
continue;
4040
}
@@ -51,7 +51,7 @@ public function execute(QueueInterface $queue, Message $message)
5151

5252
// Skip this iteration if the node can not be fetched from the current context
5353
if (!$currentNode instanceof NodeInterface) {
54-
$this->log(sprintf('action=removal step=failed node=%s message="Node could not be processed"', $node['nodeIdentifier']));
54+
$this->log(sprintf('action=removal step=failed node=%s message="Node could not be processed"', $node['identifier']));
5555
continue;
5656
}
5757

0 commit comments

Comments
 (0)