Skip to content

Commit c7340b9

Browse files
authored
Merge branch '3.0' into es-5-support
2 parents 41f14b6 + 0c92519 commit c7340b9

7 files changed

Lines changed: 64 additions & 35 deletions

File tree

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ before_install:
2525
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
2626
- export NEOS_TARGET_VERSION=2.3
2727
- cd ..
28-
- 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
29-
- 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
28+
- 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
29+
- 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
3030
- if [ "$ES" = 5 ]; then wget --no-check-certificate https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.2.zip && unzip elasticsearch-5.4.2.zip && mv elasticsearch-5.4.2 elasticsearch; fi
3131
- cd elasticsearch
3232
- bin/elasticsearch -d

Classes/Command/NodeIndexCommandController.php

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@
1212
*/
1313

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\NodeTypeMappingBuilderInterface;
15+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
1516
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait;
17+
use Flowpack\ElasticSearch\Domain\Model\Mapping;
18+
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
19+
use Symfony\Component\Yaml\Yaml;
1620
use TYPO3\Flow\Annotations as Flow;
1721
use TYPO3\Flow\Cli\CommandController;
22+
use TYPO3\Flow\Configuration\ConfigurationManager;
23+
use TYPO3\Flow\Object\ObjectManagerInterface;
1824
use TYPO3\Neos\Controller\CreateContentContextTrait;
1925
use TYPO3\TYPO3CR\Domain\Model\Workspace;
26+
use TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository;
27+
use TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository;
28+
use TYPO3\TYPO3CR\Domain\Service\ContentDimensionPresetSourceInterface;
29+
use TYPO3\TYPO3CR\Search\Indexer\NodeIndexerInterface;
2030

2131
/**
2232
* Provides CLI features for index handling
@@ -30,19 +40,19 @@ class NodeIndexCommandController extends CommandController
3040

3141
/**
3242
* @Flow\Inject
33-
* @var \TYPO3\TYPO3CR\Search\Indexer\NodeIndexerInterface
43+
* @var NodeIndexerInterface
3444
*/
3545
protected $nodeIndexer;
3646

3747
/**
3848
* @Flow\Inject
39-
* @var \TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository
49+
* @var WorkspaceRepository
4050
*/
4151
protected $workspaceRepository;
4252

4353
/**
4454
* @Flow\Inject
45-
* @var \TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository
55+
* @var NodeDataRepository
4656
*/
4757
protected $nodeDataRepository;
4858

@@ -54,7 +64,7 @@ class NodeIndexCommandController extends CommandController
5464

5565
/**
5666
* @Flow\Inject
57-
* @var \TYPO3\TYPO3CR\Domain\Service\ContentDimensionPresetSourceInterface
67+
* @var ContentDimensionPresetSourceInterface
5868
*/
5969
protected $contentDimensionPresetSource;
6070

@@ -66,13 +76,13 @@ class NodeIndexCommandController extends CommandController
6676

6777
/**
6878
* @Flow\Inject
69-
* @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface
79+
* @var LoggerInterface
7080
*/
7181
protected $logger;
7282

7383
/**
7484
* @Flow\Inject
75-
* @var \TYPO3\Flow\Configuration\ConfigurationManager
85+
* @var ConfigurationManager
7686
*/
7787
protected $configurationManager;
7888

