Skip to content

Commit 34e00bc

Browse files
committed
TASK: Try to build a fake node in RemovalJob
1 parent a99c61d commit 34e00bc

5 files changed

Lines changed: 170 additions & 149 deletions

File tree

Classes/AbstractIndexingJob.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryQueueIndexer;
3+
4+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer;
5+
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\Domain\Repository\NodeDataRepository;
6+
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\Domain\Service\FakeNodeDataFactory;
7+
use Flowpack\JobQueue\Common\Job\JobInterface;
8+
use Flowpack\JobQueue\Common\Queue\Message;
9+
use Flowpack\JobQueue\Common\Queue\QueueInterface;
10+
use Neos\ContentRepository\Domain\Model\NodeData;
11+
use Neos\Flow\Annotations as Flow;
12+
use Neos\Flow\Utility\Algorithms;
13+
use Neos\ContentRepository\Domain\Factory\NodeFactory;
14+
use Neos\ContentRepository\Domain\Model\NodeInterface;
15+
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
16+
17+
/**
18+
* Elasticsearch Node Abstract Job
19+
*/
20+
abstract class AbstractIndexingJob implements JobInterface
21+
{
22+
use LoggerTrait;
23+
24+
/**
25+
* @var NodeIndexer
26+
* @Flow\Inject
27+
*/
28+
protected $nodeIndexer;
29+
30+
/**
31+
* @var NodeDataRepository
32+
* @Flow\Inject
33+
*/
34+
protected $nodeDataRepository;
35+
36+
/**
37+
* @var NodeFactory
38+
* @Flow\Inject
39+
*/
40+
protected $nodeFactory;
41+
42+
/**
43+
* @var ContextFactoryInterface
44+
* @Flow\Inject
45+
*/
46+
protected $contextFactory;
47+
48+
/**
49+
* @var FakeNodeDataFactory
50+
* @Flow\Inject
51+
*/
52+
protected $fakeNodeDataFactory;
53+
54+
/**
55+
* @var string
56+
*/
57+
protected $identifier;
58+
59+
/**
60+
* @var string
61+
*/
62+
protected $targetWorkspaceName;
63+
64+
/**
65+
* @var string
66+
*/
67+
protected $indexPostfix;
68+
69+
/**
70+
* @var array
71+
*/
72+
protected $nodes = [];
73+
74+
/**
75+
* @param string $indexPostfix
76+
* @param string $targetWorkspaceName In case indexing is triggered during publishing, a target workspace name will be passed in
77+
* @param array $nodes
78+
*/
79+
public function __construct($indexPostfix, $targetWorkspaceName, array $nodes)
80+
{
81+
$this->identifier = Algorithms::generateRandomString(24);
82+
$this->targetWorkspaceName = $targetWorkspaceName;
83+
$this->indexPostfix = $indexPostfix;
84+
$this->nodes = $nodes;
85+
}
86+
87+
/**
88+
* Get an optional identifier for the job
89+
*
90+
* @return string A job identifier
91+
*/
92+
public function getIdentifier()
93+
{
94+
return $this->identifier;
95+
}
96+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\Domain\Service;
3+
4+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception;
5+
use Neos\ContentRepository\Domain\Model\NodeData;
6+
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
7+
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
8+
use Neos\Flow\Annotations as Flow;
9+
10+
/**
11+
* @Flow\Scope("singleton")
12+
*/
13+
class FakeNodeDataFactory
14+
{
15+
/**
16+
* @var WorkspaceRepository
17+
* @Flow\Inject
18+
*/
19+
protected $workspaceRepository;
20+
21+
/**
22+
* @var NodeTypeManager
23+
* @Flow\Inject
24+
*/
25+
protected $nodeTypeManager;
26+
27+
public function createFromPayload(array $data)
28+
{
29+
if (!isset($data['workspace']) || empty($data['workspace'])) {
30+
throw new Exception('Unable to create fake node data, missing workspace value', 1508448007);
31+
}
32+
if (!isset($data['path']) || empty($data['path'])) {
33+
throw new Exception('Unable to create fake node data, missing path value', 1508448008);
34+
}
35+
if (!isset($data['nodeIdentifier']) || empty($data['nodeIdentifier'])) {
36+
throw new Exception('Unable to create fake node data, missing identifier value', 1508448009);
37+
}
38+
if (!isset($data['nodeType']) || empty($data['nodeType'])) {
39+
throw new Exception('Unable to create fake node data, missing nodeType value', 1508448011);
40+
}
41+
42+
$workspace = $this->workspaceRepository->findOneByName($data['workspace']);
43+
if ($workspace === null) {
44+
throw new Exception('Unable to create fake node data, workspace not found', 1508448028);
45+
}
46+
47+
$nodeData = new NodeData($data['path'], $workspace, $data['nodeIdentifier'], isset($data['dimensions']) ? $data['dimensions'] : null);
48+
$nodeData->setNodeType($this->nodeTypeManager->getNodeType($data['nodeType']));
49+
50+
$nodeData->setProperty('title', 'Fake node');
51+
$nodeData->setProperty('uriPathSegment', 'fake-node');
52+
53+
$nodeData->setRemoved(true);
54+
55+
return $nodeData;
56+
}
57+
}

Classes/Indexer/NodeIndexer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null)
4747
[
4848
'nodeIdentifier' => $this->persistenceManager->getIdentifierByObject($node->getNodeData()),
4949
'dimensions' => $node->getDimensions(),
50+
'workspace' => $node->getWorkspace()->getName(),
5051
'nodeType' => $node->getNodeType()->getName(),
5152
'contextPath' => $node->getContextPath(),
53+
'path' => $node->getPath(),
5254
]
5355
]);
5456
$this->jobManager->queue(NodeIndexQueueCommandController::LIVE_QUEUE_NAME, $indexingJob);
@@ -68,8 +70,10 @@ public function removeNode(NodeInterface $node, $targetWorkspaceName = null)
6870
[
6971
'nodeIdentifier' => $this->persistenceManager->getIdentifierByObject($node->getNodeData()),
7072
'dimensions' => $node->getDimensions(),
73+
'workspace' => $node->getWorkspace()->getName(),
7174
'nodeType' => $node->getNodeType()->getName(),
7275
'contextPath' => $node->getContextPath(),
76+
'path' => $node->getPath(),
7377
]
7478
]);
7579
$this->jobManager->queue(NodeIndexQueueCommandController::LIVE_QUEUE_NAME, $removalJob);

