1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Merge branch 'master' of github.com:doctrine/doctrine2

This commit is contained in:
Benjamin Eberlei 2011-04-30 11:19:58 +02:00
commit ed355d2eb6
7 changed files with 42 additions and 11 deletions

View File

@ -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;
}
}

View File

@ -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.
*/

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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);
}
@ -648,9 +657,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 +677,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)

View File

@ -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);
}
}