Skip to content

Commit ac7318e

Browse files
authored
Merge pull request #235 from dfeyer/feature-indexname-strategy
FEATURE: IndexName Strategy
2 parents 5bb6e92 + 15a027c commit ac7318e

File tree

3 files changed

+68
-24
lines changed

3 files changed

+68
-24
lines changed

Classes/ElasticSearchClient.php

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

14+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexNameStrategyInterface;
1415
use Neos\Flow\Annotations as Flow;
1516
use Neos\Flow\Configuration\ConfigurationManager;
1617

@@ -27,30 +28,10 @@
2728
class ElasticSearchClient extends \Flowpack\ElasticSearch\Domain\Model\Client
2829
{
2930
/**
30-
* The index name to be used for querying (by default "neoscr")
31-
*
32-
* @var string
33-
*/
34-
protected $indexName;
35-
36-
/**
31+
* @var IndexNameStrategyInterface
3732
* @Flow\Inject
38-
* @var ConfigurationManager
39-
*/
40-
protected $configurationManager;
41-
42-
/**
43-
* Called by the Flow object framework after creating the object and resolving all dependencies.
44-
*
45-
* @param integer $cause Creation cause
4633
*/
47-
public function initializeObject($cause)
48-
{
49-
if ($cause === \Neos\Flow\ObjectManagement\ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
50-
$settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepository.Search');
51-
$this->indexName = $settings['elasticSearch']['indexName'];
52-
}
53-
}
34+
protected $indexNameStrategy;
5435

5536
/**
5637
* Get the index name to be used
@@ -59,7 +40,11 @@ public function initializeObject($cause)
5940
*/
6041
public function getIndexName()
6142
{
62-
return $this->indexName;
43+
$name = trim($this->indexNameStrategy->get());
44+
if ($name === '') {
45+
throw new Exception('Index name can not be null');
46+
}
47+
return $name;
6348
}
6449

6550
/**
@@ -70,6 +55,6 @@ public function getIndexName()
7055
*/
7156
public function getIndex()
7257
{
73-
return $this->findIndex($this->indexName);
58+
return $this->findIndex($this->getIndexName());
7459
}
7560
}

Classes/Service/IndexNameStrategy.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service;
3+
4+
/*
5+
* This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package.
6+
*
7+
* (c) Contributors of the Neos Project - www.neos.io
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE file which was distributed with this
11+
* source code.
12+
*/
13+
14+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception;
15+
use Neos\Flow\Annotations as Flow;
16+
17+
/**
18+
* Get Index Name from Settings
19+
*
20+
* @Flow\Scope("singleton")
21+
*/
22+
class IndexNameStrategy implements IndexNameStrategyInterface
23+
{
24+
/**
25+
* @var string
26+
* @Flow\InjectConfiguration(path="elasticSearch.indexName", package="Neos.ContentRepository.Search")
27+
*/
28+
protected $indexName;
29+
30+
public function get()
31+
{
32+
$name = $this->indexName;
33+
if ($name === '') {
34+
throw new Exception('Index name can not be null, check Settings at path: Neos.ContentRepository.Search.elasticSearch.indexName');
35+
}
36+
return $name;
37+
}
38+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service;
3+
4+
/*
5+
* This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package.
6+
*
7+
* (c) Contributors of the Neos Project - www.neos.io
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE file which was distributed with this
11+
* source code.
12+
*/
13+
14+
15+
/**
16+
* Get Index Name
17+
*/
18+
interface IndexNameStrategyInterface
19+
{
20+
public function get();
21+
}

0 commit comments

Comments
 (0)