| @@ 245-284 (lines=40) @@ | ||
| 242 | $previous = FALSE; |
|
| 243 | ||
| 244 | // Validate all available migrations, and run the ones within our target range |
|
| 245 | foreach ($migrations as $number => $file) |
|
| 246 | { |
|
| 247 | // Check for sequence gaps |
|
| 248 | if ($this->_migration_type === 'sequential' && $previous !== FALSE && abs($number - $previous) > 1) |
|
| 249 | { |
|
| 250 | $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); |
|
| 251 | return FALSE; |
|
| 252 | } |
|
| 253 | ||
| 254 | include_once($file); |
|
| 255 | $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); |
|
| 256 | ||
| 257 | // Validate the migration file structure |
|
| 258 | if ( ! class_exists($class, FALSE)) |
|
| 259 | { |
|
| 260 | $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); |
|
| 261 | return FALSE; |
|
| 262 | } |
|
| 263 | ||
| 264 | $previous = $number; |
|
| 265 | ||
| 266 | // Run migrations that are inside the target range |
|
| 267 | if ( |
|
| 268 | ($method === 'up' && $number > $current_version && $number <= $target_version) OR |
|
| 269 | ($method === 'down' && $number <= $current_version && $number > $target_version) |
|
| 270 | ) |
|
| 271 | { |
|
| 272 | $instance = new $class(); |
|
| 273 | if ( ! is_callable(array($instance, $method))) |
|
| 274 | { |
|
| 275 | $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); |
|
| 276 | return FALSE; |
|
| 277 | } |
|
| 278 | ||
| 279 | log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number); |
|
| 280 | call_user_func(array($instance, $method)); |
|
| 281 | $current_version = $number; |
|
| 282 | $this->_update_version($type, $current_version); |
|
| 283 | } |
|
| 284 | } |
|
| 285 | ||
| 286 | // This is necessary when moving down, since the the last migration applied |
|
| 287 | // will be the down() method for the next migration up from the target |
|
| @@ 238-277 (lines=40) @@ | ||
| 235 | $previous = FALSE; |
|
| 236 | ||
| 237 | // Validate all available migrations, and run the ones within our target range |
|
| 238 | foreach ($migrations as $number => $file) |
|
| 239 | { |
|
| 240 | // Check for sequence gaps |
|
| 241 | if ($this->_migration_type === 'sequential' && $previous !== FALSE && abs($number - $previous) > 1) |
|
| 242 | { |
|
| 243 | $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); |
|
| 244 | return FALSE; |
|
| 245 | } |
|
| 246 | ||
| 247 | include_once($file); |
|
| 248 | $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); |
|
| 249 | ||
| 250 | // Validate the migration file structure |
|
| 251 | if ( ! class_exists($class, FALSE)) |
|
| 252 | { |
|
| 253 | $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); |
|
| 254 | return FALSE; |
|
| 255 | } |
|
| 256 | ||
| 257 | $previous = $number; |
|
| 258 | ||
| 259 | // Run migrations that are inside the target range |
|
| 260 | if ( |
|
| 261 | ($method === 'up' && $number > $current_version && $number <= $target_version) OR |
|
| 262 | ($method === 'down' && $number <= $current_version && $number > $target_version) |
|
| 263 | ) |
|
| 264 | { |
|
| 265 | $instance = new $class(); |
|
| 266 | if ( ! is_callable(array($instance, $method))) |
|
| 267 | { |
|
| 268 | $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); |
|
| 269 | return FALSE; |
|
| 270 | } |
|
| 271 | ||
| 272 | log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number); |
|
| 273 | call_user_func(array($instance, $method)); |
|
| 274 | $current_version = $number; |
|
| 275 | $this->_update_version($current_version); |
|
| 276 | } |
|
| 277 | } |
|
| 278 | ||
| 279 | // This is necessary when moving down, since the the last migration applied |
|
| 280 | // will be the down() method for the next migration up from the target |
|