Skip to content

Commit 463498a

Browse files
Merge pull request #193 from daniellienert/task/merge-master
TASK: Merge refactored CR-Adapter into master
2 parents 5ee0cea + cbcacea commit 463498a

53 files changed

Lines changed: 2602 additions & 747 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@ language: php
22
matrix:
33
include:
44
- php: 7.0
5-
- php: 5.6
6-
- php: 5.5
5+
env: ES=1
6+
- php: 7.0
7+
env: ES=2
78
sudo: false
89
before_install:
10+
- export NEOS_TARGET_VERSION=3.0
911
- cd ..
10-
- wget --no-check-certificate https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/zip/elasticsearch/2.4.1/elasticsearch-2.4.1.zip && unzip elasticsearch-2.4.1.zip
11-
- mv elasticsearch-2.4.1 elasticsearch
12+
- if [ "$ES" = 1 ]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.5.zip && unzip elasticsearch-1.7.5.zip && mv elasticsearch-1.7.5 elasticsearch; fi
13+
- if [ "$ES" = 2 ]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.4.3.zip && unzip elasticsearch-2.4.3.zip && mv elasticsearch-2.4.3 elasticsearch; fi
1214
- cd elasticsearch
1315
- bin/elasticsearch -d
1416
- cd ..
15-
- git clone https://github.com/neos/neos-base-distribution.git
17+
- git clone https://github.com/neos/neos-base-distribution.git -b ${NEOS_TARGET_VERSION}
1618
- cd neos-base-distribution
17-
- composer require flowpack/elasticsearch-contentrepositoryadaptor dev-master
18-
- composer require typo3/typo3cr-search dev-master
19+
- composer require --no-update --no-interaction flowpack/elasticsearch-contentrepositoryadaptor:dev-master
1920
install:
20-
- composer install
21+
- composer install --no-interaction
2122
- cd ..
2223
- rm -rf neos-base-distribution/Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor
2324
- mv Flowpack.ElasticSearch.ContentRepositoryAdaptor neos-base-distribution/Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor
2425
- cd neos-base-distribution
2526
script:
26-
- bin/phpunit -c Build/BuildEssentials/PhpUnit/UnitTests.xml Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor/Tests/Unit
27-
- bin/phpunit -c Build/BuildEssentials/PhpUnit/FunctionalTests.xml Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor/Tests/Functional
27+
- bin/phpunit --colors -c Build/BuildEssentials/PhpUnit/UnitTests.xml Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor/Tests/Unit
28+
- if [ "$ES" = 1 ]; then FLOW_CONTEXT="Testing/ElasticVersion1" bin/phpunit --colors --stop-on-failure -c Build/BuildEssentials/PhpUnit/FunctionalTests.xml Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor/Tests/Functional; fi
29+
- if [ "$ES" = 2 ]; then FLOW_CONTEXT="Testing/ElasticVersion2" bin/phpunit --colors --stop-on-failure -c Build/BuildEssentials/PhpUnit/FunctionalTests.xml Packages/Application/Flowpack.ElasticSearch.ContentRepositoryAdaptor/Tests/Functional; fi

Classes/Command/NodeIndexCommandController.php

Lines changed: 68 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait;
1616
use Neos\Flow\Annotations as Flow;
1717
use Neos\Flow\Cli\CommandController;
18-
use Neos\ContentRepository\Domain\Model\NodeInterface;
18+
use Neos\Neos\Controller\CreateContentContextTrait;
19+
use Neos\ContentRepository\Domain\Model\Workspace;
1920

2021
/**
2122
* Provides CLI features for index handling
@@ -25,6 +26,7 @@
2526
class NodeIndexCommandController extends CommandController
2627
{
2728
use IndexWorkspaceTrait;
29+
use CreateContentContextTrait;
2830

2931
/**
3032
* @Flow\Inject
@@ -62,11 +64,6 @@ class NodeIndexCommandController extends CommandController
6264
*/
6365
protected $nodeTypeMappingBuilder;
6466