Classes/IndexingJob.php

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,18 @@
11
<?php
22
namespace Flowpack\ElasticSearch\ContentRepositoryQueueIndexer;
33

4-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer;
5-
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\Domain\Repository\NodeDataRepository;
6-
use Flowpack\JobQueue\Common\Job\JobInterface;
4+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception;
75
use Flowpack\JobQueue\Common\Queue\Message;
86
use Flowpack\JobQueue\Common\Queue\QueueInterface;
97
use Neos\ContentRepository\Domain\Model\NodeData;
108
use Neos\Flow\Annotations as Flow;
11-
use Neos\Flow\Utility\Algorithms;
12-
use Neos\ContentRepository\Domain\Factory\NodeFactory;
139
use Neos\ContentRepository\Domain\Model\NodeInterface;
14-
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
1510

1611
/**
1712
* Elasticsearch Node Indexing Job
1813
*/
19-
class IndexingJob implements JobInterface
14+
class IndexingJob extends AbstractIndexingJob
2015
{
21-
use LoggerTrait;
22-
23-
/**
24-
* @var NodeIndexer
25-
* @Flow\Inject
26-
*/
27-
protected $nodeIndexer;
28-
29-
/**
30-
* @var NodeDataRepository
31-
* @Flow\Inject
32-
*/
33-
protected $nodeDataRepository;
34-
35-
/**
36-
* @var NodeFactory
37-
* @Flow\Inject
38-
*/
39-
protected $nodeFactory;
40-
41-
/**
42-
* @var ContextFactoryInterface
43-
* @Flow\Inject
44-
*/
45-
protected $contextFactory;
46-
47-
/**
48-
* @var string
49-
*/
50-
protected $identifier;
51-
52-
/**
53-
* @var string
54-
*/
55-
protected $targetWorkspaceName;
56-
57-
/**
58-
* @var string
59-
*/
60-
protected $indexPostfix;
61-
62-
/**
63-
* @var array
64-
*/
65-
protected $nodes = [];
66-
67-
/**
68-
* @param string $indexPostfix
69-
* @param string $targetWorkspaceName In case indexing is triggered during publishing, a target workspace name will be passed in
70-
* @param array $nodes
71-
*/
72-
public function __construct($indexPostfix, $targetWorkspaceName, array $nodes)
73-
{
74-
$this->identifier = Algorithms::generateRandomString(24);
75-
$this->targetWorkspaceName = $targetWorkspaceName;
76-
$this->indexPostfix = $indexPostfix;
77-
$this->nodes = $nodes;
78-
}
79-
8016
/**
8117
* Execute the indexing of nodes
8218
*
@@ -95,7 +31,7 @@ public function execute(QueueInterface $queue, Message $message)
9531

9632
// Skip this iteration if the nodedata can not be fetched (deleted node)
9733
if (!$nodeData instanceof NodeData) {
98-
$this->log(sprintf('action=indexing step=failed node=%s message="Node data could not be loaded"', $node['nodeIdentifier']));
34+
$this->log(sprintf('action=indexing step=failed node=%s message="Node data could not be loaded"', $node['nodeIdentifier']), \LOG_ERR);
9935
continue;
10036
}
10137

@@ -128,16 +64,6 @@ public function execute(QueueInterface $queue, Message $message)
12864
return true;
12965
}
13066

131-
/**
132-
* Get an optional identifier for the job
133-
*
134-
* @return string A job identifier
135-
*/
136-
public function getIdentifier()
137-
{
138-
return $this->identifier;
139-
}
140-
14167
/**
14268
* Get a readable label for the job
14369
*

0 commit comments

Comments
 (0)