Development

Changeset 5736

You must first sign up to be able to contribute.

Changeset 5736

Show
Ignore:
Timestamp:
10/29/07 09:48:15 (1 year ago)
Author:
kupokomapa
Message:

[sfPropelMigrationsLightPlugin] Made the plugin work with sfPropel13Plugin. Made the pake task accept the environment also as part of the application name as 'frontend:dev' so that it stays backward compatible.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelMigrationsLightPlugin/trunk/data/tasks/sfPakePropelMigrationsLight.php

    r5481 r5736  
    5151  } 
    5252 
    53   $app = $args[0]
     53  @list($app, $env) = explode(':', $args[0])
    5454 
    5555  if (!is_dir(sfConfig::get('sf_app_dir').DIRECTORY_SEPARATOR.$app)) 
     
    6161  define('SF_ROOT_DIR',    sfConfig::get('sf_root_dir')); 
    6262  define('SF_APP',         $app); 
    63   define('SF_ENVIRONMENT', 'cli'); 
     63  define('SF_ENVIRONMENT', ($env)?$env:'cli'); 
    6464  define('SF_DEBUG',       true); 
    6565 
  • plugins/sfPropelMigrationsLightPlugin/trunk/lib/sfMigration.class.php

    r5481 r5736  
    1818abstract class sfMigration 
    1919{ 
    20   private $dbConnection = null; 
    2120  private $migrator = null; 
    2221  private $migrationNumber = null; 
     
    3029  public function __construct(sfMigrator $migrator, $migrationNumber) 
    3130  { 
    32     $this->dbConnection = Propel::getConnection(); 
    3331    $this->migrator = $migrator; 
    3432    $this->migrationNumber = $migrationNumber; 
     
    5250  protected function getConnection() 
    5351  { 
    54     return $this->dbConnection
     52    return Propel::getConnection()
    5553  } 
    5654   
     
    8280  protected final function executeSQL($sql) 
    8381  { 
    84     return $this->getConnection()->executeUpdate($sql); 
     82    return sfMigrator::executeUpdate($sql); 
    8583  } 
    8684 
     
    9593  protected final function executeQuery($sql, $fetchmode = null) 
    9694  { 
    97     return $this->getConnection()->executeQuery($sql, $fetchmode); 
     95    return sfMigrator::executeQuery($sql, $fetchmode); 
    9896  } 
    9997 
     
    116114    } 
    117115 
    118     return $this->executeSQL($sql); 
     116    return sfMigrator::executeSQL($sql); 
    119117  } 
    120118 
  • plugins/sfPropelMigrationsLightPlugin/trunk/lib/sfMigrator.class.php

    r5481 r5736  
    119119  protected function setCurrentVersion($version) 
    120120  { 
    121     $conn = Propel::getConnection(); 
    122  
    123121    $version = (int)$version; 
    124122 
    125     $conn->executeUpdate("UPDATE schema_info SET version = $version"); 
     123    self::executeUpdate("UPDATE schema_info SET version = $version"); 
    126124  } 
    127125 
     
    141139    for ($i = $from; $i > $to; $i--) 
    142140    { 
    143       $con->begin(); 
     141      if ($con instanceof PropelPDO) { 
     142        $con->beginTransaction(); 
     143      } else { 
     144        $con->begin(); 
     145      } 
    144146      try 
    145147      { 
     
    174176    $con = Propel::getConnection(); 
    175177    $counter = 0; 
    176      
     178 
    177179    // iterate over all needed migrations 
    178180    for ($i = $from + 1; $i <= $to; $i++) 
    179181    { 
    180       $con->begin(); 
     182      if ($con instanceof PropelPDO) { 
     183        $con->beginTransaction(); 
     184      } else { 
     185        $con->begin(); 
     186      } 
    181187      try 
    182188      { 
     
    304310  public function getCurrentVersion()  
    305311  { 
    306     $conn = Propel::getConnection(); 
    307      
    308312    // check if schema_info table exists 
    309     $rs = $conn->executeQuery("SHOW TABLES LIKE 'schema_info'"); 
    310     if ($rs->getRecordCount() == 1) 
    311     { 
    312       $rs = $conn->executeQuery("SELECT version FROM schema_info"); 
    313        
    314       if ($rs->next()) 
    315       { 
    316         $currentVersion = $rs->getInt("version"); 
    317       } 
    318       else 
    319       { 
    320         throw new sfDatabaseException("unable to retrieve current schema version"); 
     313    $result = self::executeQuery("SHOW TABLES LIKE 'schema_info'"); 
     314    if ($result instanceof PDOStatement) { 
     315      $exists = ($result->rowCount() == 1); 
     316    } else { 
     317      $exists = ($rs->getRecordCount() == 1); 
     318    } 
     319     
     320    if ($exists) 
     321    { 
     322      $result = self::executeQuery("SELECT version FROM schema_info"); 
     323 
     324      if ($result instanceof PDOStatement)  
     325      { 
     326        $currentVersion = $result->fetchColumn(0); 
     327      }  
     328      else  
     329      { 
     330        if ($rs->next()) 
     331        { 
     332          $currentVersion = $rs->getInt("version"); 
     333        } 
     334        else 
     335        { 
     336          throw new sfDatabaseException("unable to retrieve current schema version"); 
     337        } 
    321338      } 
    322339    } 
     
    325342      // no schema_info table exists yet 
    326343      // so we create it 
    327       $conn->executeUpdate("CREATE TABLE schema_info (version INTEGER UNSIGNED)"); 
     344      self::executeUpdate("CREATE TABLE schema_info (version INTEGER UNSIGNED)"); 
    328345      // and insert the version record 
    329346      // if no schema_info existed before, we'll call that version 0 
    330       $conn->executeUpdate("INSERT INTO schema_info SET version = 0"); 
     347      self::executeUpdate("INSERT INTO schema_info SET version = 0"); 
    331348      $currentVersion = 0; 
    332349    } 
     
    342359  public function getMigrationNumberFromFile($file)  
    343360  { 
     361    $matches = array(); 
    344362    $match_count = preg_match('#'.preg_quote(DIRECTORY_SEPARATOR, '#').'(\d{3}).*\.php$#', $file, $matches); 
    345363    $number = $matches[1]; 
     
    361379    return $this->getMigrationsDir().DIRECTORY_SEPARATOR.'fixtures'; 
    362380  } 
     381   
     382  public static function executeUpdate($sql) 
     383  { 
     384    $connection = Propel::getConnection(); 
     385     
     386    if (version_compare(Propel::VERSION, "1.3.x", ">=")) { 
     387      return $connection->exec($sql); 
     388    } else { 
     389      return $connection->executeUpdate($sql); 
     390    } 
     391  } 
     392   
     393  public static function executeQuery($sql, $fetchmode = null) 
     394  { 
     395    $connection = Propel::getConnection(); 
     396     
     397    if (version_compare(Propel::VERSION, "1.3.x", ">="))  
     398    { 
     399      $stmt = $connection->prepare($sql); 
     400      $stmt->execute(); 
     401       
     402      return $stmt; 
     403    } 
     404    else  
     405    { 
     406      return $connection->executeQuery($sql, $fetchmode); 
     407    } 
     408  } 
    363409}