65-
/**
66-
* @var integer
67-
*/
68-
protected $limit;
69-
7067
/**
7168
* @Flow\Inject
7269
* @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface
@@ -131,6 +128,64 @@ public function showMappingCommand()
131128
}
132129
}
133130

131+
/**
132+
* Index a single node by the given identifier and workspace name
133+
*
134+
* @param string $identifier
135+
* @param string $workspace
136+
* @return void
137+
*/
138+
public function indexNodeCommand($identifier, $workspace = null)
139+
{
140+
if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) {
141+
$workspace = 'live';
142+
}
143+
144+
$indexNode = function ($identifier, Workspace $workspace, array $dimensions) {
145+
$context = $this->createContentContext($workspace->getName(), $dimensions);
146+
$node = $context->getNodeByIdentifier($identifier);
147+
if ($node === null) {
148+
$this->outputLine('Node with the given identifier is not found.');
149+
$this->quit();
150+
}
151+
$this->outputLine();
152+
$this->outputLine('Index node "%s" (%s)', [
153+
$node->getLabel(),
154+
$node->getIdentifier(),
155+
]);
156+
$this->outputLine(' workspace: %s', [
157+
$workspace->getName()
158+
]);
159+
$this->outputLine(' node type: %s', [
160+
$node->getNodeType()->getName()
161+
]);
162+
$this->outputLine(' dimensions: %s', [
163+
json_encode($dimensions)
164+
]);
165+
$this->nodeIndexer->indexNode($node);
166+
};
167+
168+
$indexInWorkspace = function ($identifier, Workspace $workspace) use ($indexNode) {
169+
$combinations = $this->contentDimensionCombinator->getAllAllowedCombinations();
170+
if ($combinations === []) {
171+
$indexNode($identifier, $workspace, []);
172+
} else {
173+
foreach ($combinations as $combination) {
174+
$indexNode($identifier, $workspace, $combination);
175+
}
176+
}
177+
};
178+
179+
if ($workspace === null) {
180+
foreach ($this->workspaceRepository->findAll() as $workspace) {
181+
$indexInWorkspace($identifier, $workspace);
182+
}
183+
} else {
184+
$workspace = $this->workspaceRepository->findByIdentifier($workspace);
185+
$indexInWorkspace($identifier, $workspace);
186+
}
187+
}
188+
134189
/**
135190
* Index all nodes by creating a new index and when everything was completed, switch the index alias.
136191
*
@@ -166,7 +221,6 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
166221
$this->logger->log(sprintf('Indexing %snodes ... ', ($limit !== null ? 'the first ' . $limit . ' ' : '')), LOG_INFO);
167222

168223
$count = 0;
169-
$this->limit = $limit;
170224

171225
if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) {
172226
$workspace = 'live';
@@ -181,10 +235,10 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
181235
};
182236
if ($workspace === null) {
183237
foreach ($this->workspaceRepository->findAll() as $workspace) {
184-
$count += $this->indexWorkspace($workspace->getName());
238+
$count += $this->indexWorkspace($workspace->getName(), $limit, $callback);
185239
}
186240
} else {
187-
$count = $this->indexWorkspace($workspace);
241+
$count += $this->indexWorkspace($workspace, $limit, $callback);
188242
}
189243

190244
$this->nodeIndexingManager->flushQueues();
@@ -206,81 +260,17 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
206260
public function cleanupCommand()
207261
{
208262
try {
209-
$removedIndices = $this->nodeIndexer->removeOldIndices();
210-
if (count($removedIndices) > 0) {
211-
if (count($removedIndices) === 1) {
212-
$this->logger->log('Removed old index ' . current($removedIndices) . '.');
213-
} else {
214-
$this->logger->log('Removed old indices ' . implode(', ', $removedIndices) . '.');
263+
$indicesToBeRemoved = $this->nodeIndexer->removeOldIndices();
264+
if (count($indicesToBeRemoved) > 0) {
265+
foreach ($indicesToBeRemoved as $indexToBeRemoved) {
266+
$this->logger->log('Removing old index ' . $indexToBeRemoved);
215267
}
216268
} else {
217269
$this->logger->log('Nothing to remove.');
218270
}
219271
} catch (\Flowpack\ElasticSearch\Transfer\Exception\ApiException $exception) {
220272
$response = json_decode($exception->getResponse());
221-
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s"', $response->status, $response->error->type, $response->error->reason));
273+
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s"', $response->status, $response->error));
222274
}
223275
}
224-
225-
/**
226-
* @param string $workspaceName
227-
* @return int
228-
*/
229-
protected function indexWorkspace($workspaceName)
230-
{
231-
$indexedNodes = 0;
232-
$combinations = $this->contentDimensionCombinator->getAllAllowedCombinations();
233-
if ($combinations === []) {
234-
$indexedNodes += $this->indexWorkspaceWithDimensions($workspaceName);
235-
} else {
236-
foreach ($combinations as $combination) {
237-
$indexedNodes += $this->indexWorkspaceWithDimensions($workspaceName, $combination);
238-
}
239-
}
240-
241-
return $indexedNodes;
242-
}
243-
244-
/**
245-
* @param string $workspaceName
246-
* @param array $dimensions
247-
* @return int
248-
*/
249-
protected function indexWorkspaceWithDimensions($workspaceName, array $dimensions = [])
250-
{
251-
$indexedNodes = 0;
252-
$context = $this->contextFactory->create(['workspaceName' => $workspaceName, 'dimensions' => $dimensions]);
253-
$rootNode = $context->getRootNode();
254-
255-
$indexedNodes += $this->traverseNodes($rootNode);
256-
257-
if ($dimensions === []) {
258-
$this->outputLine('Workspace "' . $workspaceName . '" without dimensions done. (Indexed ' . $indexedNodes . ' nodes)');
259-
} else {
260-
$this->outputLine('Workspace "' . $workspaceName . '" and dimensions "' . json_encode($dimensions) . '" done. (Indexed ' . $indexedNodes . ' nodes)');
261-
}
262-
263-
return $indexedNodes;
264-
}
265-
266-
/**
267-
* @param NodeInterface $currentNode
268-
* @param integer $traversedUntilNow
269-
* @return integer Indexed nodes in this traversal
270-
*/
271-
protected function traverseNodes(NodeInterface $currentNode, $traversedUntilNow = 0)
272-
{
273-
if ($this->limit !== null && $traversedUntilNow > $this->limit) {
274-
return $traversedUntilNow;
275-
}
276-
277-
$this->nodeIndexingManager->indexNode($currentNode);
278-
$traversedUntilNow++;
279-
280-
foreach ($currentNode->getChildNodes() as $childNode) {
281-
$traversedUntilNow = $this->traverseNodes($childNode, $traversedUntilNow);
282-
}
283-
284-
return $traversedUntilNow;
285-
}
286276
}

