Skip to content

Commit ed41ef0

Browse files
committed
Merge branch 'master' into task-improve-errorhandling
2 parents c6c9f18 + 1a5f2bc commit ed41ef0

64 files changed

Lines changed: 3204 additions & 1069 deletions

File tree

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/elasticsearch/elasticsearch-1.7.5.zip && unzip elasticsearch-1.7.5.zip
11-
- mv elasticsearch-1.7.5 elasticsearch
12+
- if [ "$ES" = 1 ]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.6.zip && unzip elasticsearch-1.7.6.zip && mv elasticsearch-1.7.6 elasticsearch; fi
13+
- if [ "$ES" = 2 ]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.4.5.zip && unzip elasticsearch-2.4.5.zip && mv elasticsearch-2.4.5 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/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Client/ClientFactory.php renamed to Classes/Client/ClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
1515
use Flowpack\ElasticSearch\Domain\Model\Client;
16-
use TYPO3\Flow\Annotations as Flow;
16+
use Neos\Flow\Annotations as Flow;
1717

1818
/**
1919
* ClientFactory

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Command/NodeIndexCommandController.php renamed to Classes/Command/NodeIndexCommandController.php

Lines changed: 164 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,25 @@
1212
*/
1313

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\Error\ErrorInterface;
15+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
1516
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
1617
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\ErrorHandlingService;
1718
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait;
18-
use TYPO3\Flow\Annotations as Flow;
19-
use TYPO3\Flow\Cli\CommandController;
19+
use Flowpack\ElasticSearch\Domain\Model\Mapping;
20+
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
21+
use Neos\ContentRepository\Domain\Factory\NodeFactory;
22+
use Neos\ContentRepository\Domain\Model\Workspace;
23+
use Neos\ContentRepository\Domain\Repository\NodeDataRepository;
24+
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
25+
use Neos\ContentRepository\Domain\Service\ContentDimensionPresetSourceInterface;
26+
use Neos\ContentRepository\Domain\Service\Context;
27+
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
28+
use Neos\ContentRepository\Search\Indexer\NodeIndexerInterface;
29+
use Neos\Flow\Annotations as Flow;
30+
use Neos\Flow\Cli\CommandController;
31+
use Neos\Flow\Configuration\ConfigurationManager;
32+
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
33+
use Symfony\Component\Yaml\Yaml;
2034

2135
/**
2236
* Provides CLI features for index handling
@@ -35,31 +49,31 @@ class NodeIndexCommandController extends CommandController
3549

3650
/**
3751
* @Flow\Inject
38-
* @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer
52+
* @var NodeIndexerInterface
3953
*/
4054
protected $nodeIndexer;
4155

4256
/**
4357
* @Flow\Inject
44-
* @var \TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository
58+
* @var WorkspaceRepository
4559
*/
4660
protected $workspaceRepository;
4761

4862
/**
4963
* @Flow\Inject
50-
* @var \TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository
64+
* @var NodeDataRepository
5165
*/
5266
protected $nodeDataRepository;
5367

5468
/**
5569
* @Flow\Inject
56-
* @var \TYPO3\TYPO3CR\Domain\Factory\NodeFactory
70+
* @var NodeFactory
5771
*/
5872
protected $nodeFactory;
5973

6074
/**
6175
* @Flow\Inject
62-
* @var \TYPO3\Neos\Domain\Service\ContentDimensionPresetSourceInterface
76+
* @var ContentDimensionPresetSourceInterface
6377
*/
6478
protected $contentDimensionPresetSource;
6579

@@ -71,16 +85,22 @@ class NodeIndexCommandController extends CommandController
7185

7286
/**
7387
* @Flow\Inject
74-
* @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface
88+
* @var LoggerInterface
7589
*/
7690
protected $logger;
7791

7892
/**
7993
* @Flow\Inject
80-
* @var \TYPO3\Flow\Configuration\ConfigurationManager
94+
* @var ConfigurationManager
8195
*/
8296
protected $configurationManager;
8397

98+
/**
99+
* @Flow\Inject
100+
* @var ContextFactoryInterface
101+
*/
102+
protected $contextFactory;
103+
84104
/**
85105
* @var array
86106
*/
@@ -93,8 +113,8 @@ class NodeIndexCommandController extends CommandController
93113
*/
94114
public function initializeObject($cause)
95115
{
96-
if ($cause === \TYPO3\Flow\Object\ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
97-
$this->settings = $this->configurationManager->getConfiguration(\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.TYPO3CR.Search');
116+
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
117+
$this->settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepository.Search');
98118
}
99119
}
100120

@@ -107,8 +127,8 @@ public function showMappingCommand()
107127
{
108128
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
109129
foreach ($nodeTypeMappingCollection as $mapping) {
110-
/** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
111-
$this->output(\Symfony\Component\Yaml\Yaml::dump($mapping->asArray(), 5, 2));
130+
/** @var Mapping $mapping */
131+
$this->output(Yaml::dump($mapping->asArray(), 5, 2));
112132
$this->outputLine();
113133
}
114134
$this->outputLine('------------');
@@ -133,6 +153,69 @@ public function showMappingCommand()
133153
}
134154
}
135155

