1
0
mirror of synced 2025-01-18 06:21:40 +03:00

Merged r3122:r3126

This commit is contained in:
Jonathan.Wage 2007-11-10 19:54:34 +00:00
parent ec1ec99446
commit b1c4c5f53f
4 changed files with 75 additions and 28 deletions

View File

@ -714,6 +714,8 @@ final class Doctrine
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
$connections = $manager->getConnections(); $connections = $manager->getConnections();
$results = array();
foreach ($connections as $name => $connection) { foreach ($connections as $name => $connection) {
if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) { if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
continue; continue;
@ -738,10 +740,14 @@ final class Doctrine
// Reopen original connection with newly created database // Reopen original connection with newly created database
$manager->openConnection(new PDO($info['dsn'], $username, $password), $name, true); $manager->openConnection(new PDO($info['dsn'], $username, $password), $name, true);
} catch (Exception $e) {
$results[$name] = true;
} catch (Exception $e) {
$results[$name] = false;
} }
} }
return $results;
} }
/** /**
@ -762,6 +768,8 @@ final class Doctrine
$connections = $manager->getConnections(); $connections = $manager->getConnections();
$results = array();
foreach ($connections as $name => $connection) { foreach ($connections as $name => $connection) {
if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) { if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
continue; continue;
@ -769,10 +777,14 @@ final class Doctrine
try { try {
$connection->export->dropDatabase($name); $connection->export->dropDatabase($name);
} catch (Exception $e) {
$results[$name] = true;
} catch (Exception $e) {
$results[$name] = false;
} }
} }
return $results;
} }
/** /**
@ -1047,10 +1059,38 @@ final class Doctrine
*/ */
public static function makeDirectories($path, $mode = 0777) public static function makeDirectories($path, $mode = 0777)
{ {
if (!$path) {
return false;
}
if (is_dir($path) || is_file($path)) { if (is_dir($path) || is_file($path)) {
return true; return true;
} }
return mkdir($path, $mode, true); return mkdir($path, $mode, true);
} }
function removeDirectories($folderPath)
{
if (is_dir($folderPath))
{
foreach (scandir($folderPath) as $value)
{
if ($value != '.' && $value != '..')
{
$value = $folderPath . "/" . $value;
if (is_dir($value)) {
self::removeDirectories($value);
} else if (is_file($value)) {
@unlink($value);
}
}
}
return rmdir ( $folderPath );
} else {
return false;
}
}
} }

View File

@ -64,7 +64,7 @@ class Doctrine_Data_Import extends Doctrine_Data
// If they specified a specific yml file // If they specified a specific yml file
if (end($e) == 'yml') { if (end($e) == 'yml') {
$array = array_merge(Doctrine_Parser::load($dir, $this->getFormat()), $array); $array = array_merge($array, Doctrine_Parser::load($dir, $this->getFormat()));
// If they specified a directory // If they specified a directory
} else if(is_dir($dir)) { } else if(is_dir($dir)) {
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
@ -73,17 +73,17 @@ class Doctrine_Data_Import extends Doctrine_Data
foreach ($it as $file) { foreach ($it as $file) {
$e = explode('.', $file->getFileName()); $e = explode('.', $file->getFileName());
if (in_array(end($e), $this->getFormats())) { if (in_array(end($e), $this->getFormats())) {
$array = array_merge(Doctrine_Parser::load($file->getPathName(), $this->getFormat()), $array); $array = array_merge($array, Doctrine_Parser::load($file->getPathName(), $this->getFormat()));
} }
} }
} }
} }
} }
$this->loadData($array); $this->_loadData($array);
} }
protected function buildRows($className, $data) protected function _buildRows($className, $data)
{ {
$rows = array(); $rows = array();
foreach ($data as $rowKey => $row) { foreach ($data as $rowKey => $row) {
@ -96,7 +96,7 @@ class Doctrine_Data_Import extends Doctrine_Data
// Skip associative arrays defining keys to relationships // Skip associative arrays defining keys to relationships
if (!isset($keys[0])) { if (!isset($keys[0])) {
$rows = array_merge($rows, $this->buildRows(Doctrine::getTable($className)->getRelation($key)->getTable()->getOption('name'), $value)); $rows = array_merge($rows, $this->_buildRows(Doctrine::getTable($className)->getRelation($key)->getTable()->getOption('name'), $value));
} }
} }
} }
@ -110,7 +110,7 @@ class Doctrine_Data_Import extends Doctrine_Data
* @param string $array * @param string $array
* @return void * @return void
*/ */
protected function loadData(array $array) protected function _loadData(array $array)
{ {
$specifiedModels = $this->getModels(); $specifiedModels = $this->getModels();
$rows = array(); $rows = array();
@ -127,9 +127,9 @@ class Doctrine_Data_Import extends Doctrine_Data
$templates = array_keys($obj->getTable()->getTemplates()); $templates = array_keys($obj->getTable()->getTemplates());
if (in_array('Doctrine_Template_NestedSet', $templates)) { if (in_array('Doctrine_Template_NestedSet', $templates)) {
$this->loadNestedSetData($className, $data); $this->_loadNestedSetData($className, $data);
} else { } else {
$rows = array_merge($rows, $this->buildRows($className, $data)); $rows = array_merge($rows, $this->_buildRows($className, $data));
} }
} }
@ -189,7 +189,7 @@ class Doctrine_Data_Import extends Doctrine_Data
} }
} }
protected function loadNestedSetData($model, $nestedSetData, $parent = null) protected function _loadNestedSetData($model, $nestedSetData, $parent = null)
{ {
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
@ -222,7 +222,7 @@ class Doctrine_Data_Import extends Doctrine_Data
if( is_array($children) AND !empty($children) ) if( is_array($children) AND !empty($children) )
{ {
$this->loadNestedSetData($model, $children, $record); $this->_loadNestedSetData($model, $children, $record);
} }
} }
} }

