Skip to content

Commit 820e873

Browse files
Merge branch 'master' into feature-disable-indexin-per-nodetype-or-namespace
2 parents 97f97a8 + 8f7d272 commit 820e873

55 files changed

Lines changed: 664 additions & 513 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ git:
66
addons:
77
apt:
88
packages:
9-
- oracle-java8-set-default
9+
- openjdk-8-jre-headless
1010
matrix:
1111
include:
1212
- php: 7.2
1313
env: ES=5
1414

1515
before_install:
16-
- export NEOS_TARGET_VERSION=4.0
16+
- export NEOS_TARGET_VERSION=5.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 ..
2222
- git clone https://github.com/neos/neos-base-distribution.git -b ${NEOS_TARGET_VERSION}
2323
- cd neos-base-distribution
2424
- composer require --no-update --no-interaction flowpack/elasticsearch-contentrepositoryadaptor:dev-master
25+
- composer require --no-update --no-interaction neos/nodetypes
2526
install:
2627
- composer install --no-interaction
2728
- 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: 49 additions & 29 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,9 +14,10 @@
1114
* source code.
1215
*/
1316

17+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception as CRAException;
1418
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\Error\ErrorInterface;
1519
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\NodeTypeMappingBuilderInterface;
16-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
20+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer;
1721
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\ErrorHandlingService;
1822
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait;
1923
use Flowpack\ElasticSearch\Domain\Model\Mapping;
@@ -28,9 +32,11 @@
2832
use Neos\Flow\Cli\CommandController;
2933
use Neos\Flow\Configuration\ConfigurationManager;
3034
use Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException;
35+
use Neos\Flow\Log\Utility\LogEnvironment;
3136
use Neos\Flow\Mvc\Exception\StopActionException;
3237
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
3338
use Neos\Neos\Controller\CreateContentContextTrait;
39+
use Psr\Log\LoggerInterface;
3440
use Symfony\Component\Yaml\Yaml;
3541

3642
/**
@@ -51,8 +57,7 @@ class NodeIndexCommandController extends CommandController
5157
protected $errorHandlingService;
5258

5359
/**
54-
* @Flow\Inject
55-
* @var NodeIndexerInterface
60+
* @var NodeIndexer
5661
*/
5762
protected $nodeIndexer;
5863

@@ -103,13 +108,22 @@ class NodeIndexCommandController extends CommandController
103108
*/
104109
protected $settings;
105110