156+
/**
157+
* Index a single node by the given identifier and workspace name
158+
*
159+
* @param string $identifier
160+
* @param string $workspace
161+
* @return void
162+
*/
163+
public function indexNodeCommand($identifier, $workspace = null)
164+
{
165+
if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) {
166+
$workspace = 'live';
167+
}
168+
169+
$indexNode = function ($identifier, Workspace $workspace, array $dimensions) {
170+
$context = $this->createContentContext($workspace->getName(), $dimensions);
171+
$node = $context->getNodeByIdentifier($identifier);
172+
if ($node === null) {
173+
$this->outputLine('Node with the given identifier is not found.');
174+
$this->quit();
175+
}
176+
$this->outputLine();
177+
$this->outputLine('Index node "%s" (%s)', [
178+
$node->getLabel(),
179+
$node->getIdentifier(),
180+
]);
181+
$this->outputLine(' workspace: %s', [
182+
$workspace->getName()
183+
]);
184+
$this->outputLine(' node type: %s', [
185+
$node->getNodeType()->getName()
186+
]);
187+
$this->outputLine(' dimensions: %s', [
188+
json_encode($dimensions)
189+
]);
190+
$this->nodeIndexer->indexNode($node);
191+
};
192+
193+
$indexInWorkspace = function ($identifier, Workspace $workspace) use ($indexNode) {
194+
$combinations = $this->contentDimensionCombinator->getAllAllowedCombinations();
195+
if ($combinations === []) {
196+
$indexNode($identifier, $workspace, []);
197+
} else {
198+
foreach ($combinations as $combination) {
199+
$indexNode($identifier, $workspace, $combination);
200+
}
201+
}
202+
};
203+
204+
if ($workspace === null) {
205+
foreach ($this->workspaceRepository->findAll() as $workspace) {
206+
$indexInWorkspace($identifier, $workspace);
207+
}
208+
} else {
209+
/** @var Workspace $workspaceInstance */
210+
$workspaceInstance = $this->workspaceRepository->findByIdentifier($workspace);
211+
if ($workspaceInstance === null) {
212+
$this->outputLine('The given workspace (%s) does not exist.', [$workspace]);
213+
$this->quit(1);
214+
}
215+
$indexInWorkspace($identifier, $workspaceInstance);
216+
}
217+
}
218+
136219
/**
137220
* Index all nodes by creating a new index and when everything was completed, switch the index alias.
138221
*
@@ -141,29 +224,22 @@ public function showMappingCommand()
141224
* @param integer $limit Amount of nodes to index at maximum
142225
* @param boolean $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
143226
* @param string $workspace name of the workspace which should be indexed
144-
* @param string $postfix Index postfix, index with the same postifix will be deleted if exist
227+
* @param string $postfix Index postfix, index with the same postfix will be deleted if exist
145228
* @return void
146229
*/
147230
public function buildCommand($limit = null, $update = false, $workspace = null, $postfix = null)
148231
{
232+
if ($workspace !== null && $this->workspaceRepository->findByIdentifier($workspace) === null) {
233+
$this->logger->log('The given workspace (' . $workspace . ') does not exist.', LOG_ERR);
234+
$this->quit(1);
235+
}
236+
149237
if ($update === true) {
150238
$this->logger->log('!!! Update Mode (Development) active!', LOG_INFO);
151239
} else {
152-
$this->nodeIndexer->setIndexNamePostfix($postfix ?: time());
153-
if ($this->nodeIndexer->getIndex()->exists() === true) {
154-
$this->logger->log(sprintf('Deleted index with the same postfix (%s)!', $postfix), LOG_WARNING);
155-
$this->nodeIndexer->getIndex()->delete();
156-
}
157-
$this->nodeIndexer->getIndex()->create();
158-
$this->logger->log('Created index ' . $this->nodeIndexer->getIndexName(), LOG_INFO);
159-
160-
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
161-
foreach ($nodeTypeMappingCollection as $mapping) {
162-
/** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
163-
$mapping->apply();
164-
}
165-
$this->logger->log('Updated Mapping.', LOG_INFO);
240+
$this->createNewIndex($postfix);
166241
}
242+
$this->applyMapping();
167243

168244
$this->logger->log(sprintf('Indexing %snodes ... ', ($limit !== null ? 'the first ' . $limit . ' ' : '')), LOG_INFO);
169245

@@ -197,7 +273,7 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
197273
$this->outputLine('<error>Error</error> ' . $error->message());
198274
}
199275
$this->outputLine();
200-
$this->outputLine('<error>Check your logs for more informations</error>');
276+
$this->outputLine('<error>Check your logs for more information</error>');
201277
} else {
202278
$this->logger->log('Done. (indexed ' . $count . ' nodes)', LOG_INFO);
203279
}
@@ -225,9 +301,66 @@ public function cleanupCommand()
225301
} else {
226302
$this->logger->log('Nothing to remove.');
227303
}
228-
} catch (\Flowpack\ElasticSearch\Transfer\Exception\ApiException $exception) {
304+
} catch (ApiException $exception) {
229305
$response = json_decode($exception->getResponse());
230-
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s"', $response->status, $response->error));
306+
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s"', $response->status, $response->error->type, $response->error->reason));
307+
}
308+
}
309+
310+
/**
311+
* Create a ContentContext based on the given workspace name
312+
*
313+
* @param string $workspaceName Name of the workspace to set for the context
314+
* @param array $dimensions Optional list of dimensions and their values which should be set
315+
* @return Context
316+
*/
317+
protected function createContentContext($workspaceName, array $dimensions = [])
318+
{
319+
$contextProperties = [
320+
'workspaceName' => $workspaceName,
321+
'invisibleContentShown' => true,
322+
'inaccessibleContentShown' => true
323+
];
324+
325+
if ($dimensions !== []) {
326+
$contextProperties['dimensions'] = $dimensions;
327+
$contextProperties['targetDimensions'] = array_map(function ($dimensionValues) {
328+
return array_shift($dimensionValues);
329+
}, $dimensions);
330+
}
331+
332+
return $this->contextFactory->create($contextProperties);
333+
}
334+
335+
/**
336+
* Create a new index with the given $postfix.
337+
*
338+
* @param string $postfix
339+
* @return void
340+
*/
341+
protected function createNewIndex($postfix)
342+
{
343+
$this->nodeIndexer->setIndexNamePostfix($postfix ?: time());
344+
if ($this->nodeIndexer->getIndex()->exists() === true) {
345+
$this->logger->log(sprintf('Deleted index with the same postfix (%s)!', $postfix), LOG_WARNING);
346+
$this->nodeIndexer->getIndex()->delete();
347+
}
348+
$this->nodeIndexer->getIndex()->create();
349+
$this->logger->log('Created index ' . $this->nodeIndexer->getIndexName(), LOG_INFO);
350+
}
351+
352+
/**
353+
* Apply the mapping to the current index.
354+
*
355+
* @return void
356+
*/
357+
protected function applyMapping()
358+
{
359+
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
360+
foreach ($nodeTypeMappingCollection as $mapping) {
361+
/** @var Mapping $mapping */
362+
$mapping->apply();
231363
}
364+
$this->logger->log('Updated Mapping.', LOG_INFO);
232365
}
233366
}

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Command/NodeTypeCommandController.php renamed to Classes/Command/NodeTypeCommandController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
* source code.
1212
*/
1313

14-
use TYPO3\Flow\Annotations as Flow;
15-
use TYPO3\Flow\Cli\CommandController;
14+
use Neos\Flow\Annotations as Flow;
15+
use Neos\Flow\Cli\CommandController;
1616

1717
/**
1818
* Provides CLI features for debugging the node types.
@@ -25,7 +25,7 @@ class NodeTypeCommandController extends CommandController
2525
{
2626
/**
2727
* @Flow\Inject
28-
* @var \TYPO3\TYPO3CR\Domain\Service\NodeTypeManager
28+
* @var \Neos\ContentRepository\Domain\Service\NodeTypeManager
2929
*/
3030
protected $nodeTypeManager;
3131

@@ -38,13 +38,13 @@ class NodeTypeCommandController extends CommandController
3838
public function showCommand($nodeType = null)
3939
{
4040
if ($nodeType !== null) {
41-
/** @var \TYPO3\TYPO3CR\Domain\Model\NodeType $nodeType */
41+
/** @var \Neos\ContentRepository\Domain\Model\NodeType $nodeType */
4242
$nodeType = $this->nodeTypeManager->getNodeType($nodeType);
4343
$configuration = $nodeType->getFullConfiguration();
4444
} else {
4545
$nodeTypes = $this->nodeTypeManager->getNodeTypes();
4646
$configuration = [];
47-
/** @var \TYPO3\TYPO3CR\Domain\Model\NodeType $nodeType */
47+
/** @var \Neos\ContentRepository\Domain\Model\NodeType $nodeType */
4848
foreach ($nodeTypes as $nodeTypeName => $nodeType) {
4949
$configuration[$nodeTypeName] = $nodeType->getFullConfiguration();
5050
}

0 commit comments

Comments
 (0)