@@ -88,8 +98,8 @@ class NodeIndexCommandController extends CommandController
8898
*/
8999
public function initializeObject($cause)
90100
{
91-
if ($cause === \TYPO3\Flow\Object\ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
92-
$this->settings = $this->configurationManager->getConfiguration(\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.TYPO3CR.Search');
101+
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
102+
$this->settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.TYPO3CR.Search');
93103
}
94104
}
95105

@@ -102,8 +112,8 @@ public function showMappingCommand()
102112
{
103113
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
104114
foreach ($nodeTypeMappingCollection as $mapping) {
105-
/** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
106-
$this->output(\Symfony\Component\Yaml\Yaml::dump($mapping->asArray(), 5, 2));
115+
/** @var Mapping $mapping */
116+
$this->output(Yaml::dump($mapping->asArray(), 5, 2));
107117
$this->outputLine();
108118
}
109119
$this->outputLine('------------');
@@ -181,6 +191,7 @@ public function indexNodeCommand($identifier, $workspace = null)
181191
$indexInWorkspace($identifier, $workspace);
182192
}
183193
} else {
194+
/** @var Workspace $workspaceInstance */
184195
$workspaceInstance = $this->workspaceRepository->findByIdentifier($workspace);
185196
if ($workspaceInstance === null) {
186197
$this->outputLine('The given workspace (%s) does not exist.', [$workspace]);
@@ -198,7 +209,7 @@ public function indexNodeCommand($identifier, $workspace = null)
198209
* @param integer $limit Amount of nodes to index at maximum
199210
* @param boolean $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
200211
* @param string $workspace name of the workspace which should be indexed
201-
* @param string $postfix Index postfix, index with the same postifix will be deleted if exist
212+
* @param string $postfix Index postfix, index with the same postfix will be deleted if exist
202213
* @return void
203214
*/
204215
public function buildCommand($limit = null, $update = false, $workspace = null, $postfix = null)
@@ -211,21 +222,9 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
211222
if ($update === true) {
212223
$this->logger->log('!!! Update Mode (Development) active!', LOG_INFO);
213224
} else {
214-
$this->nodeIndexer->setIndexNamePostfix($postfix ?: time());
215-
if ($this->nodeIndexer->getIndex()->exists() === true) {
216-
$this->logger->log(sprintf('Deleted index with the same postfix (%s)!', $postfix), LOG_WARNING);
217-
$this->nodeIndexer->getIndex()->delete();
218-
}
219-
$this->nodeIndexer->getIndex()->create();
220-
$this->logger->log('Created index ' . $this->nodeIndexer->getIndexName(), LOG_INFO);
221-
222-
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
223-
foreach ($nodeTypeMappingCollection as $mapping) {
224-
/** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
225-
$mapping->apply();
226-
}
227-
$this->logger->log('Updated Mapping.', LOG_INFO);
225+
$this->createNewIndex($postfix);
228226
}
227+
$this->applyMapping();
229228

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

@@ -277,9 +276,41 @@ public function cleanupCommand()
277276
} else {
278277
$this->logger->log('Nothing to remove.');
279278
}
280-
} catch (\Flowpack\ElasticSearch\Transfer\Exception\ApiException $exception) {
279+
} catch (ApiException $exception) {
281280
$response = json_decode($exception->getResponse());
282281
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s"', $response->status, $response->error->type, $response->error->reason));
283282
}
284283
}
284+
285+
/**
286+
* Create a new index with the given $postfix.
287+
*
288+
* @param string $postfix
289+
* @return void
290+
*/
291+
protected function createNewIndex($postfix)
292+
{
293+
$this->nodeIndexer->setIndexNamePostfix($postfix ?: time());
294+
if ($this->nodeIndexer->getIndex()->exists() === true) {
295+
$this->logger->log(sprintf('Deleted index with the same postfix (%s)!', $postfix), LOG_WARNING);
296+
$this->nodeIndexer->getIndex()->delete();
297+
}
298+
$this->nodeIndexer->getIndex()->create();
299+
$this->logger->log('Created index ' . $this->nodeIndexer->getIndexName(), LOG_INFO);
300+
}
301+
302+
/**
303+
* Apply the mapping to the current index.
304+
*
305+
* @return void
306+
*/
307+
protected function applyMapping()
308+
{
309+
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
310+
foreach ($nodeTypeMappingCollection as $mapping) {
311+
/** @var Mapping $mapping */
312+
$mapping->apply();
313+
}
314+
$this->logger->log('Updated Mapping.', LOG_INFO);
315+
}
285316
}

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 TYPO3\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\Driver\NodeTypeMappingBuilderInterface;
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 TYPO3\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 TYPO3\Flow\Annotations as Flow;
1817

Classes/Indexer/NodeIndexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function getIndex()
161161
* Index this node, and add it to the current bulk request.
162162
*
163163
* @param NodeInterface $node
164-
* @param string $targetWorkspaceName In case this is triggered during publishing, a workspace name will be passed in
164+
* @param string $targetWorkspaceName In case indexing is triggered during publishing, a target workspace name will be passed in
165165
* @return void
166166
* @throws \TYPO3\TYPO3CR\Search\Exception\IndexingException
167167
*/

0 commit comments

Comments
 (0)