Skip to content

Commit

Permalink
Merge pull request #2992 from acrobat/cleanup-major-release
Browse files Browse the repository at this point in the history
[AllBundles] Major version cleanup
  • Loading branch information
acrobat committed Oct 16, 2021
2 parents 0fb4b6c + 3bfe00c commit 0c81697
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 274 deletions.
12 changes: 3 additions & 9 deletions src/Kunstmaan/AdminBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@ public function getConfigTreeBuilder()
->fixXmlConfig('menu_item')
->children()
->scalarNode('website_title')->defaultNull()->end()
->scalarNode('multi_language') //NEXT_MAJOR: change type to booleanNode and make required or provide default value
->defaultNull()
->beforeNormalization()->ifString()->then(function ($v) {
// Workaroud to allow detecting if value is not provided. Can be removed when type is switched to booleanNode
return (bool) $v;
})->end()
->end()
->scalarNode('required_locales')->defaultNull()->end() //NEXT_MAJOR: make config required
->scalarNode('default_locale')->defaultNull()->end() //NEXT_MAJOR: make config required
->booleanNode('multi_language')->isRequired()->defaultFalse()->end()
->scalarNode('required_locales')->isRequired()->end()
->scalarNode('default_locale')->isRequired()->end()
->scalarNode('admin_password')->end()
->arrayNode('authentication')
->addDefaultsIfNotSet()
Expand Down
12 changes: 0 additions & 12 deletions src/Kunstmaan/AdminBundle/Entity/BaseUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,18 +553,6 @@ public function setConfirmationToken($confirmationToken)
return $this;
}

/**
* @return static
*/
public function setPasswordRequestedAt(\DateTime $date = null)
{
//TODO: check if this propery is usefull?
// NEXT_MAJOR remove method
@trigger_error(sprintf('Using method %s from class %s is deprecated since KunstmaanAdminBundle 5.9 and will be removed in KunstmaanAdminBundle 6.0.', __METHOD__, BaseUser::class), E_USER_DEPRECATED);

return $this;
}

