[2.0] Refactoring ClassExporter to allow the getting of the generated sql as well as executing it
This commit is contained in:
parent
438d970f40
commit
45079a1e98
4
UPGRADE_TO_2_0
Normal file
4
UPGRADE_TO_2_0
Normal file
@ -0,0 +1,4 @@
|
||||
Upgrade to Doctrine 2.0
|
||||
#######################
|
||||
|
||||
More information coming soon...
|
@ -58,12 +58,27 @@ class ClassExporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports entity classes to a database, according to the specified mappings.
|
||||
* Exports an array of class meta data instances to your database
|
||||
*
|
||||
* @param array $classes
|
||||
*/
|
||||
public function exportClasses(array $classes)
|
||||
{
|
||||
$exportClassesSql = $this->getExportClassesSql($classes);
|
||||
foreach ($exportClassesSql as $sql) {
|
||||
$this->_em->getConnection()->execute($sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of sql statements for the specified array of class meta data instances
|
||||
*
|
||||
* @param array $classes
|
||||
* @return array $sql
|
||||
*/
|
||||
public function getExportClassesSql(array $classes)
|
||||
{
|
||||
$sql = array();
|
||||
$foreignKeyConstraints = array();
|
||||
|
||||
// First we create the tables
|
||||
@ -143,18 +158,20 @@ class ClassExporter
|
||||
}
|
||||
$foreignKeyConstraints[] = $constraint2;
|
||||
|
||||
$this->_sm->createTable($joinTable['name'], $joinTableColumns, array());
|
||||
$sql = array_merge($sql, $this->_platform->getCreateTableSql($joinTable['name'], $joinTableColumns, array()));
|
||||
}
|
||||
}
|
||||
|
||||
$this->_sm->createTable($class->getTableName(), $columns, $options);
|
||||
$sql = array_merge($sql, $this->_platform->getCreateTableSql($class->getTableName(), $columns, $options));
|
||||
}
|
||||
|
||||
// Now create the foreign key constraints
|
||||
if ($this->_platform->supportsForeignKeyConstraints()) {
|
||||
foreach ($foreignKeyConstraints as $fkConstraint) {
|
||||
$this->_sm->createForeignKey($fkConstraint['tableName'], $fkConstraint);
|
||||
$sql = array_merge($sql, $this->_platform->getCreateForeignKeySql($fkConstraint['tableName'], $fkConstraint));
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@ class AllTests
|
||||
$suite->addTest(Query\AllTests::suite());
|
||||
$suite->addTest(Hydration\AllTests::suite());
|
||||
$suite->addTest(Entity\AllTests::suite());
|
||||
$suite->addTest(Export\AllTests::suite());
|
||||
$suite->addTest(Associations\AllTests::suite());
|
||||
$suite->addTest(Mapping\AllTests::suite());
|
||||
$suite->addTest(Functional\AllTests::suite());
|
||||
|
Loading…
Reference in New Issue
Block a user