Kunstmaan / KunstmaanBundlesCMS

An advanced yet user-friendly content management system, based on the full stack Symfony framework combined with a whole host of community bundles. It provides a full featured, multi-language CMS system with an innovative page and form assembling process, versioning, workflow, translation and media managers and much more.
https://kunstmaancms.be
MIT License
402 stars 186 forks source link

Multi domain/language search population/results error. #1246

Closed alexborton closed 6 years ago

alexborton commented 8 years ago

When setting up the search for a multi-domain website, both setup commands error.

kuma:search:setup returns

app.ERROR: Symfony\Component\Debug\Exception\ContextErrorException: Notice: Undefined index: en_us (uncaught exception) at /Users/alex/Sites/*WEBSITE*/vendor/kunstmaan/bundles-cms/src/Kunstmaan/NodeSearchBundle/Configuration/NodePagesConfiguration.php line 141 while running console commandkuma:search:setup{"exception":"[object] (Symfony\\Component\\Debug\\Exception\\ContextErrorException(code: 0): Notice: Undefined index: en_us at /Users/alex/Sites/*WEBSITE*/vendor/kunstmaan/bundles-cms/src/Kunstmaan/NodeSearchBundle/Configuration/NodePagesConfiguration.php:141)"} {"file":"/Users/alex/Sites/*WEBSITE*/vendor/kunstmaan/bundles-cms/src/Kunstmaan/AdminBundle/EventListener/ConsoleExceptionListener.php","line":28,"class":"Kunstmaan\\AdminBundle\\EventListener\\ConsoleExceptionListener","function":"onConsoleException"}

[Symfony\Component\Debug\Exception\ContextErrorException]  
  Notice: Undefined index: en_us    

Probably linked to that, the populate function also returns an error of a missing index;

app.ERROR: Elastica\Exception\ResponseException: IndexMissingException[[*WEBSITE*nodeindex_en_us] missing] (uncaught exception) at /Users/alex/Sites/*WEBSITE*/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php line 170 while running console commandkuma:search:populate{"exception":"[object] (Elastica\\Exception\\ResponseException(code: 0): IndexMissingException[[*WEBSITE*nodeindex_en_us] missing] at /Users/alex/Sites/*WEBSITE*/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php:170)"} {"file":"/Users/alex/Sites/*WEBSITE*/vendor/kunstmaan/bundles-cms/src/Kunstmaan/AdminBundle/EventListener/ConsoleExceptionListener.php","line":28,"class":"Kunstmaan\\AdminBundle\\EventListener\\ConsoleExceptionListener","function":"onConsoleException"}

Predictably, the same error as above is returned when trying to view search results on the frontend.

iknowfoobar commented 8 years ago

This is because when using the multi domain bundle you must specify your full locales, e.g. en_us, en_gb, fr_fr etc.

These locales are not defined by the analyzer_languages.yml config file in the SearchBundle hence the undefined index problems.

This file can be overridden in your site bundle where you can add in the extra locales.

Would you want us to submit a pull request with more locales added to the file or is it expected that this file should be overridden if more locales are required, it may need adding to the documentation for the multi domain bundle?

Numkil commented 8 years ago

I am convinced we have to write documentation for it. We should always strive to have every single configurable thing documented. It would be nice to add more locales to the analyzer_languages.yml but I think it will never be complete enough that we should not document the possibility to configure it. Could you make a PR that adds some documentation to the multi domain bundle?

Numkil commented 8 years ago

I actually have some free time on my hands at the moment so I will take care of this.

iknowfoobar commented 8 years ago

I can send over exactly what we did to override it next week if that is any help?

Numkil commented 8 years ago

That would be helpful yes. Thanks for that.

iknowfoobar commented 8 years ago

We just changed the Extension class in our Bundle to:

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

        if (!array_key_exists('analyzer_languages', $config) or count($config['analyzer_languages']) <= 0) {
            $config['analyzer_languages'] = $this->getDefaultAnalyzerLanguages();
        }
        $container->setParameter('analyzer_languages', $config['analyzer_languages']);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }

    public function getDefaultAnalyzerLanguages()
    {
        return Yaml::parse(file_get_contents(__DIR__ . '/../Resources/config/analyzer_languages.yml'));
    }
}

and copied the analyzer_languages.yml from the SearchBundle Resources, adding in any locales needed.

Numkil commented 6 years ago

Error messages more clear because #1635 and no more crashes