Skip to content

Instantly share code, notes, and snippets.

@ruthlessfish
Created August 30, 2011 04:55
Show Gist options
  • Save ruthlessfish/1180214 to your computer and use it in GitHub Desktop.
Save ruthlessfish/1180214 to your computer and use it in GitHub Desktop.
sample migration controller (CLI)
<?php
/**
* Sample Usage:
*
* $php index.php migrate version 5
* $php index.php migrate latest
* $php index.php migrate current
*
*/
class Migrate extends CI_Controller
{
public function _remap($method, $args)
{
$this->load->library(array('cli', 'migration'));
// only allow version, latest and current to be called
// directly from the shell
switch($method)
{
case 'version' :
$args[0] OR
$args[0] = $this->config->item('migrations_version');
break;
case 'latest' :
case 'current' :
break;
default :
$this->cli->write('Command not found.');
exit;
break;
}
if( ! call_user_func_array(array($this->migration, $method), $args))
{
$this->cli->write($this->migration->error_string());
exit;
}
$this->cli->write('Migration Successful', 'green');
}
} // end class Migrate
/* End of file migrate.php */
/* Location: ./application/controllers/migrate.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment