Skip to content

Commit f81ebc9

Browse files
Merge pull request #342 from daniellienert/bugfix/fix-node-delete
BUGFIX: Do not specify a type when deleting nodes
2 parents cbc268a + 03a3662 commit f81ebc9

4 files changed

Lines changed: 207 additions & 106 deletions

File tree

Classes/Driver/Version6/DocumentDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function delete(NodeInterface $node, string $identifier): array
3737
return [
3838
[
3939
'delete' => [
40-
'_type' => $node->getNodeType()->getName(),
40+
'_type' =>'_doc',
4141
'_id' => $identifier
4242
]
4343
]

Tests/Functional/Eel/ElasticSearchQueryTest.php

Lines changed: 6 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -13,70 +13,31 @@
1313
* source code.
1414
*/
1515

16-
use DateTime;
1716
use DateTimeImmutable;
1817
use Exception;
1918
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Command\NodeIndexCommandController;
2019
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryBuilder;
2120
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryResult;
2221
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException;
23-
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
22+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Tests\Functional\Traits\ContentRepositoryNodeCreationTrait;
2423
use Neos\ContentRepository\Domain\Model\NodeInterface;
25-
use Neos\ContentRepository\Domain\Model\Workspace;
26-
use Neos\ContentRepository\Domain\Repository\NodeDataRepository;
27-
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
28-
use Neos\ContentRepository\Domain\Service\Context;
29-
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
30-
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
31-
use Neos\ContentRepository\Exception\NodeExistsException;
32-
use Neos\ContentRepository\Exception\NodeTypeNotFoundException;
33-
use Neos\Flow\Cli\Exception\StopCommandException;
34-
use Neos\Flow\Mvc\Exception\StopActionException;
3524
use Neos\Flow\Persistence\QueryResultInterface;
3625
use Neos\Flow\Tests\FunctionalTestCase;
3726

3827
class ElasticSearchQueryTest extends FunctionalTestCase
3928
{
40-
/**
41-
* @var WorkspaceRepository
42-
*/
43-
protected $workspaceRepository;
29+
use ContentRepositoryNodeCreationTrait;
4430

4531
/**
4632
* @var NodeIndexCommandController
4733
*/
4834
protected $nodeIndexCommandController;
4935

50-
/**
51-
* @var Context
52-
*/
53-
protected $context;
54-
55-
/**
56-
* @var NodeInterface
57-
*/
58-
protected $siteNode;
59-
6036
/**
6137
* @var boolean
6238
*/
6339
protected static $testablePersistenceEnabled = true;
6440

65-
/**
66-
* @var ContextFactoryInterface
67-
*/
68-
protected $contextFactory;
69-
70-
/**
71-
* @var NodeTypeManager
72-
*/
73-
protected $nodeTypeManager;
74-
75-
/**
76-
* @var NodeDataRepository
77-
*/
78-
protected $nodeDataRepository;
79-
8041
/**
8142
* @var boolean
8243
*/
@@ -85,27 +46,13 @@ class ElasticSearchQueryTest extends FunctionalTestCase
8546
public function setUp(): void
8647
{
8748
parent::setUp();
88-
$this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class);
89-
$liveWorkspace = new Workspace('live');
90-
$this->workspaceRepository->add($liveWorkspace);
91-
92-
$this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
93-
$this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
94-
$this->context = $this->contextFactory->create([
95-
'workspaceName' => 'live',
96-
'dimensions' => ['language' => ['en_US']],
97-
'targetDimensions' => ['language' => 'en_US']
98-
]);
99-
$rootNode = $this->context->getRootNode();
100-
101-
$this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
102-
$this->siteNode->setProperty('title', 'welcome');
103-
104-
$this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class);
49+
$this->setupContentRepository();
10550

10651
$this->nodeIndexCommandController = $this->objectManager->get(NodeIndexCommandController::class);
10752

10853
$this->createNodesForNodeSearchTest();
54+
sleep(2);
55+
$this->indexNodes();
10956
}
11057

11158
public function tearDown(): void
@@ -394,52 +341,8 @@ protected function getLogMessagePrefix(string $method): string
394341
return substr(strrchr($method, '\\'), 1);
395342
}
396343

