Skip to content

Commit

Permalink
Fix ngsite:database:dump command
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed May 26, 2023
1 parent 19cb360 commit ceb95ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions bundle/Command/DumpDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Netgen\Bundle\SiteBundle\Command;

use Doctrine\DBAL\Connection;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;

Expand All @@ -22,7 +22,7 @@

final class DumpDatabaseCommand extends Command
{
public function __construct(private ContainerInterface $container)
public function __construct(private Connection $connection)
{
// Parent constructor call is mandatory for commands registered as services
parent::__construct();
Expand All @@ -40,11 +40,6 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$databaseName = $this->container->getParameter('database_name');
$databaseHost = $this->container->getParameter('database_host');
$databaseUser = $this->container->getParameter('database_user');
$databasePassword = $this->container->getParameter('database_password');

$filePath = getcwd() . DIRECTORY_SEPARATOR . trim($input->getArgument('file'), '/');
$targetDirectory = dirname($filePath);
$fileName = basename($filePath);
Expand All @@ -54,26 +49,28 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$fs->mkdir($targetDirectory);
}

$params = $this->connection->getParams();

// https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_opt
// https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_quick
// https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction
$process = new Process(
[
'mysqldump',
'-u',
$databaseUser,
$params['user'],
'-h',
$databaseHost,
$params['host'],
'--opt',
'--quick',
'--single-transaction',
'-r',
$targetDirectory . '/' . $fileName,
$databaseName,
$params['dbname'],
],
null,
[
'MYSQL_PWD' => $databasePassword,
'MYSQL_PWD' => $params['password'],
],
null,
null,
Expand Down
2 changes: 1 addition & 1 deletion bundle/Resources/config/services/commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
ngsite.command.dump_database:
class: Netgen\Bundle\SiteBundle\Command\DumpDatabaseCommand
arguments:
- "@service_container"
- "@ibexa.persistence.connection"
tags:
- { name: console.command, command: 'ngsite:database:dump' }

Expand Down

0 comments on commit ceb95ed

Please sign in to comment.