View File

@ -131,8 +131,8 @@ class Doctrine_Import_Builder
{ {
Doctrine::makeDirectories($path); Doctrine::makeDirectories($path);
if (!$this->_packagesPath) { if ( ! $this->_packagesPath) {
$this->_packagesPath = $path . DIRECTORY_SEPARATOR . 'packages'; $this->setPackagesPath($path . DIRECTORY_SEPARATOR . 'packages');
} }
$this->_path = $path; $this->_path = $path;
@ -157,6 +157,8 @@ class Doctrine_Import_Builder
*/ */
public function setPackagesPath($packagesPath) public function setPackagesPath($packagesPath)
{ {
Doctrine::makeDirectories($packagesPath);
$this->_packagesPath = $packagesPath; $this->_packagesPath = $packagesPath;
} }
@ -259,8 +261,14 @@ class Doctrine_Import_Builder
*/ */
public function setOption($key, $value) public function setOption($key, $value)
{ {
$name = '_'.$key; $name = 'set' . Doctrine::classify($key);
$this->$name = $value;
if (method_exists($this, $name)) {
$this->$name($value);
} else {
$key = '_' . $key;
$this->$key = $value;
}
} }
/** /**

View File

@ -117,7 +117,7 @@ class Doctrine_Import_Schema
} }
} }
$this->buildRelationships($array); $this->_buildRelationships($array);
return array('schema' => $array, 'relations' => $this->_relations); return array('schema' => $array, 'relations' => $this->_relations);
} }
@ -137,13 +137,12 @@ class Doctrine_Import_Schema
{ {
$builder = new Doctrine_Import_Builder(); $builder = new Doctrine_Import_Builder();
$builder->setTargetPath($directory); $builder->setTargetPath($directory);
$builder->generateBaseClasses($this->getOption('generateBaseClasses'));
$builder->generateTableClasses($this->getOption('generateTableClasses')); foreach ($this->_options as $key => $value) {
$builder->setBaseClassesDirectory($this->getOption('baseClassesDirectory')); if ($value) {
$builder->setBaseClassName($this->getOption('baseClassName')); $builder->setOption($key, $value);
$builder->setPackagesPath($this->getOption('packagesPath')); }
$builder->setPackagesPrefix($this->getOption('packagesPrefix')); }
$builder->setSuffix($this->getOption('suffix'));
$schema = $this->buildSchema($schema, $format); $schema = $this->buildSchema($schema, $format);
@ -376,7 +375,7 @@ class Doctrine_Import_Schema
* @param string $array * @param string $array
* @return void * @return void
*/ */
protected function buildRelationships(&$array) protected function _buildRelationships(&$array)
{ {
foreach ($array as $name => $properties) { foreach ($array as $name => $properties) {
if ( ! isset($properties['relations'])) { if ( ! isset($properties['relations'])) {
@ -420,7 +419,7 @@ class Doctrine_Import_Schema
} }
// Now we fix all the relationships and auto-complete opposite ends of relationships // Now we fix all the relationships and auto-complete opposite ends of relationships
$this->fixRelationships(); $this->_fixRelationships();
} }
/** /**
@ -430,7 +429,7 @@ class Doctrine_Import_Schema
* *
* @return void * @return void
*/ */
protected function fixRelationships() protected function _fixRelationships()
{ {
foreach($this->_relations as $className => $relations) { foreach($this->_relations as $className => $relations) {
foreach ($relations AS $alias => $relation) { foreach ($relations AS $alias => $relation) {