From a476c62efe748931820f059eff8f952621d5e31b Mon Sep 17 00:00:00 2001 From: "Jonathan.Wage" Date: Wed, 7 Nov 2007 01:57:01 +0000 Subject: [PATCH] Cleaned up some stuff with schema generation and removed name: key from column definition. --- lib/Doctrine/Export/Schema.php | 13 ++++++------- lib/Doctrine/Import/Schema.php | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/Doctrine/Export/Schema.php b/lib/Doctrine/Export/Schema.php index 6d6c0f70d..d31b42abe 100644 --- a/lib/Doctrine/Export/Schema.php +++ b/lib/Doctrine/Export/Schema.php @@ -59,22 +59,21 @@ class Doctrine_Export_Schema // we iterate trhough the diff of previously declared classes // and currently declared classes - foreach ($loadedModels as $name) { - if ( ! empty($models) && !in_array($name, $models)) { + foreach ($loadedModels as $className) { + if ( ! empty($models) && !in_array($className, $models)) { continue; } - $record = new $name(); + $record = new $className(); $recordTable = $record->getTable(); $data = $recordTable->getExportableFormat(); $table = array(); - $table['tableName'] = $data['tableName']; - $table['className'] = get_class($record); foreach ($data['columns'] AS $name => $column) { - $data['columns'][$name]['name'] = $name; + $data['columns'][$name]['type'] = $column['type'] . '(' . $column['length'] . ')'; + unset($data['columns'][$name]['length']); } $table['columns'] = $data['columns']; @@ -105,7 +104,7 @@ class Doctrine_Export_Schema } } - $array[$table['className']] = $table; + $array[$className] = $table; } return $array; diff --git a/lib/Doctrine/Import/Schema.php b/lib/Doctrine/Import/Schema.php index 2d32863f4..7a7d6a8e2 100644 --- a/lib/Doctrine/Import/Schema.php +++ b/lib/Doctrine/Import/Schema.php @@ -100,14 +100,14 @@ class Doctrine_Import_Schema public function buildSchema($schema, $format) { $array = array(); - + foreach ((array) $schema AS $s) { if (is_file($s)) { $array = array_merge($array, $this->parseSchema($s, $format)); } else if (is_dir($s)) { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($s), RecursiveIteratorIterator::LEAVES_ONLY); - + foreach ($it as $file) { $e = explode('.', $file->getFileName()); if (end($e) === $format) { @@ -116,9 +116,9 @@ class Doctrine_Import_Schema } } } - + $this->buildRelationships($array); - + return array('schema' => $array, 'relations' => $this->_relations); } @@ -218,15 +218,15 @@ class Doctrine_Import_Schema $exist_relations = array(); $unique_relations = array(); foreach ($all_relations as $relation) { - if (!in_array($relation['class'], $exist_relations)) { - $exist_relations[] = $relation['class']; - $unique_relations = array_merge($unique_relations, array($relation['alias'] => $relation)); - } else { - // check to see if this relationship is not autogenerated, if it's not, then the user must have explicitly declared it - if (!isset($relation['autogenerated']) || $relation['autogenerated'] != true) { - $unique_relations = array_merge($unique_relations, array($relation['alias'] => $relation)); + if (!in_array($relation['class'], $exist_relations)) { + $exist_relations[] = $relation['class']; + $unique_relations = array_merge($unique_relations, array($relation['alias'] => $relation)); + } else { + // check to see if this relationship is not autogenerated, if it's not, then the user must have explicitly declared it + if (!isset($relation['autogenerated']) || $relation['autogenerated'] != true) { + $unique_relations = array_merge($unique_relations, array($relation['alias'] => $relation)); + } } - } } return $unique_relations; @@ -320,7 +320,7 @@ class Doctrine_Import_Schema if ( ! empty($columns)) { foreach ($columns as $columnName => $field) { $colDesc = array(); - $colDesc['name'] = isset($field['name']) ? (string) $field['name']:$columnName; + $colDesc['name'] = $columnName; $e = explode('(', $field['type']); if (isset($e[0]) && isset($e[1])) {