Skip to content

Commit 1a5f2bc

Browse files
committed
MERGE: Merge branch '3.0' into master
2 parents a3872e1 + 0c92519 commit 1a5f2bc

8 files changed

Lines changed: 67 additions & 39 deletions

File tree

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ sudo: false
99
before_install:
1010
- export NEOS_TARGET_VERSION=3.0
1111
- cd ..
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
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
1414
- cd elasticsearch
1515
- bin/elasticsearch -d
1616
- cd ..

Classes/Command/NodeIndexCommandController.php

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

14+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
1415
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
1516
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait;
17+
use Flowpack\ElasticSearch\Domain\Model\Mapping;
18+
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
19+
use Neos\ContentRepository\Domain\Factory\NodeFactory;
20+
use Neos\ContentRepository\Domain\Model\Workspace;
21+
use Neos\ContentRepository\Domain\Repository\NodeDataRepository;
22+
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
23+
use Neos\ContentRepository\Domain\Service\ContentDimensionPresetSourceInterface;
1624
use Neos\ContentRepository\Domain\Service\Context;
1725
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
26+
use Neos\ContentRepository\Search\Indexer\NodeIndexerInterface;
1827
use Neos\Flow\Annotations as Flow;
1928
use Neos\Flow\Cli\CommandController;
20-
use Neos\ContentRepository\Domain\Model\Workspace;
29+
use Neos\Flow\Configuration\ConfigurationManager;
30+
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
31+
use Symfony\Component\Yaml\Yaml;
2132

2233
/**
2334
* Provides CLI features for index handling
@@ -30,31 +41,31 @@ class NodeIndexCommandController extends CommandController
3041

3142
/**
3243
* @Flow\Inject
33-
* @var \Neos\ContentRepository\Search\Indexer\NodeIndexerInterface
44+
* @var NodeIndexerInterface
3445
*/
3546
protected $nodeIndexer;
3647

3748
/**
3849
* @Flow\Inject
39-
* @var \Neos\ContentRepository\Domain\Repository\WorkspaceRepository
50+
* @var WorkspaceRepository
4051
*/
4152
protected $workspaceRepository;
4253

4354
/**
4455
* @Flow\Inject
45-
* @var \Neos\ContentRepository\Domain\Repository\NodeDataRepository
56+
* @var NodeDataRepository
4657
*/
4758
protected $nodeDataRepository;
4859

4960
/**
5061
* @Flow\Inject
51-
* @var \Neos\ContentRepository\Domain\Factory\NodeFactory
62+
* @var NodeFactory
5263
*/
5364
protected $nodeFactory;
5465

5566
/**
5667
* @Flow\Inject
57-
* @var \Neos\ContentRepository\Domain\Service\ContentDimensionPresetSourceInterface
68+
* @var ContentDimensionPresetSourceInterface
5869
*/
5970
protected $contentDimensionPresetSource;
6071

@@ -66,13 +77,13 @@ class NodeIndexCommandController extends CommandController
6677

6778
/**
6879
* @Flow\Inject
69-
* @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface
80+
* @var LoggerInterface
7081
*/
7182
protected $logger;
7283

7384
/**
7485
* @Flow\Inject
75-
* @var \Neos\Flow\Configuration\ConfigurationManager
86+
* @var ConfigurationManager
7687
*/
7788
protected $configurationManager;
7889

