Show
Ignore:
Timestamp:
10/20/07 20:14:30 (15 months ago)
Author:
jwage
Message:

Enhancing CLI. New commands and cleaning up.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine.php

    r2943 r2951  
    735735     * @return void 
    736736     */ 
    737     public static function createDatabases($specifiedConnections) 
     737    public static function createDatabases($specifiedConnections = array()) 
    738738    { 
    739739        if (!is_array($specifiedConnections)) { 
     
    741741        } 
    742742         
    743         $connections = Doctrine_Manager::getInstance()->getConnections(); 
     743        $manager = Doctrine_Manager::getInstance(); 
     744        $connections = $manager->getConnections(); 
    744745         
    745746        foreach ($connections as $name => $connection) { 
     
    748749            } 
    749750             
    750             $connection->export->createDatabase($name); 
     751            $info = $manager->parsePdoDsn($connection->getOption('dsn')); 
     752            $username = $connection->getOption('username'); 
     753            $password = $connection->getOption('password'); 
     754             
     755            // Make connection without database specified so we can create it 
     756            $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false); 
     757             
     758            try { 
     759                // Create database 
     760                $connect->export->createDatabase($name); 
     761                 
     762                // Close the tmp connection with no database 
     763                $manager->closeConnection($connect); 
     764                 
     765                // Close original connection 
     766                $manager->closeConnection($connection); 
     767                 
     768                // Reopen original connection with newly created database 
     769                $manager->openConnection(new PDO($info['dsn'], $username, $password), $name, true); 
     770            } catch (Exception $e) { 
     771                 
     772            } 
    751773        } 
    752774    } 
     
    766788        } 
    767789         
    768         $connections = Doctrine_Manager::getInstance()->getConnections(); 
     790        $manager = Doctrine_Manager::getInstance(); 
     791         
     792        $connections = $manager->getConnections(); 
    769793         
    770794        foreach ($connections as $name => $connection) { 
     
    773797            } 
    774798             
    775             $connection->export->dropDatabase($name); 
     799            try { 
     800                $connection->export->dropDatabase($name); 
     801            } catch (Exception $e) { 
     802                 
     803            } 
    776804        } 
    777805    }