Skip to content

Commit 877aea4

Browse files
committed
Merge branch 'master' into task/some-docs-and-code-tweaks
# Conflicts: # Classes/Command/NodeIndexCommandController.php # Classes/Eel/ElasticSearchQueryBuilder.php # Tests/Unit/Eel/ElasticSearchQueryBuilderTest.php
2 parents 3f96caa + dd2ca2a commit 877aea4

Some content is hidden

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

50 files changed

+503
-309
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ matrix:
1515
before_install:
1616
- export NEOS_TARGET_VERSION=4.0
1717
- cd ..
18-
- if [ "$ES" = 5 ]; then wget --no-check-certificate https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.8.zip && unzip elasticsearch-5.6.8.zip && mv elasticsearch-5.6.8 elasticsearch; fi
18+
- if [ "$ES" = 5 ]; then wget --no-check-certificate https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.15.zip && unzip elasticsearch-5.6.15.zip && mv elasticsearch-5.6.15 elasticsearch; fi
1919
- cd elasticsearch
2020
- bin/elasticsearch -d
2121
- cd ..

Classes/Client/ClientFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Client;
36

47
/*
@@ -34,7 +37,7 @@ class ClientFactory
3437
* @return Client
3538
* @throws \Flowpack\ElasticSearch\Exception
3639
*/
37-
public function create()
40+
public function create(): Client
3841
{
3942
return $this->clientFactory->create(null, ElasticSearchClient::class);
4043
}

Classes/Command/NodeIndexCommandController.php

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Command;
36

47
/*
@@ -11,8 +14,10 @@
1114
* source code.
1215
*/
1316

14-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\NodeTypeMappingBuilderInterface;
17+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception as CRAException;
1518
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\Error\ErrorInterface;
19+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\NodeTypeMappingBuilderInterface;
20+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer;
1621
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
1722
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\ErrorHandlingService;
1823
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait;
@@ -51,8 +56,7 @@ class NodeIndexCommandController extends CommandController
5156
protected $errorHandlingService;
5257

5358
/**
54-
* @Flow\Inject
55-
* @var NodeIndexerInterface
59+
* @var NodeIndexer
5660
*/
5761
protected $nodeIndexer;
5862

@@ -103,13 +107,22 @@ class NodeIndexCommandController extends CommandController
103107
*/
104108
protected $settings;
105109

