From 50ab186792b6a7d8775fb19c5c76a0bda1d09f02 Mon Sep 17 00:00:00 2001 From: "Jonathan.Wage" Date: Tue, 16 Oct 2007 02:37:31 +0000 Subject: [PATCH] Fixes for sql exporting so it will get all loaded models if no directory is specified. --- lib/Doctrine/Data/Export.php | 10 ++++++++-- lib/Doctrine/Export.php | 14 +++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/Data/Export.php b/lib/Doctrine/Data/Export.php index dbc683647..f8ab75be5 100644 --- a/lib/Doctrine/Data/Export.php +++ b/lib/Doctrine/Data/Export.php @@ -101,17 +101,23 @@ class Doctrine_Data_Export extends Doctrine_Data if (is_array($directory)) { throw new Doctrine_Data_Exception('You must specify a single path to a folder in order to export individual files.'); + } else if (!is_dir($directory) && is_file($directory)) { + $directory = dirname($directory); } foreach ($data as $className => $classData) { - Doctrine_Parser::dump(array($className => $classData), $format, $directory.DIRECTORY_SEPARATOR.$className.'.'.$format); + if (!empty($classData)) { + Doctrine_Parser::dump(array($className => $classData), $format, $directory.DIRECTORY_SEPARATOR.$className.'.'.$format); + } } } else { if (is_dir($directory)) { throw new Doctrine_Data_Exception('You must specify the path to a '.$format.' file to export. You specified a directory.'); } - return Doctrine_Parser::dump($data, $format, $directory); + if (!empty($data)) { + return Doctrine_Parser::dump($data, $format, $directory); + } } } /** diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index 53cd567b3..b6b060175 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -978,9 +978,9 @@ class Doctrine_Export extends Doctrine_Connection_Module public function exportSchema($directory = null) { if ($directory !== null) { - $models = Doctrine::loadModels($directory); + $models = Doctrine_Facade::loadModels($directory); } else { - $models = Doctrine::getLoadedModels(); + $models = Doctrine_Facade::getLoadedModels(); } $this->exportClasses($models); @@ -1058,7 +1058,7 @@ class Doctrine_Export extends Doctrine_Connection_Module */ public function exportClassesSql(array $classes) { - $models = Doctrine::getLoadedModels($classes); + $models = Doctrine_Facade::getLoadedModels($classes); $sql = array(); @@ -1136,8 +1136,12 @@ class Doctrine_Export extends Doctrine_Connection_Module */ public function exportSql($directory = null) { - $models = Doctrine::loadModels($directory); - + if ($directory !== null) { + $models = Doctrine_Facade::loadModels($directory); + } else { + $models = Doctrine_Facade::getLoadedModels(); + } + return $this->exportClassesSql($models); } /**