Created
September 12, 2012 23:45
-
-
Save danramosd/3710821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is the command line script that deals with running the migrations | |
* | |
*/ | |
if( !isset($argv[1]) ){ | |
echo "Hi, seems you forgot to pass me a parameter. Why dont you try one of the following: create : up : down. \n"; | |
} | |
else{ | |
switch($argv[1]){ | |
case "create": | |
if( !isset($argv[2])){ | |
echo "Please supply a name for the migration class. \n"; | |
} | |
else{ | |
$classScaffold = | |
'<?php | |
require_once("MigrationScaffold.php"); | |
class '.$argv[2].' extends MigrationScaffold{ | |
public function up(){ | |
$sql = ""; | |
$this->run($sql); | |
} | |
public function down(){ | |
$sql = ""; | |
$this->run($sql); | |
} | |
} | |
?>'; | |
$file = time()."_".$argv[2].'.php'; | |
file_put_contents($file, $classScaffold); | |
}//end:else | |
break; | |
case "run": | |
if( !isset($argv[2])){ | |
echo "Please supply the migration ID and method you want to run. i.e. 1347483788:up or 1347483788:down. \n"; | |
} | |
else{ | |
$IDMethod = explode(':',$argv[2]); | |
$ID = $IDMethod[0]; | |
$method = $IDMethod[1]; | |
$migrationFile; | |
if ($handle = opendir('.')) { | |
while (false !== ($entry = readdir($handle))) { | |
if (substr_count($entry, $ID)) { | |
$migrationFile = $entry; | |
} | |
}//end:while | |
closedir($handle); | |
}//end:if | |
require_once($migrationFile); | |
$className = substr(basename($migrationFile, '.php'),strpos(basename($migrationFile, '.php'), "_")+1); | |
$m = new $className; | |
$m->$method(); | |
}//end:else | |
break; | |
}//switch | |
}//end:if | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment