Changeset 5736
- Timestamp:
- 10/29/07 09:48:15 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelMigrationsLightPlugin/trunk/data/tasks/sfPakePropelMigrationsLight.php
r5481 r5736 51 51 } 52 52 53 $app = $args[0];53 @list($app, $env) = explode(':', $args[0]); 54 54 55 55 if (!is_dir(sfConfig::get('sf_app_dir').DIRECTORY_SEPARATOR.$app)) … … 61 61 define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); 62 62 define('SF_APP', $app); 63 define('SF_ENVIRONMENT', 'cli');63 define('SF_ENVIRONMENT', ($env)?$env:'cli'); 64 64 define('SF_DEBUG', true); 65 65 plugins/sfPropelMigrationsLightPlugin/trunk/lib/sfMigration.class.php
r5481 r5736 18 18 abstract class sfMigration 19 19 { 20 private $dbConnection = null;21 20 private $migrator = null; 22 21 private $migrationNumber = null; … … 30 29 public function __construct(sfMigrator $migrator, $migrationNumber) 31 30 { 32 $this->dbConnection = Propel::getConnection();33 31 $this->migrator = $migrator; 34 32 $this->migrationNumber = $migrationNumber; … … 52 50 protected function getConnection() 53 51 { 54 return $this->dbConnection;52 return Propel::getConnection(); 55 53 } 56 54 … … 82 80 protected final function executeSQL($sql) 83 81 { 84 return $this->getConnection()->executeUpdate($sql);82 return sfMigrator::executeUpdate($sql); 85 83 } 86 84 … … 95 93 protected final function executeQuery($sql, $fetchmode = null) 96 94 { 97 return $this->getConnection()->executeQuery($sql, $fetchmode);95 return sfMigrator::executeQuery($sql, $fetchmode); 98 96 } 99 97 … … 116 114 } 117 115 118 return $this->executeSQL($sql);116 return sfMigrator::executeSQL($sql); 119 117 } 120 118 plugins/sfPropelMigrationsLightPlugin/trunk/lib/sfMigrator.class.php
r5481 r5736 119 119 protected function setCurrentVersion($version) 120 120 { 121 $conn = Propel::getConnection();122 123 121 $version = (int)$version; 124 122 125 $conn->executeUpdate("UPDATE schema_info SET version = $version");123 self::executeUpdate("UPDATE schema_info SET version = $version"); 126 124 } 127 125 … … 141 139 for ($i = $from; $i > $to; $i--) 142 140 { 143 $con->begin(); 141 if ($con instanceof PropelPDO) { 142 $con->beginTransaction(); 143 } else { 144 $con->begin(); 145 } 144 146 try 145 147 { … … 174 176 $con = Propel::getConnection(); 175 177 $counter = 0; 176 178 177 179 // iterate over all needed migrations 178 180 for ($i = $from + 1; $i <= $to; $i++) 179 181 { 180 $con->begin(); 182 if ($con instanceof PropelPDO) { 183 $con->beginTransaction(); 184 } else { 185 $con->begin(); 186 } 181 187 try 182 188 { … … 304 310 public function getCurrentVersion() 305 311 { 306 $conn = Propel::getConnection();307 308 312 // 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 } 321 338 } 322 339 } … … 325 342 // no schema_info table exists yet 326 343 // so we create it 327 $conn->executeUpdate("CREATE TABLE schema_info (version INTEGER UNSIGNED)");344 self::executeUpdate("CREATE TABLE schema_info (version INTEGER UNSIGNED)"); 328 345 // and insert the version record 329 346 // 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"); 331 348 $currentVersion = 0; 332 349 } … … 342 359 public function getMigrationNumberFromFile($file) 343 360 { 361 $matches = array(); 344 362 $match_count = preg_match('#'.preg_quote(DIRECTORY_SEPARATOR, '#').'(\d{3}).*\.php$#', $file, $matches); 345 363 $number = $matches[1]; … … 361 379 return $this->getMigrationsDir().DIRECTORY_SEPARATOR.'fixtures'; 362 380 } 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 } 363 409 }