From 234d2e5f0f7313790e9717173511257b88a9cd85 Mon Sep 17 00:00:00 2001 From: Albert Jessurum Date: Tue, 15 Mar 2011 12:22:53 +0100 Subject: [PATCH 1/5] Fix typo on schema help messages --- .../ORM/Tools/Console/Command/SchemaTool/CreateCommand.php | 2 +- .../ORM/Tools/Console/Command/SchemaTool/DropCommand.php | 2 +- .../ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php index e18a9c56a..835835d28 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php @@ -65,7 +65,7 @@ EOT protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) { - $output->write('ATTENTION: This operation should not be executed in an production enviroment.' . PHP_EOL . PHP_EOL); + $output->write('ATTENTION: This operation should not be executed in a production enviroment.' . PHP_EOL . PHP_EOL); if ($input->getOption('dump-sql') === true) { $sqls = $schemaTool->getCreateSchemaSql($metadatas); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php index 82d91f4c6..f6f16cb79 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php @@ -92,7 +92,7 @@ EOT } $output->write('Database schema dropped successfully!' . PHP_EOL); } else { - $output->write('ATTENTION: This operation should not be executed in an production enviroment.' . PHP_EOL . PHP_EOL); + $output->write('ATTENTION: This operation should not be executed in a production enviroment.' . PHP_EOL . PHP_EOL); if ($isFullDatabaseDrop) { $sqls = $schemaTool->getDropDatabaseSQL(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php index f1a3a73cf..ed12358cd 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php @@ -86,7 +86,7 @@ EOT $schemaTool->updateSchema($metadatas, $saveMode); $output->write('Database schema updated successfully!' . PHP_EOL); } else { - $output->write('ATTENTION: This operation should not be executed in an production enviroment.' . PHP_EOL); + $output->write('ATTENTION: This operation should not be executed in a production enviroment.' . PHP_EOL); $output->write('Use the incremental update to detect changes during development and use' . PHP_EOL); $output->write('this SQL DDL to manually update your database in production.' . PHP_EOL . PHP_EOL); From 5784c7bacd4f1f190e0be637b5a22f06675711b0 Mon Sep 17 00:00:00 2001 From: Chekote Date: Fri, 1 Apr 2011 12:54:12 -0500 Subject: [PATCH 2/5] Fixed phpdoc on Parser::match incorrectly stating that the token parameter can be a string value --- lib/Doctrine/ORM/Query/Parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 2ba869f22..798afa0ce 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -234,7 +234,7 @@ class Parser * If they match, updates the lookahead token; otherwise raises a syntax * error. * - * @param int|string token type or value + * @param int token type * @return void * @throws QueryException If the tokens dont match. */ From 0b7feb359dff7ab499dd7024fbf8df718018a7de Mon Sep 17 00:00:00 2001 From: Rafael Dohms Date: Sun, 17 Apr 2011 23:39:59 -0300 Subject: [PATCH 3/5] Fixing outdated docblocks for SchemaTool --- lib/Doctrine/ORM/Tools/SchemaTool.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 1edbd38a1..f7e3e9d7c 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -648,9 +648,11 @@ class SchemaTool /** * Updates the database schema of the given classes by comparing the ClassMetadata - * ins$tableNametances to the current database schema that is inspected. + * instances to the current database schema that is inspected. If $saveMode is set + * to true the command is executed in the Database, else SQL is returned. * * @param array $classes + * @param boolean $saveMode * @return void */ public function updateSchema(array $classes, $saveMode=false) @@ -666,8 +668,11 @@ class SchemaTool /** * Gets the sequence of SQL statements that need to be performed in order * to bring the given class mappings in-synch with the relational schema. + * If $saveMode is set to true the command is executed in the Database, + * else SQL is returned. * * @param array $classes The classes to consider. + * @param boolean $saveMode True for writing to DB, false for SQL string * @return array The sequence of SQL statements. */ public function getUpdateSchemaSql(array $classes, $saveMode=false) From 26bd3e381195ba0901c506e8257e0eb6e5d5c931 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Mon, 25 Apr 2011 18:32:43 -0300 Subject: [PATCH 4/5] Implemented support for closure return on EntityManager::transactional. Fixes DDC-1125 --- lib/Doctrine/ORM/EntityManager.php | 7 ++++++- tests/Doctrine/Tests/ORM/EntityManagerTest.php | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index d06d2dea9..0379cc435 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -203,13 +203,18 @@ class EntityManager implements ObjectManager public function transactional(Closure $func) { $this->conn->beginTransaction(); + try { - $func($this); + $return = $func($this); + $this->flush(); $this->conn->commit(); + + return $return ?: true; } catch (Exception $e) { $this->close(); $this->conn->rollback(); + throw $e; } } diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 8f9045c34..ca896ad10 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -143,4 +143,16 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase $this->_em->close(); $this->_em->$methodName(new \stdClass()); } + + /** + * @group DDC-1125 + */ + public function testTransactionalAcceptsReturn() + { + $return = $this->_em->transactional(function ($em) { + return 'foo'; + }); + + $this->assertEquals('foo', $return); + } } \ No newline at end of file From fe66d8bc04de42ab13b83892df11a5ea1533b544 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Tue, 26 Apr 2011 12:32:04 -0300 Subject: [PATCH 5/5] Fixed SchemaTool which was failing to dropSchema due to foreignKeyContraint checks. Fixes DDC-1126 --- lib/Doctrine/ORM/Tools/SchemaTool.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 1edbd38a1..f1358708b 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -598,7 +598,11 @@ class SchemaTool */ public function getDropSchemaSQL(array $classes) { - $sm = $this->_em->getConnection()->getSchemaManager(); + /* @var $conn \Doctrine\DBAL\Connection */ + $conn = $this->_em->getConnection(); + + /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ + $sm = $conn->getSchemaManager(); $sql = array(); $orderedTables = array(); @@ -633,13 +637,18 @@ class SchemaTool } } + $supportsForeignKeyConstraints = $conn->getDatabasePlatform()->supportsForeignKeyConstraints(); $dropTablesSql = array(); + foreach ($orderedTables AS $tableName) { - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $foreignKeys = $sm->listTableForeignKeys($tableName); - foreach ($foreignKeys AS $foreignKey) { - $sql[] = $this->_platform->getDropForeignKeySQL($foreignKey, $tableName); + if ($supportsForeignKeyConstraints) { + $foreignKeys = $sm->listTableForeignKeys($tableName); + + foreach ($foreignKeys AS $foreignKey) { + $sql[] = $this->_platform->getDropForeignKeySQL($foreignKey, $tableName); + } } + $dropTablesSql[] = $this->_platform->getDropTableSQL($tableName); }