1
0
Fork 0
mirror of https://github.com/Oreolek/kohana-migrations.git synced 2024-06-26 03:40:54 +03:00

Moving logic for searching for available migrations into the model

Also added a method for getting the status of all locations, regaurdless of whether they're installed.
This commit is contained in:
Matt Button 2011-01-20 23:53:59 +00:00
parent 676f364ecd
commit f4538e6713
2 changed files with 37 additions and 20 deletions

View file

@ -209,7 +209,7 @@ class Minion_Migration_Manager {
// Get array of installed migrations with the id as key
$installed = $this->_model->fetch_all('id');
$available = $this->scan_for_migrations();
$available = $this->_model->available_migrations();
$all_migrations = array_keys($installed) + array_keys($available);
@ -242,25 +242,6 @@ class Minion_Migration_Manager {
return $this;
}
/**
* Scans all migration directories for available migration files
*
* Returns an array of
*
* migration_id => array(
* 'file' => migration_file,
* 'location' => migration_location
* );
*
* @param return array
*/
public function scan_for_migrations()
{
$files = Kohana::list_files('migrations');
return Minion_Migration_Util::compile_migrations_from_files($files);
}
/**
* Gets a database connection for running the migrations
*

View file

@ -28,6 +28,42 @@ class Model_Minion_Migration extends Model
$this->_db = $db;
}
/**
* Returns a list of migrations that are available in the filesystem
*
* @return array
*/
public function available_migrations()
{
$files = Kohana::list_files('migrations');
return Minion_Migration_Util::compile_migrations_from_files($files);
}
/**
* Gets the status of all locations, whether they're in the db or not.
*
* @return array
*/
public function get_location_statuses()
{
// Start out using all the installed locations
$locations = $this->fetch_current_versions('location', 'id');
$available = $this->available_migrations();
foreach($available as $migration)
{
if(array_key_exists($migration['id'], $locations))
{
continue;
}
$locations[$migration['location']] = NULL;
}
return $locations;
}
/**
* Get or Set the table to use to store migrations
*