When using bare-bone Doctrine with the command line that comes out of the box there are two commands available that don't seem to be available with using Doctrine with Symfony and the app/console
:
dbal
dbal:import Import SQL file(s) directly to Database.
dbal:run-sql Executes arbitrary SQL directly from the command line.
Is there a way to enable these commands within Symfony's app/console
?
Put this as
cli-config.php
into your project's root directory. This will enable the--env
parameter forphp vendor/bin/doctrine
. It is "inspired" by Symfony's app/console file.Note this is for Doctrine <=2.3, see the docs for newer versions.
Doctrine commands are available in symfony projects through the DoctrineBundle (since version 1.6.4).
You can now run
php bin/console doctrine:database:import [files]
.I found a workaround for this, as you may call it that, or maybe rather just a way to enable the commands.
By adding a
Command
to one of your own bundles (or a dedicated one, is up to you), you can simply subclass the Doctrine command. E.g. to enable thedbal:import
command use the following:As you can see, we simply subclass the original command. Since the database configuration is managed by Symfony we need to get the entity manager through the container. Once we update the
HelperSet
we pass execution back to the parent class.