Merge branch 'master' of github.com:doctrine/doctrine2
This commit is contained in:
commit
ed355d2eb6
@ -203,13 +203,18 @@ class EntityManager implements ObjectManager
|
|||||||
public function transactional(Closure $func)
|
public function transactional(Closure $func)
|
||||||
{
|
{
|
||||||
$this->conn->beginTransaction();
|
$this->conn->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$func($this);
|
$return = $func($this);
|
||||||
|
|
||||||
$this->flush();
|
$this->flush();
|
||||||
$this->conn->commit();
|
$this->conn->commit();
|
||||||
|
|
||||||
|
return $return ?: true;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->close();
|
$this->close();
|
||||||
$this->conn->rollback();
|
$this->conn->rollback();
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ class Parser
|
|||||||
* If they match, updates the lookahead token; otherwise raises a syntax
|
* If they match, updates the lookahead token; otherwise raises a syntax
|
||||||
* error.
|
* error.
|
||||||
*
|
*
|
||||||
* @param int|string token type or value
|
* @param int token type
|
||||||
* @return void
|
* @return void
|
||||||
* @throws QueryException If the tokens dont match.
|
* @throws QueryException If the tokens dont match.
|
||||||
*/
|
*/
|
||||||
|
@ -65,7 +65,7 @@ EOT
|
|||||||
|
|
||||||
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
|
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) {
|
if ($input->getOption('dump-sql') === true) {
|
||||||
$sqls = $schemaTool->getCreateSchemaSql($metadatas);
|
$sqls = $schemaTool->getCreateSchemaSql($metadatas);
|
||||||
|
@ -92,7 +92,7 @@ EOT
|
|||||||
}
|
}
|
||||||
$output->write('Database schema dropped successfully!' . PHP_EOL);
|
$output->write('Database schema dropped successfully!' . PHP_EOL);
|
||||||
} else {
|
} 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) {
|
if ($isFullDatabaseDrop) {
|
||||||
$sqls = $schemaTool->getDropDatabaseSQL();
|
$sqls = $schemaTool->getDropDatabaseSQL();
|
||||||
|
@ -86,7 +86,7 @@ EOT
|
|||||||
$schemaTool->updateSchema($metadatas, $saveMode);
|
$schemaTool->updateSchema($metadatas, $saveMode);
|
||||||
$output->write('Database schema updated successfully!' . PHP_EOL);
|
$output->write('Database schema updated successfully!' . PHP_EOL);
|
||||||
} else {
|
} 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('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);
|
$output->write('this SQL DDL to manually update your database in production.' . PHP_EOL . PHP_EOL);
|
||||||
|
|
||||||
|
@ -598,7 +598,11 @@ class SchemaTool
|
|||||||
*/
|
*/
|
||||||
public function getDropSchemaSQL(array $classes)
|
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();
|
$sql = array();
|
||||||
$orderedTables = array();
|
$orderedTables = array();
|
||||||
@ -633,13 +637,18 @@ class SchemaTool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$supportsForeignKeyConstraints = $conn->getDatabasePlatform()->supportsForeignKeyConstraints();
|
||||||
$dropTablesSql = array();
|
$dropTablesSql = array();
|
||||||
|
|
||||||
foreach ($orderedTables AS $tableName) {
|
foreach ($orderedTables AS $tableName) {
|
||||||
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
if ($supportsForeignKeyConstraints) {
|
||||||
$foreignKeys = $sm->listTableForeignKeys($tableName);
|
$foreignKeys = $sm->listTableForeignKeys($tableName);
|
||||||
|
|
||||||
foreach ($foreignKeys AS $foreignKey) {
|
foreach ($foreignKeys AS $foreignKey) {
|
||||||
$sql[] = $this->_platform->getDropForeignKeySQL($foreignKey, $tableName);
|
$sql[] = $this->_platform->getDropForeignKeySQL($foreignKey, $tableName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$dropTablesSql[] = $this->_platform->getDropTableSQL($tableName);
|
$dropTablesSql[] = $this->_platform->getDropTableSQL($tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,9 +657,11 @@ class SchemaTool
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the database schema of the given classes by comparing the ClassMetadata
|
* 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 array $classes
|
||||||
|
* @param boolean $saveMode
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function updateSchema(array $classes, $saveMode=false)
|
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
|
* 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.
|
* 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 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.
|
* @return array The sequence of SQL statements.
|
||||||
*/
|
*/
|
||||||
public function getUpdateSchemaSql(array $classes, $saveMode=false)
|
public function getUpdateSchemaSql(array $classes, $saveMode=false)
|
||||||
|
@ -143,4 +143,16 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->_em->close();
|
$this->_em->close();
|
||||||
$this->_em->$methodName(new \stdClass());
|
$this->_em->$methodName(new \stdClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1125
|
||||||
|
*/
|
||||||
|
public function testTransactionalAcceptsReturn()
|
||||||
|
{
|
||||||
|
$return = $this->_em->transactional(function ($em) {
|
||||||
|
return 'foo';
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->assertEquals('foo', $return);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user