Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

What happened to the 'doctrine:database:import' command ?#44090

Answeredbymbabker
mdeherder asked this question inQ&A
Discussion options

Command "doctrine:database:import" is not defined.

You must be logged in to vote

https://github.com/doctrine/dbal/blob/3.4.4/UPGRADE.md#bc-break-removed-dbalimport-cli-command

DBAL 3.x dropped support for it as noted in the upgrade guide. The corresponding command in the DoctrineBundle is deprecated and is only registered when DBAL 2.x is detected.

Replies: 1 comment 7 replies

Comment options

https://github.com/doctrine/dbal/blob/3.4.4/UPGRADE.md#bc-break-removed-dbalimport-cli-command

DBAL 3.x dropped support for it as noted in the upgrade guide. The corresponding command in the DoctrineBundle is deprecated and is only registered when DBAL 2.x is detected.

You must be logged in to vote
7 replies
@jcrombez
Comment options

you can also do :

dbal:run-sql "$(cat /path/to/your.sql)"
@YetiCGN
Comment options

@jcrombez Unfortunately, that yields the errorArgument list too long

@KristofDeTroch
Comment options

Has anyone found a working fix? I also ran into this issue and nothing seems to replace doctrine:database:import appropriately.

@stof
Comment options

stofSep 8, 2022
Collaborator

Well, the replacement is given by the Doctrine DBAL upgrade file (note that I edited the answer to give a link pointing to a tag rather than a removed branch so that the link works)

@homersimpsons
Comment options

In my case the database is somewhere else so I do not have access to a database client. Hence I implemented a simple script:

<?phpdeclare(strict_types=1);namespaceApp\Command;useDoctrine\Bundle\DoctrineBundle\Command\DoctrineCommand;useDoctrine\DBAL\Connection;useSymfony\Component\Console\Input\InputArgument;useSymfony\Component\Console\Input\InputInterface;useSymfony\Component\Console\Input\InputOption;useSymfony\Component\Console\Output\OutputInterface;/** * Task for executing arbitrary SQL that can come from a file or directly from the command line. * * From https://github.com/doctrine/dbal/blob/c2b8e6e82732a64ecde1cddf9e1e06cb8556e3d8/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php * Connection retrieval from https://github.com/doctrine/DoctrineBundle/blob/84f166beb72711b40419a9c0c62aa88729273d51/src/Command/CreateDatabaseDoctrineCommand.php */class SqlImportCommandextends DoctrineCommand{/**     * {@inheritdoc}     */protectedfunctionconfigure()    {$this            ->setName('app:sql:import')            ->setDescription('Import SQL file(s) directly to Database.')            ->addOption('connection','c', InputOption::VALUE_OPTIONAL,'The connection to use for this command')            ->addArgument('file', InputArgument::REQUIRED | InputArgument::IS_ARRAY,'File path(s) of SQL to be executed.')            ->setHelp('Import SQL file(s) directly to Database.');    }/**     * {@inheritdoc}     */protectedfunctionexecute(InputInterface$input,OutputInterface$output)    {$connectionName =$input->getOption('connection');assert($connectionName ===null ||is_string($connectionName));$fileNames =$input->getArgument('file');$connection =$this->getDoctrine()->getConnection($connectionName);assert($connectioninstanceof Connection);foreach ($fileNamesas$fileName) {$filePath =realpath($fileName);$output->write(sprintf("Processing file '<info>%s</info>'...",$filePath));$sql =file_get_contents($filePath);$connection->prepare($sql)->executeStatement();        }return0;    }}

This is using the internalDoctrineCommand so it may break at any time.

Answer selected bymdeherder
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
8 participants
@mdeherder@mbabker@stof@YetiCGN@jcrombez@homersimpsons@RobinTHOREL@KristofDeTroch

[8]ページ先頭

©2009-2025 Movatter.jp