3

Lately I have created an extra database with it's own user. Therefore I have created an extra database driver in the parameters.yml. This is, as far as I know, the standard approach for this kind of situations. So far, it works. In one of the services I created, I can use this database driver. When running the code on the website, there are no problems at all.

But of course there is a problem, otherwise I won't asking for your guys help.

I'm trying to install a plugin by running the following command:

$ ./composer.phar require pugx/autocompleter-bundle

This gives the following error:

[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "database_driver_geo". Did you mean this: "database_driver"?

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception

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

[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command.

Some other posts say that the error about the cache has something to do with the file/dir rights. But that doesn't seem to be the problem, because when the configuration of the geo driver is removed, these kind of errors do not appear.

I'm running Symfony 2.5

[EDIT: Added parameters.yml file]

My parameters.yml looks like this:

# This file is auto-generated during the composer install
parameters:
    # Default database
    database_driver: pdo_mysql
    database_host: ***
    database_port: ***
    database_name: ***
    database_user: ***
    database_password: ***

    # Geo database
    database_driver_geo: pdo_mysql
    database_host_geo: ***
    database_port_geo: ***
    database_name_geo: ***
    database_user_geo: ***
    database_password_geo: ***

    mailer_transport: ***
    mailer_host: ***
    mailer_user: ***
    mailer_password: ***
    locale: ***
    secret: ***

[EDIT: Added config.yml file]

The doctrine section in the config.yml file:

# Doctrine Configuration
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:         %database_driver%
                host:           %database_host%
                port:           %database_port%
                dbname:         %database_name%
                user:           %database_user%
                password:       %database_password%
                charset:        UTF8
                mapping_types:
                    enum:       string
                    bit:        integer
                # if using pdo_sqlite as your database driver, add the path in parameters.yml
                # e.g. database_path: %kernel.root_dir%/data/data.db3
                # path:     %database_path%

            geo:
                driver:         %database_driver_geo%
                host:           %database_host_geo%
                port:           %database_port_geo%
                dbname:         %database_name_geo%
                user:           %database_user_geo%
                password:       %database_password_geo%
                charset:        UTF8
                mapping_types:
                    enum:       string
                    bit:        integer
                # if using pdo_sqlite as your database driver, add the path in parameters.yml
                # e.g. database_path: %kernel.root_dir%/data/data.db3
                # path:     %database_path%

    orm:
        default_entity_manager: default
        entity_managers:
                default:
                    connection: default
                    mappings:
                        ***CoreBundle: ~
                geo:
                    connection: geo
                    mappings:
                        ***GeoBundle: ~
        auto_generate_proxy_classes: %kernel.debug%

I hope there's someone that can help me fix this problem.

Kind regards,

Malcolm

  • Can you post your parameters.yml file ? (hide the sensitive values, but keep the tree structure please). Did you register a new entity manager in your config.yml file too, under doctrine.dbal.connections ? – VaN Jul 26 '16 at 07:40
  • 1
    `parameters.yml` is automatically rebuilt when you install new composer package. You should place your parameters (or at least default values) in `parameters.yml.dist`. They will be copied into `parameters.yml`. – Jakub Matczak Jul 26 '16 at 07:56
  • @dragoste It looks like you are right. In my parameters.yml there is more data than in my .dist version. But in the config.yml symfony added this comment: "add the path in parameters.yml". So they are actually giving wrong advice? But how about the secret codes? Should I add them also to the .dist version? – Malcolm Kindermans Jul 26 '16 at 08:19
  • 1
    `parameters.yml.dist` contains default values, so e.g. there is `secret` param in `.dist` file with some default value, but it can be overridden in parameters.yml **after** deploying application to the server. – Jakub Matczak Jul 26 '16 at 08:32
  • @dragoste: thanks! It solved my problem. If you post your comment as an answer, I upvote it and mark it as the answer. – Malcolm Kindermans Jul 26 '16 at 08:44

1 Answers1

2

As mentioned in comments, parameters.yml file is autmatically rebuilt after composer update or install command. You can see that in your composer.json file in scripts section:

"scripts": {
    "post-install-cmd": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        // other commands...
    ],
    "post-update-cmd": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        // other commands...
    ]
},

You can of course turn off this feature if you don't like it. But it may be useful when used properly.

Therefore when you install some package via composer you're losing parameters that you put directly into parameters.yml.

What you should do is to make use of parameters.yml.dist file which is used to build parameters.yml. It should provide application parameters values (if they are the same for every instance of app) or default values if parameters are different for every environment (prod/dev).

In your case it's the second use case (default values), since DB credentials will change for every server. It's actually exactly the same as configuration of default DB connection. parameters.yml.dist contains some default values for these params.

Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64