110+
/**
111+
* @param NodeIndexerInterface $nodeIndexer
112+
* @return void
113+
*/
114+
public function injectNodeIndexer(NodeIndexerInterface $nodeIndexer): void
115+
{
116+
$this->nodeIndexer = $nodeIndexer;
117+
}
118+
106119
/**
107120
* Called by the Flow object framework after creating the object and resolving all dependencies.
108121
*
109122
* @param integer $cause Creation cause
110123
* @throws InvalidConfigurationTypeException
111124
*/
112-
public function initializeObject($cause)
125+
public function initializeObject(int $cause): void
113126
{
114127
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
115128
$this->settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepository.Search');
@@ -120,8 +133,9 @@ public function initializeObject($cause)
120133
* Show the mapping which would be sent to the ElasticSearch server
121134
*
122135
* @return void
136+
* @throws CRAException
123137
*/
124-
public function showMappingCommand()
138+
public function showMappingCommand(): void
125139
{
126140
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
127141
foreach ($nodeTypeMappingCollection as $mapping) {
@@ -159,7 +173,7 @@ public function showMappingCommand()
159173
* @return void
160174
* @throws StopActionException
161175
*/
162-
public function indexNodeCommand($identifier, $workspace = null)
176+
public function indexNodeCommand(string $identifier, string $workspace = null): void
163177
{
164178
if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) {
165179
$workspace = 'live';
@@ -201,8 +215,8 @@ public function indexNodeCommand($identifier, $workspace = null)
201215
};
202216

203217
if ($workspace === null) {
204-
foreach ($this->workspaceRepository->findAll() as $workspace) {
205-
$indexInWorkspace($identifier, $workspace);
218+
foreach ($this->workspaceRepository->findAll() as $workspaceToIndex) {
219+
$indexInWorkspace($identifier, $workspaceToIndex);
206220
}
207221
} else {
208222
/** @var Workspace $workspaceInstance */
@@ -220,28 +234,30 @@ public function indexNodeCommand($identifier, $workspace = null)
220234
*
221235
* This command (re-)indexes all nodes contained in the content repository and sets the schema beforehand.
222236
*
223-
* @param integer $limit Amount of nodes to index at maximum
224-
* @param boolean $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
237+
* @param int $limit Amount of nodes to index at maximum
238+
* @param bool $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
225239
* @param string $workspace name of the workspace which should be indexed
226240
* @param string $postfix Index postfix, index with the same postfix will be deleted if exist
227241
* @return void
242+
* @throws ApiException
228243
* @throws StopActionException
244+
* @throws CRAException
229245
*/
230-
public function buildCommand($limit = null, $update = false, $workspace = null, $postfix = '')
246+
public function buildCommand(int $limit = null, bool $update = false, string $workspace = null, string $postfix = ''): void
231247
{
232248
if ($workspace !== null && $this->workspaceRepository->findByIdentifier($workspace) === null) {
233249
$this->logger->log('The given workspace (' . $workspace . ') does not exist.', LOG_ERR);
234250
$this->quit(1);
235251
}
236252

237253
if ($update === true) {
238-
$this->logger->log('!!! Update Mode (Development) active!', LOG_INFO);
254+
$this->logger->log('!!! Update Mode (Development) active!');
239255
} else {
240256
$this->createNewIndex($postfix);
241257
}
242258
$this->applyMapping();
243259

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

246262
$count = 0;
247263

@@ -257,8 +273,8 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
257273
}
258274
};
259275
if ($workspace === null) {
260-
foreach ($this->workspaceRepository->findAll() as $workspace) {
261-
$count += $this->indexWorkspace($workspace->getName(), $limit, $callback);
276+
foreach ($this->workspaceRepository->findAll() as $workspaceToIndex) {
277+
$count += $this->indexWorkspace($workspaceToIndex->getName(), $limit, $callback);
262278
}
263279
} else {
264280
$count += $this->indexWorkspace($workspace, $limit, $callback);
@@ -289,8 +305,9 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
289305
* Clean up old indexes (i.e. all but the current one)
290306
*
291307
* @return void
308+
* @throws CRAException
292309
*/
293-
public function cleanupCommand()
310+
public function cleanupCommand(): void
294311
{
295312
try {
296313
$indicesToBeRemoved = $this->nodeIndexer->removeOldIndices();
@@ -316,30 +333,32 @@ public function cleanupCommand()
316333
*
317334
* @param string $postfix
318335
* @return void
336+
* @throws CRAException
319337
*/
320-
protected function createNewIndex(string $postfix)
338+
protected function createNewIndex(string $postfix): void
321339
{
322-
$this->nodeIndexer->setIndexNamePostfix($postfix ?: time());
340+
$this->nodeIndexer->setIndexNamePostfix($postfix ?: (string)time());
323341
if ($this->nodeIndexer->getIndex()->exists() === true) {
324342
$this->logger->log(sprintf('Deleted index with the same postfix (%s)!', $postfix), LOG_WARNING);
325343
$this->nodeIndexer->getIndex()->delete();
326344
}
327345
$this->nodeIndexer->getIndex()->create();
328-
$this->logger->log('Created index ' . $this->nodeIndexer->getIndexName(), LOG_INFO);
346+
$this->logger->log('Created index ' . $this->nodeIndexer->getIndexName());
329347
}
330348

331349
/**
332350
* Apply the mapping to the current index.
333351
*
334352
* @return void
353+
* @throws CRAException
335354
*/
336-
protected function applyMapping()
355+
protected function applyMapping(): void
337356
{
338357
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
339358
foreach ($nodeTypeMappingCollection as $mapping) {
340359
/** @var Mapping $mapping */
341360
$mapping->apply();
342361
}
343-
$this->logger->log('Updated Mapping.', LOG_INFO);
362+
$this->logger->log('Updated Mapping.');
344363
}
345364
}

Classes/Command/NodeTypeCommandController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Command;
36

47
/*
@@ -11,10 +14,12 @@
1114
* source code.
1215
*/
1316

17+
use Neos\ContentRepository\Domain\Model\NodeType;
1418
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
1519
use Neos\ContentRepository\Exception\NodeTypeNotFoundException;
1620
use Neos\Flow\Annotations as Flow;
1721
use Neos\Flow\Cli\CommandController;
22+
use Symfony\Component\Yaml\Yaml;
1823

1924
/**
2025
* Provides CLI features for debugging the node types.
@@ -38,20 +43,20 @@ class NodeTypeCommandController extends CommandController
3843
* @return void
3944
* @throws NodeTypeNotFoundException
4045
*/
41-
public function showCommand($nodeType = null)
46+
public function showCommand(string $nodeType = null): void
4247
{
4348
if ($nodeType !== null) {
44-
/** @var \Neos\ContentRepository\Domain\Model\NodeType $nodeType */
49+
/** @var NodeType $nodeType */
4550
$nodeType = $this->nodeTypeManager->getNodeType($nodeType);
4651
$configuration = $nodeType->getFullConfiguration();
4752
} else {
4853
$nodeTypes = $this->nodeTypeManager->getNodeTypes();
4954
$configuration = [];
50-
/** @var \Neos\ContentRepository\Domain\Model\NodeType $nodeType */
55+
/** @var NodeType $nodeType */
5156
foreach ($nodeTypes as $nodeTypeName => $nodeType) {
5257
$configuration[$nodeTypeName] = $nodeType->getFullConfiguration();
5358
}
5459
}
55-
$this->output(\Symfony\Component\Yaml\Yaml::dump($configuration, 5, 2));
60+
$this->output(Yaml::dump($configuration, 5, 2));
5661
}
5762
}

Classes/Driver/AbstractDriver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver;
36

47
/*

Classes/Driver/AbstractIndexerDriver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver;
36

47
/*

Classes/Driver/AbstractNodeTypeMappingBuilder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver;
36

47
/*
@@ -55,7 +58,7 @@ abstract class AbstractNodeTypeMappingBuilder implements NodeTypeMappingBuilderI
5558
* @param integer $cause Creation cause
5659
* @throws InvalidConfigurationTypeException
5760
*/
58-
public function initializeObject($cause)
61+
public function initializeObject($cause): void
5962
{
6063
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
6164
$settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepository.Search');
@@ -77,7 +80,7 @@ public function convertNodeTypeNameToMappingName(string $nodeTypeName): string
7780
/**
7881
* @return Result
7982
*/
80-
public function getLastMappingErrors()
83+
public function getLastMappingErrors(): Result
8184
{
8285
return $this->lastMappingErrors;
8386
}

0 commit comments

Comments
 (0)