Created
December 13, 2015 18:43
-
-
Save doctrinebot/58375ca36e51bcecb47d to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-300 - https://github.com/doctrine/doctrine2/issues/3766
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: RunSqlTask.php | |
=================================================================== | |
--- RunSqlTask.php (revision 7103) | |
+++ RunSqlTask.php (working copy) | |
@@ -99,7 +99,37 @@ | |
$arguments = $this->getArguments(); | |
if (isset($arguments['file'])) { | |
- //TODO | |
+ $fileName = $arguments['file']; | |
+ if (!file_exists($fileName)) { | |
+ throw new CliException(sprintf('The SQL file [%s] does not exist.', $fileName)); | |
+ } elseif ( ! is_readable($fileName)) { | |
+ throw new CliException(sprintf('The SQL file [%s] does not have read permissions.', $fileName)); | |
+ } | |
+ | |
+ $em = $this->getConfiguration()->getAttribute('em'); | |
+ | |
+ $resultSet = array(); | |
+ | |
+ $executedCount = 0; | |
+ | |
+ $this->getPrinter()->writeln('Processing file...'); | |
+ | |
+ foreach (file($fileName) as $sql) { | |
+ if (preg_match('/^select/i', $sql)) { | |
+ $stmt = $em->getConnection()->execute($sql); | |
+ $resultSet[] = $stmt->fetchAll(\Doctrine\DBAL\Connection::FETCH_ASSOC); | |
+ } else { | |
+ $resultSet[] = $em->getConnection()->executeUpdate($sql); | |
+ } | |
+ $executedCount ++; | |
+ } | |
+ | |
+ $this->getPrinter()->writeln(sprintf('%d statements executed.', $executedCount)); | |
+ | |
+ $maxDepth = isset($arguments['depth']) ? $arguments['depth'] : 7; | |
+ | |
+ Debug::dump($resultSet); | |
+ | |
} else if (isset($arguments['sql'])) { | |
$em = $this->getConfiguration()->getAttribute('em'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment