Changeset 3936

Show
Ignore:
Timestamp:
03/06/08 06:21:55 (16 months ago)
Author:
jwage
Message:

fixes #829 fixes #707

Location:
branches/0.10/lib
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/0.10/lib/Doctrine.php

    r3918 r3936  
    536536     * 
    537537     * @param  string   $directory      Path to directory of models or array of directory paths 
    538      * @param  integer  $forceStyle     Pass value of Doctrine::ATTR_MODEL_LOADING to force a certain style of model loading 
     538     * @param  integer  $modelLoading   Pass value of Doctrine::ATTR_MODEL_LOADING to force a certain style of model loading 
    539539     *                                  Allowed Doctrine::MODEL_LOADING_AGGRESSIVE(default) or Doctrine::MODEL_LOADING_CONSERVATIVE 
    540      * @return array    $modelLoading   Array of the models loaded by the operation 
    541540     */ 
    542541    public static function loadModels($directory, $modelLoading = null) 
     
    693692     * @param string $directory Directory to write your models to 
    694693     * @param array $databases Array of databases to generate models for 
     694     * @param array $options Array of options 
    695695     * @return boolean 
    696696     * @throws Exception 
    697697     */ 
    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); 
    701701    } 
    702702 
     
    708708     * 
    709709     * @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()) 
    713714    { 
    714715        $directory = '/tmp/tmp_doctrine_models'; 
    715716 
    716         Doctrine::generateModelsFromDb($directory); 
     717        $options['generateBaseClasses'] = isset($options['generateBaseClasses']) ? $options['generateBaseClasses']:false; 
     718        Doctrine::generateModelsFromDb($directory, $databases, $options); 
    717719 
    718720        $export = new Doctrine_Export_Schema(); 
  • branches/0.10/lib/Doctrine/Export/Schema.php

    r3884 r3936  
    5858        $fks = array(); 
    5959 
    60         // we iterate trhough the diff of previously declared classes 
     60        // we iterate through the diff of previously declared classes 
    6161        // and currently declared classes 
    6262        foreach ($loadedModels as $className) { 
     
    7070             
    7171            $table = array(); 
    72              
     72            $remove = array('ptype', 'ntype', 'alltypes'); 
     73            // Fix explicit length in schema, concat it to type in this format: type(length) 
    7374            foreach ($data['columns'] AS $name => $column) { 
    7475                $data['columns'][$name]['type'] = $column['type'] . '(' . $column['length'] . ')'; 
    7576                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                } 
    7692            } 
    7793             
  • branches/0.10/lib/Doctrine/Import/Builder.php

    r3891 r3936  
    471471            } 
    472472 
     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 
    473476            $options = $column; 
    474             $unset = array('name', 'type', 'length', 'ptype'); 
     477            $unset = array('name', 'type', 'length'); 
    475478            foreach ($options as $key => $value) { 
    476                 if (in_array($key, $unset) || $value === null) { 
     479                if (in_array($key, $unset) || empty($value)) { 
    477480                    unset($options[$key]); 
    478481                } 
    479482            } 
    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 
    481490            if (is_array($options) && !empty($options)) { 
    482491                $build .= ', ' . $this->varExport($options); 
     
    716725    public function buildRecord(array $definition) 
    717726    { 
    718         if ( !isset($definition['className'])) { 
     727        if ( ! isset($definition['className'])) { 
    719728            throw new Doctrine_Import_Builder_Exception('Missing class name.'); 
    720729        }