From 45079a1e9860a6f6ffbe6f5aebd940781e7ce394 Mon Sep 17 00:00:00 2001 From: jwage Date: Tue, 17 Feb 2009 01:54:11 +0000 Subject: [PATCH] [2.0] Refactoring ClassExporter to allow the getting of the generated sql as well as executing it --- UPGRADE_TO_2_0 | 4 ++++ lib/Doctrine/ORM/Export/ClassExporter.php | 27 ++++++++++++++++++----- tests/Doctrine/Tests/ORM/AllTests.php | 3 ++- 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 UPGRADE_TO_2_0 diff --git a/UPGRADE_TO_2_0 b/UPGRADE_TO_2_0 new file mode 100644 index 000000000..9181fc3df --- /dev/null +++ b/UPGRADE_TO_2_0 @@ -0,0 +1,4 @@ +Upgrade to Doctrine 2.0 +####################### + +More information coming soon... diff --git a/lib/Doctrine/ORM/Export/ClassExporter.php b/lib/Doctrine/ORM/Export/ClassExporter.php index d66a9e580..ffa2116e7 100644 --- a/lib/Doctrine/ORM/Export/ClassExporter.php +++ b/lib/Doctrine/ORM/Export/ClassExporter.php @@ -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; } -} +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/AllTests.php b/tests/Doctrine/Tests/ORM/AllTests.php index 6205e4cd0..83866aa5a 100644 --- a/tests/Doctrine/Tests/ORM/AllTests.php +++ b/tests/Doctrine/Tests/ORM/AllTests.php @@ -32,10 +32,11 @@ class AllTests $suite->addTestSuite('Doctrine\Tests\ORM\EntityManagerTest'); $suite->addTestSuite('Doctrine\Tests\ORM\EntityPersisterTest'); $suite->addTestSuite('Doctrine\Tests\ORM\CommitOrderCalculatorTest'); - + $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());