@@ -94,8 +105,8 @@ class NodeIndexCommandController extends CommandController
94105
*/
95106
public function initializeObject($cause)
96107
{
97-
if ($cause === \Neos\Flow\ObjectManagement\ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
98-
$this->settings = $this->configurationManager->getConfiguration(\Neos\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepository.Search');
108+
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
109+
$this->settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepository.Search');
99110
}
100111
}
101112

@@ -108,8 +119,8 @@ public function showMappingCommand()
108119
{
109120
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
110121
foreach ($nodeTypeMappingCollection as $mapping) {
111-
/** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
112-
$this->output(\Symfony\Component\Yaml\Yaml::dump($mapping->asArray(), 5, 2));
122+
/** @var Mapping $mapping */
123+
$this->output(Yaml::dump($mapping->asArray(), 5, 2));
113124
$this->outputLine();
114125
}
115126
$this->outputLine('------------');
@@ -187,6 +198,7 @@ public function indexNodeCommand($identifier, $workspace = null)
187198
$indexInWorkspace($identifier, $workspace);
188199
}
189200
} else {
201+
/** @var Workspace $workspaceInstance */
190202
$workspaceInstance = $this->workspaceRepository->findByIdentifier($workspace);
191203
if ($workspaceInstance === null) {
192204
$this->outputLine('The given workspace (%s) does not exist.', [$workspace]);
@@ -204,7 +216,7 @@ public function indexNodeCommand($identifier, $workspace = null)
204216
* @param integer $limit Amount of nodes to index at maximum
205217
* @param boolean $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
206218
* @param string $workspace name of the workspace which should be indexed
207-
* @param string $postfix Index postfix, index with the same postifix will be deleted if exist
219+
* @param string $postfix Index postfix, index with the same postfix will be deleted if exist
208220
* @return void
209221
*/
210222
public function buildCommand($limit = null, $update = false, $workspace = null, $postfix = null)
@@ -217,21 +229,9 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
217229
if ($update === true) {
218230
$this->logger->log('!!! Update Mode (Development) active!', LOG_INFO);
219231
} else {
220-
$this->nodeIndexer->setIndexNamePostfix($postfix ?: time());
221-
if ($this->nodeIndexer->getIndex()->exists() === true) {
222-
$this->logger->log(sprintf('Deleted index with the same postfix (%s)!', $postfix), LOG_WARNING);
223-
$this->nodeIndexer->getIndex()->delete();
224-
}
225-
$this->nodeIndexer->getIndex()->create();
226-
$this->logger->log('Created index ' . $this->nodeIndexer->getIndexName(), LOG_INFO);
227-
228-
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
229-
foreach ($nodeTypeMappingCollection as $mapping) {
230-
/** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
231-
$mapping->apply();
232-
}
233-
$this->logger->log('Updated Mapping.', LOG_INFO);
232+
$this->createNewIndex($postfix);
234233
}
234+
$this->applyMapping();
235235

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

@@ -283,7 +283,7 @@ public function cleanupCommand()
283283
} else {
284284
$this->logger->log('Nothing to remove.');
285285
}
286-
} catch (\Flowpack\ElasticSearch\Transfer\Exception\ApiException $exception) {
286+
} catch (ApiException $exception) {
287287
$response = json_decode($exception->getResponse());
288288
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s"', $response->status, $response->error->type, $response->error->reason));
289289
}
@@ -314,4 +314,35 @@ protected function createContentContext($workspaceName, array $dimensions = [])
314314
return $this->contextFactory->create($contextProperties);
315315
}
316316

317+
/**
318+
* Create a new index with the given $postfix.
319+
*
320+
* @param string $postfix
321+
* @return void
322+
*/
323+
protected function createNewIndex($postfix)
324+
{
325+
$this->nodeIndexer->setIndexNamePostfix($postfix ?: time());
326+
if ($this->nodeIndexer->getIndex()->exists() === true) {
327+
$this->logger->log(sprintf('Deleted index with the same postfix (%s)!', $postfix), LOG_WARNING);
328+
$this->nodeIndexer->getIndex()->delete();
329+
}
330+
$this->nodeIndexer->getIndex()->create();
331+
$this->logger->log('Created index ' . $this->nodeIndexer->getIndexName(), LOG_INFO);
332+
}
333+
334+
/**
335+
* Apply the mapping to the current index.
336+
*
337+
* @return void
338+
*/
339+
protected function applyMapping()
340+
{
341+
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
342+
foreach ($nodeTypeMappingCollection as $mapping) {
343+
/** @var Mapping $mapping */
344+
$mapping->apply();
345+
}
346+
$this->logger->log('Updated Mapping.', LOG_INFO);
347+
}
317348
}

Classes/Driver/Version1/DocumentDriver.php

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

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\AbstractDriver;
1515
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\DocumentDriverInterface;
16-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\DriverInterface;
1716
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
1817
use Flowpack\ElasticSearch\Domain\Model\Index;
1918
use Neos\Flow\Annotations as Flow;

Classes/Driver/Version1/IndexDriver.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\AbstractDriver;
15-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\DriverInterface;
1615
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\IndexDriverInterface;
1716
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception;
1817
use Neos\Flow\Annotations as Flow;
@@ -52,10 +51,12 @@ public function deleteIndex($index)
5251
public function indexesByAlias($alias)
5352
{
5453
$response = $this->searchClient->request('GET', '/_alias/' . $alias);
55-
if ($response->getStatusCode() !== 200) {
54+
if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 404) {
5655
throw new Exception('The alias "' . $alias . '" was not found with some unexpected error... (return code: ' . $response->getStatusCode() . ')', 1383650137);
5756
}
5857

59-
return array_keys($response->getTreatedContent());
58+
// return empty array if content from response cannot be read as an array
59+
$treatedContent = $response->getTreatedContent();
60+
return is_array($treatedContent) ? array_keys($treatedContent) : [];
6061
}
6162
}

Classes/Driver/Version1/IndexerDriver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\AbstractIndexerDriver;
15-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\DriverInterface;
1615
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\IndexerDriverInterface;
1716
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
1817
use Flowpack\ElasticSearch\Domain\Model\Document as ElasticSearchDocument;

Classes/Factory/AbstractDriverSpecificObjectFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
* source code.
1212
*/
1313

14-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\DriverInterface;
1514
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\DriverConfigurationException;
1615
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
1716
use Neos\Flow\Annotations as Flow;

Classes/Factory/DriverFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\DocumentDriverInterface;
15-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\DriverInterface;
1615
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\IndexerDriverInterface;
1716
use Neos\Flow\Annotations as Flow;
1817

Classes/Indexer/NodeIndexer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function getIndex()
155155
* Index this node, and add it to the current bulk request.
156156
*
157157
* @param NodeInterface $node
158-
* @param string $targetWorkspaceName In case this is triggered during publishing, a workspace name will be passed in
158+
* @param string $targetWorkspaceName In case indexing is triggered during publishing, a target workspace name will be passed in
159159
* @return void
160160
* @throws \Neos\ContentRepository\Search\Exception\IndexingException
161161
*/
@@ -214,7 +214,7 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null)
214214
}
215215

216216
if ($this->isFulltextEnabled($node)) {
217-
$this->currentBulkRequest[] = $this->indexerDriver->document($this->getIndexName(), $node, $document, $documentData, $fulltextIndexOfNode, $targetWorkspaceName);
217+
$this->currentBulkRequest[] = $this->indexerDriver->document($this->getIndexName(), $node, $document, $documentData);
218218
$this->currentBulkRequest[] = $this->indexerDriver->fulltext($node, $fulltextIndexOfNode, $targetWorkspaceName);
219219
}
220220

0 commit comments

Comments
 (0)