Classes/Driver/AbstractDriver.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver;
3+
4+
/*
5+
* This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package.
6+
*
7+
* (c) Contributors of the Neos Project - www.neos.io
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE file which was distributed with this
11+
* source code.
12+
*/
13+
14+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
15+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
16+
use Neos\Flow\Annotations as Flow;
17+
18+
/**
19+
* Abstract Elasticsearch driver
20+
*/
21+
abstract class AbstractDriver
22+
{
23+
/**
24+
* @Flow\Inject
25+
* @var ElasticSearchClient
26+
*/
27+
protected $searchClient;
28+
29+
/**
30+
* @Flow\Inject
31+
* @var LoggerInterface
32+
*/
33+
protected $logger;
34+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver;
3+
4+
/*
5+
* This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package.
6+
*
7+
* (c) Contributors of the Neos Project - www.neos.io
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE file which was distributed with this
11+
* source code.
12+
*/
13+
14+
use Neos\ContentRepository\Domain\Model\NodeInterface;
15+
16+
/**
17+
* Abstract Fulltext Indexer Driver
18+
*/
19+
abstract class AbstractIndexerDriver extends AbstractDriver
20+
{
21+
/**
22+
* Whether the node is configured as fulltext root.
23+
*
24+
* @param NodeInterface $node
25+
* @return boolean
26+
*/
27+
protected function isFulltextRoot(NodeInterface $node)
28+
{
29+
if ($node->getNodeType()->hasConfiguration('search')) {
30+
$elasticSearchSettingsForNode = $node->getNodeType()->getConfiguration('search');
31+
if (isset($elasticSearchSettingsForNode['fulltext']['isRoot']) && $elasticSearchSettingsForNode['fulltext']['isRoot'] === true) {
32+
return true;
33+
}
34+
}
35+
36+
return false;
37+
}
38+
}

0 commit comments

Comments
 (0)