Changeset 3847

Show
Ignore:
Timestamp:
02/19/08 23:30:54 (17 months ago)
Author:
jwage
Message:

Fixes to model loading across the board. Breakage occurred after conservative model loading was fixed to actually be conservative.

Location:
branches/0.10
Files:
7 modified

Legend:

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

    r3834 r3847  
    566566                            if ($foundClasses) { 
    567567                                foreach ($foundClasses as $className) { 
    568                                     if (self::isValidModelClass($className) && !in_array($className, $loadedModels)) { 
     568                                    if (self::isValidModelClass($className)) { 
    569569                                        $loadedModels[] = $className; 
    570570 
     571                                        self::$_loadedModelFiles[$className] = $file->getPathName(); 
    571572                                        self::$_pathModels[$file->getPathName()][$className] = $className; 
    572573                                    } 
     
    579580        } 
    580581 
    581         // We do not want to filter invalid models when using conservative model loading 
    582         // The filtering requires that the class be loaded and inflected in order to determine if it is  
    583         // a valid class. 
    584         if ($manager->getAttribute(Doctrine::ATTR_MODEL_LOADING) == Doctrine::MODEL_LOADING_CONSERVATIVE) { 
    585             return $loadedModels; 
    586         } else { 
    587             return self::filterInvalidModels($loadedModels); 
    588         } 
     582        return $loadedModels; 
    589583    } 
    590584 
  • branches/0.10/lib/Doctrine/Export.php

    r3844 r3847  
    10421042    { 
    10431043        if ($directory !== null) { 
    1044             $models = Doctrine::loadModels($directory); 
     1044            $models = Doctrine::filterInvalidModels(Doctrine::loadModels($directory)); 
    10451045        } else { 
    10461046            $models = Doctrine::getLoadedModels(); 
    10471047        } 
    1048          
     1048 
    10491049        $this->exportClasses($models); 
    10501050    } 
     
    10601060     */ 
    10611061     public function exportClasses(array $classes) 
    1062      {  
     1062     { 
    10631063         $connections = array(); 
    10641064         foreach ($classes as $class) { 
    1065              $record = new $class(); 
    1066              $connection = $record->getTable()->getConnection(); 
    1067              $connectionName = Doctrine_Manager::getInstance()->getConnectionName($connection); 
     1065             $connection = Doctrine_Manager::getInstance()->getConnectionForComponent($class); 
     1066             $connectionName = $connection->getName(); 
    10681067 
    10691068             if ( ! isset($connections[$connectionName])) { 
     
    12461245    { 
    12471246        if ($directory !== null) { 
    1248             $models = Doctrine::loadModels($directory); 
     1247            $models = Doctrine::filterInvalidModels(Doctrine::loadModels($directory)); 
    12491248        } else { 
    12501249            $models = Doctrine::getLoadedModels(); 
  • branches/0.10/lib/Doctrine/Export/Schema.php

    r3844 r3847  
    4545    public function buildSchema($directory = null, $models = array()) 
    4646    { 
    47         if ($directory) { 
    48             $loadedModels = Doctrine::loadModels($directory); 
     47        if ($directory !== null) { 
     48            $loadedModels = Doctrine::filterInvalidModels(Doctrine::loadModels($directory)); 
    4949        } else { 
    5050            $loadedModels = Doctrine::getLoadedModels(); 
    5151        } 
    52  
     52         
    5353        $array = array(); 
    5454         
     
    6565            } 
    6666 
    67             $record = new $className(); 
    68             $recordTable  = $record->getTable(); 
     67            $recordTable = Doctrine::getTable($className); 
    6968             
    7069            $data = $recordTable->getExportableFormat(); 
  • branches/0.10/lib/Doctrine/Migration.php

    r3820 r3847  
    123123     * @return void 
    124124     */ 
    125     public function loadMigrationClassesFromDirectory($classes){ 
     125    public function loadMigrationClassesFromDirectory() 
     126    { 
     127        $classes = get_declared_classes(); 
     128         
    126129        foreach ((array) $this->_migrationClassesDirectory as $dir) { 
    127130            $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), 
     
    155158    protected function loadMigrationClasses() 
    156159    { 
    157         if ($this->_migrationClasses) { 
    158             return $this->_migrationClasses; 
    159         } 
    160          
    161         $classes = get_declared_classes(); 
    162          
    163160        if ($this->_migrationClassesDirectory !== null) { 
    164             $this->loadMigrationClassesFromDirectory($classes); 
    165         } 
    166  
     161            $this->loadMigrationClassesFromDirectory(); 
     162        } 
    167163         
    168164        $parent = new ReflectionClass('Doctrine_Migration'); 
  • branches/0.10/lib/Doctrine/Migration/Builder.php

    r3844 r3847  
    156156    public function generateMigrationsFromModels($modelsPath = null) 
    157157    { 
    158         if ($modelsPath) { 
    159             $models = Doctrine::loadModels($modelsPath); 
     158        if ($modelsPath !== null) { 
     159            $models = Doctrine::filterInvalidModels(Doctrine::loadModels($modelsPath)); 
    160160        } else { 
    161161            $models = Doctrine::getLoadedModels(); 
     
    173173             
    174174            $className = 'Add' . Doctrine::classify($export['tableName']); 
    175              
     175 
    176176            $this->generateMigrationClass($className, array(), $up, $down); 
    177177        } 
    178178         
    179         $className = 'ApplyForeignKeyConstraints'; 
    180          
    181         $up = ''; 
    182         $down = ''; 
    183         foreach ($foreignKeys as $tableName => $definitions)    { 
    184             $tableForeignKeyNames[$tableName] = array(); 
    185              
    186             foreach ($definitions as $definition) { 
    187                 $definition['name'] = $tableName . '_' . $definition['foreignTable'] . '_' . $definition['local'] . '_' . $definition['foreign']; 
     179        if ( ! empty($foreignKeys)) { 
     180            $className = 'ApplyForeignKeyConstraints'; 
     181         
     182            $up = ''; 
     183            $down = ''; 
     184            foreach ($foreignKeys as $tableName => $definitions)    { 
     185                $tableForeignKeyNames[$tableName] = array(); 
     186             
     187                foreach ($definitions as $definition) { 
     188                    $definition['name'] = $tableName . '_' . $definition['foreignTable'] . '_' . $definition['local'] . '_' . $definition['foreign']; 
    188189                 
    189                 $up .= $this->buildCreateForeignKey($tableName, $definition); 
    190                 $down .= $this->buildDropForeignKey($tableName, $definition); 
     190                    $up .= $this->buildCreateForeignKey($tableName, $definition); 
     191                    $down .= $this->buildDropForeignKey($tableName, $definition); 
     192                } 
    191193            } 
    192         } 
    193          
    194         $this->generateMigrationClass($className, array(), $up, $down); 
     194         
     195            $this->generateMigrationClass($className, array(), $up, $down); 
     196        } 
    195197         
    196198        return true; 
     
    274276            $path = $this->getMigrationsPath() . DIRECTORY_SEPARATOR . $fileName; 
    275277             
     278            if ( class_exists($className)) { 
     279                throw new Doctrine_Exception('Migration class with the name "' . $className . '" already exists.'); 
     280            } 
     281             
    276282            file_put_contents($path, $class); 
    277283        } 
  • branches/0.10/tools/sandbox/config.php.dist

    r3797 r3847  
    5252 
    5353Doctrine_Manager::getInstance()->setAttribute('model_loading', 'conservative'); 
    54  
    55 Doctrine::loadModels('models'); 
  • branches/0.10/tools/sandbox/index.php.dist

    r2859 r3847  
    11<?php 
    22require_once('config.php'); 
     3 
     4Doctrine::loadModels('models');