Changeset 3936
- Timestamp:
- 03/06/08 06:21:55 (16 months ago)
- Location:
- branches/0.10/lib
- Files:
-
- 3 modified
-
Doctrine.php (modified) (3 diffs)
-
Doctrine/Export/Schema.php (modified) (2 diffs)
-
Doctrine/Import/Builder.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.10/lib/Doctrine.php
r3918 r3936 536 536 * 537 537 * @param string $directory Path to directory of models or array of directory paths 538 * @param integer $ forceStylePass value of Doctrine::ATTR_MODEL_LOADING to force a certain style of model loading538 * @param integer $modelLoading Pass value of Doctrine::ATTR_MODEL_LOADING to force a certain style of model loading 539 539 * Allowed Doctrine::MODEL_LOADING_AGGRESSIVE(default) or Doctrine::MODEL_LOADING_CONSERVATIVE 540 * @return array $modelLoading Array of the models loaded by the operation541 540 */ 542 541 public static function loadModels($directory, $modelLoading = null) … … 693 692 * @param string $directory Directory to write your models to 694 693 * @param array $databases Array of databases to generate models for 694 * @param array $options Array of options 695 695 * @return boolean 696 696 * @throws Exception 697 697 */ 698 public static function generateModelsFromDb($directory, array $databases = array() )699 { 700 return Doctrine_Manager::connection()->import->importSchema($directory, $databases );698 public static function generateModelsFromDb($directory, array $databases = array(), array $options = array()) 699 { 700 return Doctrine_Manager::connection()->import->importSchema($directory, $databases, $options); 701 701 } 702 702 … … 708 708 * 709 709 * @param string $yamlPath Path to write oyur yaml schema file to 710 * @return void 711 */ 712 public static function generateYamlFromDb($yamlPath) 710 * @param array $options Array of options 711 * @return void 712 */ 713 public static function generateYamlFromDb($yamlPath, array $databases = array(), array $options = array()) 713 714 { 714 715 $directory = '/tmp/tmp_doctrine_models'; 715 716 716 Doctrine::generateModelsFromDb($directory); 717 $options['generateBaseClasses'] = isset($options['generateBaseClasses']) ? $options['generateBaseClasses']:false; 718 Doctrine::generateModelsFromDb($directory, $databases, $options); 717 719 718 720 $export = new Doctrine_Export_Schema(); -
branches/0.10/lib/Doctrine/Export/Schema.php
r3884 r3936 58 58 $fks = array(); 59 59 60 // we iterate t rhough the diff of previously declared classes60 // we iterate through the diff of previously declared classes 61 61 // and currently declared classes 62 62 foreach ($loadedModels as $className) { … … 70 70 71 71 $table = array(); 72 72 $remove = array('ptype', 'ntype', 'alltypes'); 73 // Fix explicit length in schema, concat it to type in this format: type(length) 73 74 foreach ($data['columns'] AS $name => $column) { 74 75 $data['columns'][$name]['type'] = $column['type'] . '(' . $column['length'] . ')'; 75 76 unset($data['columns'][$name]['length']); 77 78 // Strip out schema information which is not necessary to be dumped to the yaml schema file 79 foreach ($remove as $value) { 80 if (isset($data['columns'][$name][$value])) { 81 unset($data['columns'][$name][$value]); 82 } 83 } 84 85 // If type is the only property of the column then lets abbreviate the syntax 86 // columns: { name: string(255) } 87 if (count($data['columns'][$name]) === 1 && isset($data['columns'][$name]['type'])) { 88 $type = $data['columns'][$name]['type']; 89 unset($data['columns'][$name]); 90 $data['columns'][$name] = $type; 91 } 76 92 } 77 93 -
branches/0.10/lib/Doctrine/Import/Builder.php
r3891 r3936 471 471 } 472 472 473 // The column definition is one array, everthing but name, type and length are an array of 474 // possible options. This removes the name, type and length and creates the options array for 475 // the column definition 473 476 $options = $column; 474 $unset = array('name', 'type', 'length' , 'ptype');477 $unset = array('name', 'type', 'length'); 475 478 foreach ($options as $key => $value) { 476 if (in_array($key, $unset) || $value === null) {479 if (in_array($key, $unset) || empty($value)) { 477 480 unset($options[$key]); 478 481 } 479 482 } 480 483 484 // Unset notnull if the column is primary and if notnull === true 485 // It defaults to true so no need to have it in definition 486 if (isset($options['primary']) && $options['primary'] && isset($options['notnull']) && $options['notnull'] === true) { 487 unset($options['notnull']); 488 } 489 481 490 if (is_array($options) && !empty($options)) { 482 491 $build .= ', ' . $this->varExport($options); … … 716 725 public function buildRecord(array $definition) 717 726 { 718 if ( ! isset($definition['className'])) {727 if ( ! isset($definition['className'])) { 719 728 throw new Doctrine_Import_Builder_Exception('Missing class name.'); 720 729 }