Q:

Symfony2: copy entities in two environments with own database

The title sounds a bit strange but I'll try to explain.
I want two environments for the customer, a production environment and a QA environment. The customer asks if it's possible to create 'products' in the QA environment and afterwards copy this to the production environment. Is this even possible?
The environment have each a own database configuration.

A:

It's possible, you need two entity managers
//config.yml
doctrine:
    dbal:
        default_connection: default
        connections:
            client:
                driver:   %database_driver%
                host:     %database_host%
                port:     %database_port%
                dbname:   %database_name%
                user:     %database_user%
                password: %database_password%
                charset:  UTF8
            qa:
                driver:   %database_ga_driver%
                host:     %database_ga_host%
                port:     %database_ga_port%
                dbname:   %database_ga_name%
                user:     %database_ga_user%
                password: %database_ga_password%
                charset:  UTF8
    orm:
        default_entity_manager: default
        entity_managers:
            default:
                connection:     default
                mappings:
                    AcmeProductBundle: ~
            qa:
                connection:     qa
                mappings:
                    AcmeProductBundle: ~

Then just program some functions to copy the objects, some operations would look like that:
$em = $this->getDoctrine()->getManager();
$qa_em = $this->getDoctrine()->getManager('qa');

$qa_object = $qa_em->getRepository('AcmeProductBundle:Product')->find(1);

$em->persist($qa_object);
$em->flush();

