MadGenius88
1/23/2017 - 8:00 PM

MySQLdump.php

<?php
// Add to app/start/artisan.php
// Artisan::add(new MysqlDump);
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class MysqlDump extends Command {
	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'MysqlDump';
	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Create A MysqlDump SQL dump into the test database for acceptance testing in Codeception';
	/**
	 * Create a new command instance.
	 *
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();
	}
	/**
	 * Execute the console command.
	 *
	 * @return mixed
*/
    public function fire()
    {
        $host = Config::get('database.connections.mysql.host');
        $database = Config::get('database.connections.mysql.database');
        $username = Config::get('database.connections.mysql.username');
        $password = Config::get('database.connections.mysql.password');
        $backupPath = app_path() . '/tests/_data/dump.sql';
        // Sending some info to the console for really debugging purposes if needed.
        $this->info('MysqlDump of database: ' . $database . ' - Export Started ...');
        $this->info('... Processing into ... ' . $backupPath);
        $this->info('We need your database password!');
        $path = "/usr/bin/mysqldump";
        $command = $path . " -u " . $username . " -p  " . $database . " > " . $backupPath;
        //$command = $path . " -u " . $username . " " . $database . " > " . $backupPath;
        system($command);
        $this->info('MysqlDump has been completed!');
    }
}