8

Can't install/require the ongr/elasticsearch-bundle "~5.0" as per github example.

Im running a fresh install of the latest symfony.

I'm running the following command: composer require ongr/elasticsearch-bundle "~5.0"

as per https://github.com/ongr-io/ElasticsearchBundle

composer require ongr/elasticsearch-bundle "~5.0"

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.2.*"
Package operations: 7 installs, 0 updates, 0 removals
  - Installing react/promise (v2.7.1): Loading from cache
  - Installing guzzlehttp/streams (3.0.0): Loading from cache
  - Installing guzzlehttp/ringphp (1.1.1): Loading from cache
  - Installing elasticsearch/elasticsearch (v5.5.0): Loading from cache
  - Installing ongr/elasticsearch-dsl (v5.0.6): Loading from cache
  - Installing symfony/templating (v4.2.11): Loading from cache
  - Installing ongr/elasticsearch-bundle (v5.2.4): Loading from cache
Writing lock file
Generating autoload files
ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
Symfony operations: 1 recipe (c91982d16a3859d0a43fd4ff85aa437a)
  - Configuring ongr/elasticsearch-bundle (>=v5.2.4): From auto-generated recipe
Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 1
!!  
!!  In ArrayNode.php line 228:
!!                                                                                
!!    The child node "managers" at path "ongr_elasticsearch" must be configured.  
!!                                                                                
!!  
!!  
Script @auto-scripts was called via post-update-cmd

Installation failed, reverting ./composer.json to its original content.

What can I do to solve this issue?

The tutorial mentions a config.yml (which i dont have), i'd assume this would be created if it doesnt exist during the installation

Bart
  • 103
  • 1
  • 1
  • 5
  • This looks like the configuration for the bundle is missing. Try continuing with step 2 (Add configuration). Afterwards you should be able to run `composer install? or just the `bin/console cache:clear` that fails after installing the bundle – dbrumann Aug 07 '19 at 11:54
  • The other solution would be to temporarily remove the added line from the `AppKernel` until `composer require ongr/elasticsearch-bundle "~5.0"` finished. By registering the bundle right away you have to make sure that at least the mandatory configuration is set. – dbrumann Aug 07 '19 at 11:57
  • @dbrumann, thanks for your help thus far! Somehow composer is adding the line to my bundles.php automatically during the install. Ill try some variations of what you mentioned and report back shortly! – Bart Aug 07 '19 at 12:22

2 Answers2

5

The problem is that there's a script that clears Symfony cache immediately after the new dependencies are installed, before you get the chance to add proper configuration to your config files.

Assuming there's a section in your composer.json file that looks like this:

"scripts": {
    "auto-scripts": {
        "cache:clear": "symfony-cmd",
        "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },

you should remove the "cache:clear": "symfony-cmd" line. If it doesn't look exactly like this, just remove all lines that contain cache:clear. You might want to restore this line/these lines after you've successfully installed and configured ongr/elasticsearch-bundle, so that you don't have to remember to clear cache manually after installing bundles that are better compatible with Symfony Flex, or don't fall victim to its overzealousness with trying to be helpful.

Alternatively, and this is probably a much better solution - get rid of symfony/flex entirely. It has a nasty habit of messing up your configuration files when some 3rd party adds a command to a recipe without checking if all the requirements have been met. I know, I've been there.

Bartosz Zasada
  • 3,762
  • 2
  • 19
  • 25
  • 13
    Rather than removing the `cache:clear` command completely, maybe consider using `composer require --no-scripts ...` to make sure that other update commands will clear the cache to prevent odd behavior due to outdated caches. – dbrumann Aug 07 '19 at 13:10
3

You can use --no-scripts option to bypass cache:clear in the beginning, just use it with knowledge as bypassing a cache clear can create regular caching problems from old uses when app is being initiated.

ycbandiran
  • 31
  • 3