diff --git a/reference/configuration/doctrine.rst b/reference/configuration/doctrine.rst index 6e5bd12aaea..be655f90ae9 100644 --- a/reference/configuration/doctrine.rst +++ b/reference/configuration/doctrine.rst @@ -166,6 +166,96 @@ you can access it using the ``getConnection()`` method and the name of the conne } } +Disable Autocommit Mode +~~~~~~~~~~~~~~~~~~~~~~~ + +To disable the `Autocommit`_ mode, update your DBAL configuration as follows: + +.. configuration-block:: + + .. code-block:: yaml + + doctrine: + dbal: + connections: + default: + options: + # Only if you're using DBAL with PDO: + !php/const PDO::ATTR_AUTOCOMMIT: false + + # This line disables auto-commit at the DBAL level: + auto_commit: false + + .. code-block:: xml + + + + + + + + + false + + + + + +When using the `Doctrine Migrations Bundle`_, an additional listener needs to be registered to ensure that the last migration is properly committed: + +.. configuration-block:: + + .. code-block:: yaml + + # config/services.yaml + services: + Doctrine\Migrations\Event\Listeners\AutoCommitListener: + tags: + - name: doctrine.event_listener + event: onMigrationsMigrated + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // config/services.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + use Doctrine\Migrations\Event\Listeners\AutoCommitListener; + use Doctrine\Migrations\Events; + + return function(ContainerConfigurator $container): void { + $services = $container->services(); + + $services->set(AutoCommitListener::class) + ->tag('doctrine.event_listener', [ + 'event' => Events::onMigrationsMigrated + ]) + ; + }; + Doctrine ORM Configuration -------------------------- @@ -544,6 +634,7 @@ Ensure your environment variables are correctly set in the ``.env.local`` or This configuration secures your MySQL connection with SSL by specifying the paths to the required certificates. - +.. _Autocommit: https://en.wikipedia.org/wiki/Autocommit +.. _Doctrine Migrations Bundle: https://github.com/doctrine/DoctrineMigrationsBundle .. _DBAL documentation: https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/configuration.html .. _`Doctrine Metadata Drivers`: https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/metadata-drivers.html