Add delete and purge Command

This commit is contained in:
Tim
2022-09-28 13:18:17 +02:00
parent 7a4cc21f8e
commit af30297d74
5 changed files with 98 additions and 6 deletions

View File

@ -17,8 +17,7 @@ class BackupDatabase extends Command
protected static $defaultName = 'db:backup';
public function __construct(
private DatabaseService $db,
private BackupService $bs,
private readonly BackupService $bs,
)
{
parent::__construct();

View File

@ -0,0 +1,39 @@
<?php
namespace App\Console;
use App\Service\DatabaseService;
use App\Service\Traits\SelectDatabaseQuestion;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DeleteDatabaseCommand extends Command
{
use SelectDatabaseQuestion;
protected static $defaultName = 'db:delete';
public function __construct(
private DatabaseService $db,
)
{
parent::__construct();
}
protected function configure(): void
{
$this->addArgument('name', InputArgument::OPTIONAL, 'Database name');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$db = $this->getDatabaseName($input, $output);
$this->db->deleteDatabase($db);
$output->writeln(sprintf('Database deleted: %s', $db));
return Command::SUCCESS;
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace App\Console;
use App\Service\DatabaseService;
use App\Service\Traits\SelectDatabaseQuestion;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class PurgeDatabaseCommand extends Command
{
use SelectDatabaseQuestion;
protected static $defaultName = 'db:purge';
public function __construct(
private DatabaseService $db,
)
{
parent::__construct();
}
protected function configure(): void
{
$this->addArgument('name', InputArgument::OPTIONAL, 'Database name');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$db = $this->getDatabaseName($input, $output);
$this->db->purgeDatabase($db);
$output->writeln(sprintf('Database purged: %s', $db));
return Command::SUCCESS;
}
}