397-
/**
398-
* Creates some sample nodes to run tests against
399-
*
400-
* @throws NodeExistsException
401-
* @throws NodeTypeNotFoundException
402-
* @throws StopActionException
403-
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
404-
* @throws ApiException
405-
* @throws StopCommandException
406-
*/
407-
protected function createNodesForNodeSearchTest(): void
344+
protected function indexNodes(): void
408345
{
409-
$newDocumentNode1 = $this->siteNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
410-
$newDocumentNode1->setProperty('title', 'chicken');
411-
$newDocumentNode1->setProperty('title_analyzed', 'chicken');
412-
413-
$newContentNode1 = $newDocumentNode1->getNode('main')->createNode('document-1-text-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
414-
$newContentNode1->setProperty('text', 'A Scout smiles and whistles under all circumstances.');
415-
416-
$newDocumentNode2 = $this->siteNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
417-
$newDocumentNode2->setProperty('title', 'chicken');
418-
$newDocumentNode2->setProperty('title_analyzed', 'chicken');
419-
420-
// Nodes for cacheLifetime test
421-
$newContentNode2 = $newDocumentNode2->getNode('main')->createNode('document-2-text-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
422-
$newContentNode2->setProperty('text', 'Hidden after 2025-01-01');
423-
$newContentNode2->setHiddenAfterDateTime(new DateTime('@1735686000'));
424-
$newContentNode3 = $newDocumentNode2->getNode('main')->createNode('document-2-text-2', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
425-
$newContentNode3->setProperty('text', 'Hidden before 2018-07-18');
426-
$newContentNode3->setHiddenBeforeDateTime(new DateTime('@1531864800'));
427-
428-
$newDocumentNode3 = $this->siteNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
429-
$newDocumentNode3->setProperty('title', 'egg');
430-
$newDocumentNode3->setProperty('title_analyzed', 'egg');
431-
432-
$dimensionContext = $this->contextFactory->create([
433-
'workspaceName' => 'live',
434-
'dimensions' => ['language' => ['de']]
435-
]);
436-
$translatedNode3 = $dimensionContext->adoptNode($newDocumentNode3, true);
437-
$translatedNode3->setProperty('title', 'De');
438-
439-
$this->persistenceManager->persistAll();
440-
441-
sleep(2);
442-
443346
if (self::$indexInitialized === true) {
444347
return;
445348
}

Tests/Functional/Indexer/NodeIndexerTest.php

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,33 @@
1313
* source code.
1414
*/
1515

16+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\NodeTypeMappingBuilderInterface;
17+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\QueryInterface;
18+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\Version6\Mapping\NodeTypeMappingBuilder;
19+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\Version6\Query\FilteredQuery;
1620
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
1721
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\ConfigurationException;
1822
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer;
1923
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\DimensionsService;
24+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Tests\Functional\Traits\ContentRepositoryNodeCreationTrait;
25+
use Flowpack\ElasticSearch\Domain\Model\Mapping;
2026
use Flowpack\ElasticSearch\Exception;
2127
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
28+
use Neos\ContentRepository\Domain\Model\NodeInterface;
2229
use Neos\Flow\Tests\FunctionalTestCase;
30+
use Neos\Utility\Arrays;
2331

2432
class NodeIndexerTest extends FunctionalTestCase
2533
{
34+
use ContentRepositoryNodeCreationTrait;
35+
2636
const TESTING_INDEX_PREFIX = 'neoscr_testing';
2737

38+
/**
39+
* @var boolean
40+
*/
41+
protected static $testablePersistenceEnabled = true;
42+
2843
/**
2944
* @var NodeIndexer
3045
*/
@@ -40,12 +55,18 @@ class NodeIndexerTest extends FunctionalTestCase
4055
*/
4156
protected $searchClient;
4257

58+
/**
59+
* @var NodeTypeMappingBuilder
60+
*/
61+
protected $nodeTypeMappingBuilder;
62+
4363
public function setUp(): void
4464
{
4565
parent::setUp();
4666
$this->searchClient = $this->objectManager->get(ElasticSearchClient::class);
4767
$this->nodeIndexer = $this->objectManager->get(NodeIndexer::class);
4868
$this->dimensionService = $this->objectManager->get(DimensionsService::class);
69+
$this->nodeTypeMappingBuilder = $this->objectManager->get(NodeTypeMappingBuilderInterface::class);
4970
}
5071

5172
protected function tearDown(): void
@@ -59,9 +80,10 @@ protected function tearDown(): void
5980
*/
6081
public function getIndexWithoutDimensionConfigured(): void
6182
{
83+
$this->nodeIndexer->setIndexNamePostfix('');
6284
$this->nodeIndexer->setDimensions([]);
6385
$index = $this->nodeIndexer->getIndex();
64-
static::assertEquals(self::TESTING_INDEX_PREFIX . '-default-functionaltest', $index->getName());
86+
static::assertEquals(self::TESTING_INDEX_PREFIX . '-default', $index->getName());
6587
}
6688

6789
/**
@@ -78,7 +100,7 @@ public function getIndexForDimensionConfiguration(): void
78100
$index = $this->nodeIndexer->getIndex();
79101
$dimesionHash = $this->dimensionService->hash($dimensionValues);
80102

81-
static::assertEquals(self::TESTING_INDEX_PREFIX . '-' . $dimesionHash . '-functionaltest', $index->getName());
103+
static::assertEquals(self::TESTING_INDEX_PREFIX . '-' . $dimesionHash, $index->getName());
82104
}
83105

84106
/**
@@ -97,6 +119,36 @@ public function updateIndexAlias(): void
97119
$this->assertAliasesEquals(self::TESTING_INDEX_PREFIX, [$this->nodeIndexer->getIndexName()]);
98120
}
99121

122+
/**
123+
* @test
124+
*/
125+
public function indexAndDeleteNode(): void
126+
{
127+
$this->setupContentRepository();
128+
$this->createNodesForNodeSearchTest();
129+
/** @var NodeInterface $testNode */
130+
$testNode = current($this->siteNode->getChildNodes('Neos.NodeTypes:Page', 1));
131+
132+
$dimensionValues = ['language' => ['en_US']];
133+
$this->nodeIndexer->setDimensions($dimensionValues);
134+
$this->nodeIndexer->getIndex()->create();
135+
136+
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
137+
foreach ($nodeTypeMappingCollection as $mapping) {
138+
/** @var Mapping $mapping */
139+
$mapping->apply();
140+
}
141+
142+
$this->nodeIndexer->indexNode($testNode);
143+
$this->nodeIndexer->flush();
144+
$this->assertTrue($this->nodeExistsInIndex($testNode), 'Node was not successfully indexed.');
145+
146+
$this->nodeIndexer->removeNode($testNode);
147+
$this->nodeIndexer->flush();
148+
sleep(1);
149+
$this->assertFalse($this->nodeExistsInIndex($testNode), 'Node still exists after delete');
150+
}
151+
100152

101153
/**
102154
* @param string $indexName
@@ -115,4 +167,24 @@ protected function assertAliasesEquals(string $aliasPrefix, array $expectdAliase
115167
$content = $this->searchClient->request('GET', '/_alias/' . $aliasPrefix . '*')->getTreatedContent();
116168
static::assertEquals($expectdAliases, array_keys($content));
117169
}
170+
171+
/**
172+
* @param NodeInterface $testNode
173+
* @return bool
174+
* @throws ConfigurationException
175+
* @throws Exception
176+
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
177+
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException
178+
* @throws \Neos\Flow\Http\Exception
179+
*/
180+
private function nodeExistsInIndex(NodeInterface $testNode): bool
181+
{
182+
$this->searchClient->setContextNode($this->siteNode);
183+
/** @var FilteredQuery $query */
184+
$query = $this->objectManager->get(QueryInterface::class);
185+
$query->queryFilter('term', ['neos_node_identifier' => $testNode->getIdentifier()]);
186+
187+
$result = $this->nodeIndexer->getIndex()->request('GET', '/_search', [], $query->toArray())->getTreatedContent();
188+
return count(Arrays::getValueByPath($result, 'hits.hits')) === 1;
189+
}
118190
}

0 commit comments

Comments
 (0)