From 8d8ac0ee0921ac2b190146fda9fd55ede31ae2c3 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 7 Aug 2018 09:13:23 -0700 Subject: [PATCH] Removed dbal:import CLI command --- UPGRADE.md | 5 + .../Tools/Console/Command/ImportCommand.php | 123 ------------------ .../DBAL/Tools/Console/ConsoleRunner.php | 2 - 3 files changed, 5 insertions(+), 125 deletions(-) delete mode 100644 lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php diff --git a/UPGRADE.md b/UPGRADE.md index a6731e2ad03..fca29599cff 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,10 @@ # Upgrade to 3.0 +## BC BREAK: Removed dbal:import CLI command + +The `dbal:import` CLI command has been removed since it only worked with PDO-based drivers by relying on a non-documented behavior of the extension, and it was impossible to make it work with other drivers. +Please use other database client applications for import, e.g. `mysql < data.sql`. + ## BC BREAK: Removed support for DB-generated UUIDs The support for DB-generated UUIDs was removed as non-portable. diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php deleted file mode 100644 index 48dde2c84fc..00000000000 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ /dev/null @@ -1,123 +0,0 @@ - - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel - */ -class ImportCommand extends Command -{ - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('dbal:import') - ->setDescription('Import SQL file(s) directly to Database.') - ->setDefinition([ - new InputArgument( - 'file', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'File path(s) of SQL to be executed.' - ) - ]) - ->setHelp(<<getHelper('db')->getConnection(); - - if (($fileNames = $input->getArgument('file')) !== null) { - foreach ((array) $fileNames as $fileName) { - $filePath = realpath($fileName); - - // Phar compatibility. - if (false === $filePath) { - $filePath = $fileName; - } - - if ( ! file_exists($filePath)) { - throw new \InvalidArgumentException( - sprintf("SQL file '%s' does not exist.", $filePath) - ); - } elseif ( ! is_readable($filePath)) { - throw new \InvalidArgumentException( - sprintf("SQL file '%s' does not have read permissions.", $filePath) - ); - } - - $output->write(sprintf("Processing file '%s'... ", $filePath)); - $sql = file_get_contents($filePath); - - if ($conn instanceof \Doctrine\DBAL\Driver\PDOConnection) { - // PDO Drivers - try { - $lines = 0; - - $stmt = $conn->prepare($sql); - assert($stmt instanceof PDOStatement); - - $stmt->execute(); - - do { - // Required due to "MySQL has gone away!" issue - $stmt->fetch(); - $stmt->closeCursor(); - - $lines++; - } while ($stmt->nextRowset()); - - $output->write(sprintf('%d statements executed!', $lines) . PHP_EOL); - } catch (\PDOException $e) { - $output->write('error!' . PHP_EOL); - - throw new \RuntimeException($e->getMessage(), $e->getCode(), $e); - } - } else { - // Non-PDO Drivers (ie. OCI8 driver) - $stmt = $conn->prepare($sql); - $rs = $stmt->execute(); - - if ($rs) { - $output->writeln('OK!' . PHP_EOL); - } else { - $error = $stmt->errorInfo(); - - $output->write('error!' . PHP_EOL); - - throw new \RuntimeException($error[2], $error[0]); - } - - $stmt->closeCursor(); - } - } - } - } -} diff --git a/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php b/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php index 69098e2ea8e..f2d40551ac7 100644 --- a/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php @@ -3,7 +3,6 @@ namespace Doctrine\DBAL\Tools\Console; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Tools\Console\Command\ImportCommand; use Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand; use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; @@ -60,7 +59,6 @@ public static function addCommands(Application $cli) { $cli->addCommands([ new RunSqlCommand(), - new ImportCommand(), new ReservedWordsCommand(), ]); }