public function getLastLogin()
{
return $this->lastLogin;
Expand Down
7 changes: 0 additions & 7 deletions src/Kunstmaan/AdminBundle/Entity/UserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ public function getConfirmationToken();
*/
public function setConfirmationToken($confirmationToken);

/**
* Sets the timestamp that the user requested a password reset.
*
* @return static
*/
public function setPasswordRequestedAt(\DateTime $date = null);

/**
* Sets the last login time.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ConfigurationTest extends TestCase

private const DEFAULT_EXPECTED_CONFIG = [
'website_title' => null,
'multi_language' => null,
'multi_language' => true,
'required_locales' => null,
'default_locale' => null,
'admin_prefix' => 'admin',
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testConfigGeneratesAsExpected()
{
$array = [
'website_title' => null,
'multi_language' => null,
'multi_language' => true,
'required_locales' => null,
'default_locale' => null,
'authentication' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@
*/
class Configuration implements ConfigurationInterface
{
/**
* @var bool
*/
private $useElasticSearchVersion6;

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

/**
* @return TreeBuilder
*/
Expand Down Expand Up @@ -53,28 +40,16 @@ public function getConfigTreeBuilder()
'binary',
'geo_point',
];
if (!$this->useElasticSearchVersion6) {
$types[] = 'string';
}

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

if ($this->useElasticSearchVersion6) {
$properties->children()->booleanNode('fielddata');
$properties->children()->booleanNode('doc_values');
$properties->children()
->scalarNode('index')
->beforeNormalization()
->ifNotInArray(['true', 'false', true, false])
->thenInvalid('index must be one of: true, false');
} else {
$properties->children()
->scalarNode('index')
->beforeNormalization()
->ifNotInArray(['analyzed', 'not_analyzed', 'no'])
->thenInvalid('index must be one of: analyzed, not_analyzed, no');
$properties->children()->booleanNode('include_in_all');
}
$properties->children()->booleanNode('fielddata');
$properties->children()->booleanNode('doc_values');
$properties->children()
->scalarNode('index')
->beforeNormalization()
->ifNotInArray(['true', 'false', true, false])
->thenInvalid('index must be one of: true, false');

$properties->children()->booleanNode('store');
$properties->children()->floatNode('boost');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Kunstmaan\NodeSearchBundle\DependencyInjection;

use Kunstmaan\NodeSearchBundle\Helper\ElasticSearchUtil;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
Expand All @@ -12,14 +10,9 @@

class KunstmaanNodeSearchExtension extends Extension implements PrependExtensionInterface
{
/**
* @var bool
*/
private $useElasticSearchVersion6;

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

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
Expand All @@ -38,163 +31,48 @@ public function load(array $configs, ContainerBuilder $container)
->addMethodCall('setDefaultProperties', [$config['mapping']]);

$container->setParameter('kunstmaan_node_search.contexts', $config['contexts']);

if (class_exists(\Elastica\Type\Mapping::class)) {
$nodeSearch = $container->getDefinition('kunstmaan_node_search.search.node');
$nodeSearch->addMethodCall('setIndexType', ['%kunstmaan_node_search.indextype%']);
}
}

/**
* Allow an extension to prepend the extension configurations.
*/
public function prepend(ContainerBuilder $container)
{
$this->useElasticSearchVersion6 = $this->useElasticSearchV6($container);

if ($this->useElasticSearchVersion6) {
$mapping = [
'mapping' => [
'root_id' => [
'type' => 'integer',
],
'node_id' => [
'type' => 'integer',
],
'nodetranslation_id' => [
'type' => 'integer',
],
'nodeversion_id' => [
'type' => 'integer',
],
'title' => [
'type' => 'text',
],
'slug' => [
'type' => 'text',
],
'type' => [
'type' => 'keyword',
],
'page_class' => [
'type' => 'keyword',
],
'content' => [
'type' => 'text',
],
'view_roles' => [
'type' => 'keyword',
],
$mapping = [
'mapping' => [
'root_id' => [
'type' => 'integer',
],
];
} else {
$mapping = [
'mapping' => [
'root_id' => [
'type' => 'integer',
'include_in_all' => false,
'index' => 'not_analyzed',
],
'node_id' => [
'type' => 'integer',
'include_in_all' => false,
'index' => 'not_analyzed',
],
'nodetranslation_id' => [
'type' => 'integer',
'include_in_all' => false,
'index' => 'not_analyzed',
],
'nodeversion_id' => [
'type' => 'integer',
'include_in_all' => false,
'index' => 'not_analyzed',
],
'title' => [
'type' => 'string',
'include_in_all' => true,
],
'slug' => [
'type' => 'string',
'include_in_all' => false,
'index' => 'not_analyzed',
],
'type' => [
'type' => 'string',
'include_in_all' => false,
'index' => 'not_analyzed',
],
'page_class' => [
'type' => 'string',
'include_in_all' => false,
'index' => 'not_analyzed',
],
'content' => [
'type' => 'string',
'include_in_all' => true,
],
'created' => [
'type' => 'date',
'include_in_all' => false,
'index' => 'not_analyzed',
],
'updated' => [
'type' => 'date',
'include_in_all' => false,
'index' => 'not_analyzed',
],
'view_roles' => [
'type' => 'string',
'include_in_all' => true,
'index' => 'not_analyzed',
],
'node_id' => [
'type' => 'integer',
],
];
}
'nodetranslation_id' => [
'type' => 'integer',
],
'nodeversion_id' => [
'type' => 'integer',
],
'title' => [
'type' => 'text',
],
'slug' => [
'type' => 'text',
],
'type' => [
'type' => 'keyword',
],
'page_class' => [
'type' => 'keyword',
],
'content' => [
'type' => 'text',
],
'view_roles' => [
'type' => 'keyword',
],
],
];

$container->prependExtensionConfig('kunstmaan_node_search', $mapping);
}

private function useElasticSearchV6(ContainerBuilder $container)
{
if ($container->hasParameter('kunstmaan_search.elasticsearch_version')) {
$version = (string) $container->getParameter('kunstmaan_search.elasticsearch_version');
if (!preg_match('/^(\d+\.)?(\d+\.)?(\*|\d+)$/', $version)) {
throw new \InvalidArgumentException('Invalid value for "%kunstmaan_search.elasticsearch_version%" parameter, expected value must match a format like "6", "6.1" or "6.1.2".');
}

if (version_compare($version, '5.0.0', '>=')) {
return true;
}

return false;
}

$hosts = [];
if ($container->hasParameter('kunstmaan_search.hostname') && $container->hasParameter('kunstmaan_search.port')) {
$host = $container->getParameter('kunstmaan_search.hostname') . ':' . $container->getParameter('kunstmaan_search.port');

if ($container->hasParameter('kunstmaan_search.username') && $container->hasParameter('kunstmaan_search.password') &&
null !== $container->getParameter('kunstmaan_search.username') && null !== $container->getParameter('kunstmaan_search.password')) {
$host = sprintf(
'%s:%s@%s',
$container->getParameter('kunstmaan_search.username'),
$container->getParameter('kunstmaan_search.password'),
$host
);
}

$hosts[] = $host;
}

return ElasticSearchUtil::useVersion6($hosts);
}

/**
* @return ConfigurationInterface|null
*/
public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($this->useElasticSearchV6($container));
}
}
Loading

0 comments on commit 0c81697

Please sign in to comment.