Changeset 7411

Show
Ignore:
Timestamp:
03/17/10 18:33:25 (4 months ago)
Author:
jwage
Message:

[2.0] Extracting Doctrine 1 schema conversion from orm:convert-mapping task to a orm:convert-d1-schema task

Location:
trunk/lib/Doctrine
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine/Common/Cli/CliController.php

    r7405 r7411  
    8383             ->addTask('run-dql', $ns . '\RunDqlTask') 
    8484             ->addTask('schema-tool', $ns . '\SchemaToolTask') 
    85              ->addTask('version', $ns . '\VersionTask'); 
     85             ->addTask('version', $ns . '\VersionTask') 
     86             ->addTask('convert-d1-schema', $ns . '\ConvertDoctrine1SchemaTask'); 
    8687 
    8788        $ns = 'Doctrine\DBAL\Tools\Cli\Tasks'; 
  • trunk/lib/Doctrine/ORM/Tools/Cli/Tasks/ConvertMappingTask.php

    r7404 r7411  
    130130        $from = (array) $arguments['from']; 
    131131 
    132         if ($this->_isDoctrine1Schema($from)) { 
    133             $printer->writeln('Converting Doctrine 1 schema to Doctrine 2 mapping files', 'INFO'); 
    134  
    135             $converter = new \Doctrine\ORM\Tools\ConvertDoctrine1Schema($from); 
    136             $metadatas = $converter->getMetadatasFromSchema(); 
    137         } else { 
    138             foreach ($from as $source) { 
    139                 $sourceArg = $source; 
    140                 $type = $this->_determineSourceType($sourceArg); 
    141                  
    142                 if ( ! $type) { 
    143                     throw new CliException( 
    144                         "Invalid mapping source type '$sourceArg'." 
    145                     ); 
    146                 } 
    147                  
    148                 $source = $this->_getSourceByType($type, $sourceArg); 
    149                  
    150                 $printer->writeln( 
    151                     sprintf( 
    152                         'Adding "%s" mapping source which contains the "%s" format',  
    153                         $printer->format($sourceArg, 'KEYWORD'), $printer->format($type, 'KEYWORD') 
    154                     ) 
     132        foreach ($from as $source) { 
     133            $sourceArg = $source; 
     134            $type = $this->_determineSourceType($sourceArg); 
     135             
     136            if ( ! $type) { 
     137                throw new CliException( 
     138                    "Invalid mapping source type '$sourceArg'." 
    155139                ); 
    156  
    157                 $cme->addMappingSource($source, $type); 
    158             } 
    159              
    160             $metadatas = $cme->getMetadatasForMappingSources(); 
    161         } 
     140            } 
     141             
     142            $source = $this->_getSourceByType($type, $sourceArg); 
     143             
     144            $printer->writeln( 
     145                sprintf( 
     146                    'Adding "%s" mapping source which contains the "%s" format',  
     147                    $printer->format($sourceArg, 'KEYWORD'), $printer->format($type, 'KEYWORD') 
     148                ) 
     149            ); 
     150 
     151            $cme->addMappingSource($source, $type); 
     152        } 
     153         
     154        $metadatas = $cme->getMetadatasForMappingSources(); 
    162155 
    163156        foreach ($metadatas as $metadata) { 
     
    177170        $exporter->setMetadatas($metadatas); 
    178171        $exporter->export(); 
    179     } 
    180  
    181     private function _isDoctrine1Schema(array $from) 
    182     { 
    183         $files = glob(current($from) . '/*.yml'); 
    184          
    185         if ($files) { 
    186             $array = \Symfony\Components\Yaml\Yaml::load($files[0]); 
    187             $first = current($array); 
    188              
    189             // We're dealing with a Doctrine 1 schema if you have 
    190             // a columns index in the first model array 
    191             return isset($first['columns']); 
    192         } else { 
    193             return false; 
    194         } 
    195172    } 
    196173