<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use LaravelZero\Framework\Commands\Command;
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
use App\Facades\Install;
|
|
|
|
use Hackzilla\PasswordGenerator\Generator\ComputerPasswordGenerator;
|
|
use Hackzilla\PasswordGenerator\RandomGenerator\Php7RandomGenerator;
|
|
|
|
/**
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
class MariadbRemoveCommand extends Command
|
|
{
|
|
/**
|
|
* The signature of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'mariadb:remove {database}';
|
|
|
|
/**
|
|
* The description of the command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Remove Mariadb Database and User';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->info('Mariadb Remove Database...');
|
|
|
|
// getting root password
|
|
$password = $this->secret('Enter root password');
|
|
|
|
// connect database
|
|
try {
|
|
$mysqli = new \mysqli('127.0.0.1', 'root', $password);
|
|
} catch(\ErrorException $exception) {
|
|
$this->error('Failed! '.$exception->getMessage());
|
|
exit();
|
|
}
|
|
|
|
$database = $this->argument('database');
|
|
|
|
// check for user of database
|
|
$result = $mysqli->query("SELECT User FROM mysql.db WHERE Db = '$database'");
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
// get user from row
|
|
$user = $row['User'];
|
|
|
|
// remove if exists
|
|
$mysqli->query("DROP USER IF EXISTS $user@localhost");
|
|
$mysqli->query("DROP USER IS EXISTS $user@'%'");
|
|
}
|
|
|
|
// drop database
|
|
$mysqli->query("DROP DATABASE IF EXISTS $database");
|
|
$mysqli->close();
|
|
|
|
$this->info('Success! \o/ ');
|
|
}
|
|
}
|