Changeset 4317

Show
Ignore:
Timestamp:
04/30/08 20:02:20 (14 months ago)
Author:
jwage
Message:

Added attribute for singularizing when importing from existing databases. On by default but can be turned off at the manager or connection level.

Location:
branches/0.11
Files:
5 modified

Legend:

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

    r4306 r4317  
    195195    const ATTR_MODEL_LOADING            = 161; 
    196196    const ATTR_RECURSIVE_MERGE_FIXTURES = 162; 
     197    const ATTR_SINGULARIZE_IMPORT       = 163; 
    197198 
    198199    /** 
  • branches/0.11/lib/Doctrine/Configurable.php

    r4252 r4317  
    181181            case Doctrine::ATTR_QUERY_CACHE_LIFESPAN: 
    182182            case Doctrine::ATTR_RECURSIVE_MERGE_FIXTURES; 
     183            case Doctrine::ATTR_SINGULARIZE_IMPORT; 
    183184 
    184185                break; 
  • branches/0.11/lib/Doctrine/Connection.php

    r4296 r4317  
    263263    public function getAttribute($attribute) 
    264264    { 
     265        if (is_string($attribute)) { 
     266            $stringAttribute = $attribute; 
     267            $attribute = $this->getAttributeFromString($attribute); 
     268        } 
     269 
    265270        if ($attribute >= 100) { 
    266271            if ( ! isset($this->attributes[$attribute])) { 
  • branches/0.11/lib/Doctrine/Import.php

    r4257 r4317  
    340340    public function importSchema($directory, array $databases = array(), array $options = array()) 
    341341    { 
     342        $options['singularize'] = ! isset($options['singularize']) ?  
     343                $this->conn->getAttribute('singularize_import'):$options['singularize']; 
     344 
    342345        $connections = Doctrine_Manager::getInstance()->getConnections(); 
    343346 
  • branches/0.11/tests/ImportTestCase.php

    r4301 r4317  
    5252        Doctrine_Lib::removeDirectories('Import/_files'); 
    5353    } 
     54 
     55    public function testImportSingularizeOn() 
     56    { 
     57        $this->dbh = new PDO('sqlite::memory:'); 
     58 
     59        $this->dbh->exec('CREATE TABLE imports_tests_users (id INTEGER PRIMARY KEY, name TEXT)'); 
     60 
     61        $this->conn = Doctrine_Manager::connection($this->dbh, 'tmp1234'); 
     62        $this->conn->setAttribute(Doctrine::ATTR_SINGULARIZE_IMPORT, true); 
     63        $this->conn->import->importSchema('Import/_files', array('tmp1234')); 
     64 
     65        $this->assertTrue(file_exists('Import/_files/ImportTestUser.php')); 
     66        $this->assertTrue(file_exists('Import/_files/generated/BaseImportTestUser.php')); 
     67        Doctrine_Lib::removeDirectories('Import/_files'); 
     68    } 
     69 
     70    public function testImportSingularizeOff() 
     71    { 
     72        $this->dbh = new PDO('sqlite::memory:'); 
     73 
     74        $this->dbh->exec('CREATE TABLE imports_tests_users (id INTEGER PRIMARY KEY, name TEXT)'); 
     75 
     76        $this->conn = Doctrine_Manager::connection($this->dbh, 'tmp1235'); 
     77        $this->conn->setAttribute(Doctrine::ATTR_SINGULARIZE_IMPORT, false); 
     78        $this->conn->import->importSchema('Import/_files', array('tmp1235')); 
     79 
     80        $this->assertTrue(file_exists('Import/_files/ImportsTestsUsers.php')); 
     81        $this->assertTrue(file_exists('Import/_files/generated/BaseImportsTestsUsers.php')); 
     82        Doctrine_Lib::removeDirectories('Import/_files'); 
     83    } 
    5484}