111+
/**
112+
* @param NodeIndexerInterface $nodeIndexer
113+
* @return void
114+
*/
115+
public function injectNodeIndexer(NodeIndexerInterface $nodeIndexer): void
116+
{
117+
$this->nodeIndexer = $nodeIndexer;
118+
}
119+
106120
/**
107121
* Called by the Flow object framework after creating the object and resolving all dependencies.
108122
*
109123
* @param integer $cause Creation cause
110124
* @throws InvalidConfigurationTypeException
111125
*/
112-
public function initializeObject($cause)
126+
public function initializeObject(int $cause): void
113127
{
114128
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
115129
$this->settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepository.Search');
@@ -120,8 +134,9 @@ public function initializeObject($cause)
120134
* Show the mapping which would be sent to the ElasticSearch server
121135
*
122136
* @return void
137+
* @throws CRAException
123138
*/
124-
public function showMappingCommand()
139+
public function showMappingCommand(): void
125140
{
126141
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
127142
foreach ($nodeTypeMappingCollection as $mapping) {
@@ -145,7 +160,7 @@ public function showMappingCommand()
145160
$this->outputLine('<b>Mapping Warnings</b>');
146161
foreach ($mappingErrors->getFlattenedWarnings() as $warnings) {
147162
foreach ($warnings as $warning) {
148-
$this->outputLine($warning);
163+
$this->outputLine((string)$warning);
149164
}
150165
}
151166
}
@@ -159,7 +174,7 @@ public function showMappingCommand()
159174
* @return void
160175
* @throws StopActionException
161176
*/
162-
public function indexNodeCommand($identifier, $workspace = null)
177+
public function indexNodeCommand(string $identifier, string $workspace = null): void
163178
{
164179
if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) {
165180
$workspace = 'live';
@@ -201,8 +216,8 @@ public function indexNodeCommand($identifier, $workspace = null)
201216
};
202217

203218
if ($workspace === null) {
204-
foreach ($this->workspaceRepository->findAll() as $workspace) {
205-
$indexInWorkspace($identifier, $workspace);
219+
foreach ($this->workspaceRepository->findAll() as $workspaceToIndex) {
220+
$indexInWorkspace($identifier, $workspaceToIndex);
206221
}
207222
} else {
208223
/** @var Workspace $workspaceInstance */
@@ -220,28 +235,30 @@ public function indexNodeCommand($identifier, $workspace = null)
220235
*
221236
* This command (re-)indexes all nodes contained in the content repository and sets the schema beforehand.
222237
*
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*.
238+
* @param int $limit Amount of nodes to index at maximum
239+
* @param bool $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
225240
* @param string $workspace name of the workspace which should be indexed
226241
* @param string $postfix Index postfix, index with the same postfix will be deleted if exist
227242
* @return void
243+
* @throws ApiException
228244
* @throws StopActionException
245+
* @throws CRAException
229246
*/
230-
public function buildCommand($limit = null, $update = false, $workspace = null, $postfix = '')
247+
public function buildCommand(int $limit = null, bool $update = false, string $workspace = null, string $postfix = ''): void
231248
{
232249
if ($workspace !== null && $this->workspaceRepository->findByIdentifier($workspace) === null) {
233-
$this->logger->log('The given workspace (' . $workspace . ') does not exist.', LOG_ERR);
250+
$this->logger->error('The given workspace (' . $workspace . ') does not exist.', LogEnvironment::fromMethodName(__METHOD__));
234251
$this->quit(1);
235252
}
236253

237254
if ($update === true) {
238-
$this->logger->log('!!! Update Mode (Development) active!', LOG_INFO);
255+
$this->logger->warning('!!! Update Mode (Development) active!', LogEnvironment::fromMethodName(__METHOD__));
239256
} else {
240257
$this->createNewIndex($postfix);
241258
}
242259
$this->applyMapping();
243260

244-
$this->logger->log(sprintf('Indexing %snodes ... ', ($limit !== null ? 'the first ' . $limit . ' ' : '')), LOG_INFO);
261+
$this->logger->info(sprintf('Indexing %snodes ... ', ($limit !== null ? 'the first ' . $limit . ' ' : '')), LogEnvironment::fromMethodName(__METHOD__));
245262

246263
$count = 0;
247264

@@ -257,8 +274,8 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
257274
}
258275
};
259276
if ($workspace === null) {
260-
foreach ($this->workspaceRepository->findAll() as $workspace) {
261-
$count += $this->indexWorkspace($workspace->getName(), $limit, $callback);
277+
foreach ($this->workspaceRepository->findAll() as $workspaceToIndex) {
278+
$count += $this->indexWorkspace($workspaceToIndex->getName(), $limit, $callback);
262279
}
263280
} else {
264281
$count += $this->indexWorkspace($workspace, $limit, $callback);
@@ -275,7 +292,7 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
275292
$this->outputLine();
276293
$this->outputLine('<error>Check your logs for more information</error>');
277294
} else {
278-
$this->logger->log('Done. (indexed ' . $count . ' nodes)', LOG_INFO);
295+
$this->logger->info('Done. (indexed ' . $count . ' nodes)', LogEnvironment::fromMethodName(__METHOD__));
279296
}
280297
$this->nodeIndexer->getIndex()->refresh();
281298

@@ -289,24 +306,25 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
289306
* Clean up old indexes (i.e. all but the current one)
290307
*
291308
* @return void
309+
* @throws CRAException
292310
*/
293-
public function cleanupCommand()
311+
public function cleanupCommand(): void
294312
{
295313
try {
296314
$indicesToBeRemoved = $this->nodeIndexer->removeOldIndices();
297315
if (count($indicesToBeRemoved) > 0) {
298316
foreach ($indicesToBeRemoved as $indexToBeRemoved) {
299-
$this->logger->log('Removing old index ' . $indexToBeRemoved);
317+
$this->logger->info('Removing old index ' . $indexToBeRemoved, LogEnvironment::fromMethodName(__METHOD__));
300318
}
301319
} else {
302-
$this->logger->log('Nothing to remove.');
320+
$this->logger->info('Nothing to remove.', LogEnvironment::fromMethodName(__METHOD__));
303321
}
304322
} catch (ApiException $exception) {
305323
$response = json_decode($exception->getResponse());
306324
if ($response->error instanceof \stdClass) {
307-
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s"', $response->status, $response->error->type, $response->error->reason));
325+
$this->logger->info(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s"', $response->status, $response->error->type, $response->error->reason), LogEnvironment::fromMethodName(__METHOD__));
308326
} else {
309-
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s"', $response->status, $response->error));
327+
$this->logger->info(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s"', $response->status, $response->error), LogEnvironment::fromMethodName(__METHOD__));
310328
}
311329
}
312330
}
@@ -316,30 +334,32 @@ public function cleanupCommand()
316334
*
317335
* @param string $postfix
318336
* @return void
337+
* @throws CRAException
319338
*/
320-
protected function createNewIndex(string $postfix)
339+
protected function createNewIndex(string $postfix): void
321340
{
322-
$this->nodeIndexer->setIndexNamePostfix($postfix ?: time());
341+
$this->nodeIndexer->setIndexNamePostfix($postfix ?: (string)time());
323342
if ($this->nodeIndexer->getIndex()->exists() === true) {
324-
$this->logger->log(sprintf('Deleted index with the same postfix (%s)!', $postfix), LOG_WARNING);
343+
$this->logger->warning(sprintf('Deleted index with the same postfix (%s)!', $postfix), LogEnvironment::fromMethodName(__METHOD__));
325344
$this->nodeIndexer->getIndex()->delete();
326345
}
327346
$this->nodeIndexer->getIndex()->create();
328-
$this->logger->log('Created index ' . $this->nodeIndexer->getIndexName(), LOG_INFO);
347+
$this->logger->info('Created index ' . $this->nodeIndexer->getIndexName(), LogEnvironment::fromMethodName(__METHOD__));
329348
}
330349

331350
/**
332351
* Apply the mapping to the current index.
333352
*
334353
* @return void
354+
* @throws CRAException
335355
*/
336-
protected function applyMapping()
356+
protected function applyMapping(): void
337357
{
338358
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
339359
foreach ($nodeTypeMappingCollection as $mapping) {
340360
/** @var Mapping $mapping */
341361
$mapping->apply();
342362
}
343-
$this->logger->log('Updated Mapping.', LOG_INFO);
363+
$this->logger->info('Updated Mapping.', LogEnvironment::fromMethodName(__METHOD__));
344364
}
345365
}

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: 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\Driver;
36

47
/*
@@ -12,7 +15,7 @@
1215
*/
1316

1417
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
15-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
18+
use Psr\Log\LoggerInterface;
1619
use Neos\Flow\Annotations as Flow;
1720

1821
/**

Classes/Driver/AbstractIndexerDriver.php

Lines changed: 6 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
/*
@@ -11,8 +14,9 @@
1114
* source code.
1215
*/
1316

14-
use Neos\Flow\Annotations as Flow;
1517
use Neos\ContentRepository\Domain\Model\NodeInterface;
18+
use Neos\Flow\Annotations as Flow;
19+
use Neos\Flow\Log\Utility\LogEnvironment;
1620

1721
/**
1822
* Abstract Fulltext Indexer Driver
@@ -55,7 +59,7 @@ protected function findClosestFulltextRoot(NodeInterface $node)
5559
if ($closestFulltextNode === null) {
5660
// root of hierarchy, no fulltext root found anymore, abort silently...
5761
if ($node->getPath() !== '/' && $node->getPath() !== '/sites') {
58-
$this->logger->log(sprintf('NodeIndexer: No fulltext root found for node %s (%s)', $node->getIdentifier(), $node->getContextPath()), LOG_WARNING, null, 'ElasticSearch (CR)');
62+
$this->logger->warning(sprintf('NodeIndexer: No fulltext root found for node %s (%s)', $node->getIdentifier(), $node->getContextPath()), LogEnvironment::fromMethodName(__METHOD__));
5963
}
6064

6165
return null;

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)