Created
January 23, 2015 17:52
-
-
Save atrakeur/8aca9eb473853b206e33 to your computer and use it in GitHub Desktop.
Laravel database installation script
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 | |
use Symfony\Component\Console\Output\BufferedOutput; | |
class InstallController extends BaseController { | |
public function index($user, $pass) | |
{ | |
//check trivial pour éviter les reset intenpestifs | |
//a vous d'implemnter votre propre méthode de verrification | |
if ($user != "MonUser" || $pass != "MonPass") | |
{ | |
exit; | |
} | |
//redirige STDIN pour capturer la sortie de la commande | |
define('STDIN', fopen("php://stdin","r")); | |
$output = new BufferedOutput; | |
if (!Schema::hasTable('migrations')) | |
{ | |
Artisan::call('migrate:install', array(), $output); | |
} | |
//Met a jour les migrations, puis seed la base avec le jeu de départ | |
Artisan::call('migrate:refresh', array('--force' => 1), $output); | |
Artisan::call('db:seed', array('--force' => 1), $output); | |
$messages = explode("\n", trim($output->fetch())); | |
//affiche la sortie en json | |
echo json_encode(array('messages' => $messages)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment