Merge pull request #583 from merk/rename-mappings
Rename mappings to properties maintaining BC
This commit is contained in:
commit
fa65784b47
|
@ -175,6 +175,16 @@ class Configuration implements ConfigurationInterface
|
||||||
->useAttributeAsKey('name')
|
->useAttributeAsKey('name')
|
||||||
->prototype('array')
|
->prototype('array')
|
||||||
->treatNullLike(array())
|
->treatNullLike(array())
|
||||||
|
// BC - Renaming 'mappings' node to 'properties'
|
||||||
|
->beforeNormalization()
|
||||||
|
->ifTrue(function($v) { return isset($v['mappings']); })
|
||||||
|
->then(function($v) {
|
||||||
|
$v['properties'] = $v['mappings'];
|
||||||
|
unset($v['mappings']);
|
||||||
|
|
||||||
|
return $v;
|
||||||
|
})
|
||||||
|
->end()
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('index_analyzer')->end()
|
->scalarNode('index_analyzer')->end()
|
||||||
->scalarNode('search_analyzer')->end()
|
->scalarNode('search_analyzer')->end()
|
||||||
|
@ -182,7 +192,7 @@ class Configuration implements ConfigurationInterface
|
||||||
->append($this->getSerializerNode())
|
->append($this->getSerializerNode())
|
||||||
->end()
|
->end()
|
||||||
->append($this->getIdNode())
|
->append($this->getIdNode())
|
||||||
->append($this->getMappingsNode())
|
->append($this->getPropertiesNode())
|
||||||
->append($this->getDynamicTemplateNode())
|
->append($this->getDynamicTemplateNode())
|
||||||
->append($this->getSourceNode())
|
->append($this->getSourceNode())
|
||||||
->append($this->getBoostNode())
|
->append($this->getBoostNode())
|
||||||
|
@ -198,12 +208,12 @@ class Configuration implements ConfigurationInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the array node used for "mappings".
|
* Returns the array node used for "properties".
|
||||||
*/
|
*/
|
||||||
protected function getMappingsNode()
|
protected function getPropertiesNode()
|
||||||
{
|
{
|
||||||
$builder = new TreeBuilder();
|
$builder = new TreeBuilder();
|
||||||
$node = $builder->root('mappings');
|
$node = $builder->root('properties');
|
||||||
|
|
||||||
$nestings = $this->getNestings();
|
$nestings = $this->getNestings();
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ namespace FOS\ElasticaBundle\DependencyInjection;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||||
|
@ -129,7 +128,7 @@ class FOSElasticaExtension extends Extension
|
||||||
'index' => new Reference($indexId),
|
'index' => new Reference($indexId),
|
||||||
'name_or_alias' => $indexName,
|
'name_or_alias' => $indexName,
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'mappings' => array()
|
'properties' => array()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if ($index['finder']) {
|
if ($index['finder']) {
|
||||||
|
@ -217,30 +216,30 @@ class FOSElasticaExtension extends Extension
|
||||||
}
|
}
|
||||||
$container->setDefinition($typeId, $typeDef);
|
$container->setDefinition($typeId, $typeDef);
|
||||||
|
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name] = array(
|
$this->indexConfigs[$indexName]['config']['properties'][$name] = array(
|
||||||
"_source" => array("enabled" => true), // Add a default setting for empty mapping settings
|
"_source" => array("enabled" => true), // Add a default setting for empty mapping settings
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($type['_id'])) {
|
if (isset($type['_id'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['_id'] = $type['_id'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['_id'] = $type['_id'];
|
||||||
}
|
}
|
||||||
if (isset($type['_source'])) {
|
if (isset($type['_source'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['_source'] = $type['_source'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['_source'] = $type['_source'];
|
||||||
}
|
}
|
||||||
if (isset($type['_boost'])) {
|
if (isset($type['_boost'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['_boost'] = $type['_boost'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['_boost'] = $type['_boost'];
|
||||||
}
|
}
|
||||||
if (isset($type['_routing'])) {
|
if (isset($type['_routing'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['_routing'] = $type['_routing'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['_routing'] = $type['_routing'];
|
||||||
}
|
}
|
||||||
if (isset($type['mappings']) && !empty($type['mappings'])) {
|
if (isset($type['properties']) && !empty($type['properties'])) {
|
||||||
$this->cleanUpMapping($type['mappings']);
|
$this->cleanUpProperties($type['properties']);
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['properties'] = $type['mappings'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['properties'] = $type['properties'];
|
||||||
$typeName = sprintf('%s/%s', $indexName, $name);
|
$typeName = sprintf('%s/%s', $indexName, $name);
|
||||||
$this->typeFields[$typeName] = $type['mappings'];
|
$this->typeFields[$typeName] = $type['properties'];
|
||||||
}
|
}
|
||||||
if (isset($type['_parent'])) {
|
if (isset($type['_parent'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['_parent'] = array('type' => $type['_parent']['type']);
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['_parent'] = array('type' => $type['_parent']['type']);
|
||||||
$typeName = sprintf('%s/%s', $indexName, $name);
|
$typeName = sprintf('%s/%s', $indexName, $name);
|
||||||
$this->typeFields[$typeName]['_parent'] = $type['_parent'];
|
$this->typeFields[$typeName]['_parent'] = $type['_parent'];
|
||||||
}
|
}
|
||||||
|
@ -248,27 +247,27 @@ class FOSElasticaExtension extends Extension
|
||||||
$this->loadTypePersistenceIntegration($type['persistence'], $container, $typeDef, $indexName, $name);
|
$this->loadTypePersistenceIntegration($type['persistence'], $container, $typeDef, $indexName, $name);
|
||||||
}
|
}
|
||||||
if (isset($type['index_analyzer'])) {
|
if (isset($type['index_analyzer'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['index_analyzer'] = $type['index_analyzer'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['index_analyzer'] = $type['index_analyzer'];
|
||||||
}
|
}
|
||||||
if (isset($type['search_analyzer'])) {
|
if (isset($type['search_analyzer'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['search_analyzer'] = $type['search_analyzer'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['search_analyzer'] = $type['search_analyzer'];
|
||||||
}
|
}
|
||||||
if (isset($type['index'])) {
|
if (isset($type['index'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['index'] = $type['index'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['index'] = $type['index'];
|
||||||
}
|
}
|
||||||
if (isset($type['_all'])) {
|
if (isset($type['_all'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['_all'] = $type['_all'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['_all'] = $type['_all'];
|
||||||
}
|
}
|
||||||
if (isset($type['_timestamp'])) {
|
if (isset($type['_timestamp'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['_timestamp'] = $type['_timestamp'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['_timestamp'] = $type['_timestamp'];
|
||||||
}
|
}
|
||||||
if (isset($type['_ttl'])) {
|
if (isset($type['_ttl'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['_ttl'] = $type['_ttl'];
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['_ttl'] = $type['_ttl'];
|
||||||
}
|
}
|
||||||
if (!empty($type['dynamic_templates'])) {
|
if (!empty($type['dynamic_templates'])) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['dynamic_templates'] = array();
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['dynamic_templates'] = array();
|
||||||
foreach ($type['dynamic_templates'] as $templateName => $templateData) {
|
foreach ($type['dynamic_templates'] as $templateName => $templateData) {
|
||||||
$this->indexConfigs[$indexName]['config']['mappings'][$name]['dynamic_templates'][] = array($templateName => $templateData);
|
$this->indexConfigs[$indexName]['config']['properties'][$name]['dynamic_templates'][] = array($templateName => $templateData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -569,17 +568,17 @@ class FOSElasticaExtension extends Extension
|
||||||
$container->setAlias('fos_elastica.manager', sprintf('fos_elastica.manager.%s', $defaultManagerService));
|
$container->setAlias('fos_elastica.manager', sprintf('fos_elastica.manager.%s', $defaultManagerService));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function cleanUpMapping(&$mappings)
|
protected function cleanUpProperties(&$properties)
|
||||||
{
|
{
|
||||||
foreach ($mappings as &$fieldProperties) {
|
foreach ($properties as &$fieldProperties) {
|
||||||
if (empty($fieldProperties['fields'])) {
|
if (empty($fieldProperties['fields'])) {
|
||||||
unset($fieldProperties['fields']);
|
unset($fieldProperties['fields']);
|
||||||
} else {
|
} else {
|
||||||
$this->cleanUpMapping($fieldProperties['fields']);
|
$this->cleanUpProperties($fieldProperties['fields']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($fieldProperties['properties'])) {
|
if (!empty($fieldProperties['properties'])) {
|
||||||
$this->cleanUpMapping($fieldProperties['properties']);
|
$this->cleanUpProperties($fieldProperties['properties']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ class Resetter
|
||||||
{
|
{
|
||||||
$indexConfig = $this->getIndexConfig($indexName);
|
$indexConfig = $this->getIndexConfig($indexName);
|
||||||
|
|
||||||
if (!isset($indexConfig['config']['mappings'][$typeName]['properties'])) {
|
if (!isset($indexConfig['config']['properties'][$typeName]['properties'])) {
|
||||||
throw new \InvalidArgumentException(sprintf('The mapping for index "%s" and type "%s" does not exist.', $indexName, $typeName));
|
throw new \InvalidArgumentException(sprintf('The mapping for index "%s" and type "%s" does not exist.', $indexName, $typeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ class Resetter
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$mapping = $this->createMapping($indexConfig['config']['mappings'][$typeName]);
|
$mapping = $this->createMapping($indexConfig['config']['properties'][$typeName]);
|
||||||
$type->setMapping($mapping);
|
$type->setMapping($mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,8 +160,8 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertEquals('string', $configuration['indexes']['test']['types']['test']['mappings']['title']['type']);
|
$this->assertEquals('string', $configuration['indexes']['test']['types']['test']['properties']['title']['type']);
|
||||||
$this->assertTrue($configuration['indexes']['test']['types']['test']['mappings']['title']['include_in_all']);
|
$this->assertTrue($configuration['indexes']['test']['types']['test']['properties']['title']['include_in_all']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmptyPropertiesIndexIsUnset()
|
public function testEmptyPropertiesIndexIsUnset()
|
||||||
|
@ -210,7 +210,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$configuration = $processor->processConfiguration(new Configuration(array($config), false), array($config));
|
$configuration = $processor->processConfiguration(new Configuration(array($config), false), array($config));
|
||||||
|
|
||||||
$mapping = $configuration['indexes']['test']['types']['test']['mappings'];
|
$mapping = $configuration['indexes']['test']['types']['test']['properties'];
|
||||||
$this->assertArrayNotHasKey('properties', $mapping['content']);
|
$this->assertArrayNotHasKey('properties', $mapping['content']);
|
||||||
$this->assertArrayNotHasKey('properties', $mapping['title']);
|
$this->assertArrayNotHasKey('properties', $mapping['title']);
|
||||||
$this->assertArrayHasKey('properties', $mapping['children']);
|
$this->assertArrayHasKey('properties', $mapping['children']);
|
||||||
|
@ -233,4 +233,28 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertTrue(empty($configuration['clients']['default']['servers'][0]['url']));
|
$this->assertTrue(empty($configuration['clients']['default']['servers'][0]['url']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMappingsRenamedToProperties()
|
||||||
|
{
|
||||||
|
$configuration = $this->getConfigs(array(
|
||||||
|
'clients' => array(
|
||||||
|
'default' => array('url' => 'http://localhost:9200'),
|
||||||
|
),
|
||||||
|
'indexes' => array(
|
||||||
|
'test' => array(
|
||||||
|
'types' => array(
|
||||||
|
'test' => array(
|
||||||
|
'mappings' => array(
|
||||||
|
'title' => array(),
|
||||||
|
'published' => array('type' => 'datetime'),
|
||||||
|
'body' => null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertCount(3, $configuration['indexes']['test']['types']['test']['properties']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
||||||
'foo' => array(
|
'foo' => array(
|
||||||
'index' => $this->getMockElasticaIndex(),
|
'index' => $this->getMockElasticaIndex(),
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'mappings' => array(
|
'properties' => array(
|
||||||
'a' => array(
|
'a' => array(
|
||||||
'dynamic_templates' => array(),
|
'dynamic_templates' => array(),
|
||||||
'properties' => array(),
|
'properties' => array(),
|
||||||
|
@ -30,7 +30,7 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
||||||
'bar' => array(
|
'bar' => array(
|
||||||
'index' => $this->getMockElasticaIndex(),
|
'index' => $this->getMockElasticaIndex(),
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'mappings' => array(
|
'properties' => array(
|
||||||
'a' => array('properties' => array()),
|
'a' => array('properties' => array()),
|
||||||
'b' => array('properties' => array()),
|
'b' => array('properties' => array()),
|
||||||
),
|
),
|
||||||
|
@ -39,7 +39,7 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
||||||
'parent' => array(
|
'parent' => array(
|
||||||
'index' => $this->getMockElasticaIndex(),
|
'index' => $this->getMockElasticaIndex(),
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'mappings' => array(
|
'properties' => array(
|
||||||
'a' => array(
|
'a' => array(
|
||||||
'properties' => array(
|
'properties' => array(
|
||||||
'field_2' => array()
|
'field_2' => array()
|
||||||
|
@ -105,8 +105,8 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
||||||
$type->expects($this->once())
|
$type->expects($this->once())
|
||||||
->method('delete');
|
->method('delete');
|
||||||
|
|
||||||
$mapping = Mapping::create($this->indexConfigsByName['foo']['config']['mappings']['a']['properties']);
|
$mapping = Mapping::create($this->indexConfigsByName['foo']['config']['properties']['a']['properties']);
|
||||||
$mapping->setParam('dynamic_templates', $this->indexConfigsByName['foo']['config']['mappings']['a']['dynamic_templates']);
|
$mapping->setParam('dynamic_templates', $this->indexConfigsByName['foo']['config']['properties']['a']['dynamic_templates']);
|
||||||
$type->expects($this->once())
|
$type->expects($this->once())
|
||||||
->method('setMapping')
|
->method('setMapping')
|
||||||
->with($mapping);
|
->with($mapping);
|
||||||
|
@ -149,8 +149,8 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
||||||
new Response(array('error' => 'TypeMissingException[[de_20131022] type[bla] missing]', 'status' => 404)))
|
new Response(array('error' => 'TypeMissingException[[de_20131022] type[bla] missing]', 'status' => 404)))
|
||||||
));
|
));
|
||||||
|
|
||||||
$mapping = Mapping::create($this->indexConfigsByName['foo']['config']['mappings']['a']['properties']);
|
$mapping = Mapping::create($this->indexConfigsByName['foo']['config']['properties']['a']['properties']);
|
||||||
$mapping->setParam('dynamic_templates', $this->indexConfigsByName['foo']['config']['mappings']['a']['dynamic_templates']);
|
$mapping->setParam('dynamic_templates', $this->indexConfigsByName['foo']['config']['properties']['a']['dynamic_templates']);
|
||||||
$type->expects($this->once())
|
$type->expects($this->once())
|
||||||
->method('setMapping')
|
->method('setMapping')
|
||||||
->with($mapping);
|
->with($mapping);
|
||||||
|
@ -171,7 +171,7 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
||||||
$type->expects($this->once())
|
$type->expects($this->once())
|
||||||
->method('delete');
|
->method('delete');
|
||||||
|
|
||||||
$mapping = Mapping::create($this->indexConfigsByName['parent']['config']['mappings']['a']['properties']);
|
$mapping = Mapping::create($this->indexConfigsByName['parent']['config']['properties']['a']['properties']);
|
||||||
$mapping->setParam('_parent', array('type' => 'b'));
|
$mapping->setParam('_parent', array('type' => 'b'));
|
||||||
$type->expects($this->once())
|
$type->expects($this->once())
|
||||||
->method('setMapping')
|
->method('setMapping')
|
||||||
|
|
Loading…
Reference in a new issue