Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KunstmaanNodeSearchBundle] use hosts in useVersion6 check #2075

Merged
merged 1 commit into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
*/
class Configuration implements ConfigurationInterface
{
/**
* @var bool
*/
private $useElasticSearchVersion6;


/**
* Configuration constructor.
* @param bool $useElasticSearchVersion6
*/
public function __construct($useElasticSearchVersion6)
{
$this->useElasticSearchVersion6 = $useElasticSearchVersion6;
}

/**
* {@inheritDoc}
*/
Expand All @@ -36,13 +51,13 @@ public function getConfigTreeBuilder()
'boolean',
'binary',
];
if (!ElasticSearchUtil::useVersion6()) {
if (!$this->useElasticSearchVersion6) {
$types[] = 'string';
}

$properties->children()->scalarNode('type')->beforeNormalization()->ifNotInArray($types)->thenInvalid('type must be one of: ' . implode(', ', $types));

if (ElasticSearchUtil::useVersion6()) {
if ($this->useElasticSearchVersion6) {
$properties->children()->booleanNode('fielddata');
$properties->children()->booleanNode('doc_values');
$properties->children()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
*/
class KunstmaanNodeSearchExtension extends Extension implements PrependExtensionInterface
{
/**
* @var bool
*/
private $useElasticSearchVersion6;

/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$configuration = new Configuration($this->useElasticSearchVersion6);
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Expand Down Expand Up @@ -49,7 +54,9 @@ public function load(array $configs, ContainerBuilder $container)
*/
public function prepend(ContainerBuilder $container)
{
if (ElasticSearchUtil::useVersion6()) {
$this->useElasticSearchVersion6 = ElasticSearchUtil::useVersion6(array($container->getParameter('kunstmaan_search.hostname').':'.$container->getParameter('searchport')));

if ($this->useElasticSearchVersion6) {
$mapping = [
'mapping' => [
'root_id' => [
Expand Down
12 changes: 8 additions & 4 deletions src/Kunstmaan/NodeSearchBundle/Helper/ElasticSearchUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ final class ElasticSearchUtil
private static $esClientInfo;

/**
* @var array $hosts
*
* @return bool
*/
public static function useVersion6()
public static function useVersion6($hosts = array())
{
if (PHP_MAJOR_VERSION < 7) {
return false;
}

$info = self::getESVersionInfo();
$info = self::getESVersionInfo($hosts);

if (null !== $info) {
$versionParts = explode('.', $info['version']['number']);
Expand All @@ -35,13 +37,15 @@ public static function useVersion6()
}

/**
* @var array $hosts
*
* @return array
*/
private static function getESVersionInfo()
private static function getESVersionInfo($hosts)
{
try {
if (null === self::$esClientInfo) {
$client = ClientBuilder::create()->build();
$client = ClientBuilder::create()->setHosts($hosts)->build();
self::$esClientInfo = $client->info();
}
} catch (NoNodesAvailableException $e) {
Expand Down