Skip to content

Commit

Permalink
Add a dry-run option
Browse files Browse the repository at this point in the history
  • Loading branch information
guvra committed Jun 6, 2024
1 parent c24c750 commit dd263a3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/Console/Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function configure(): void
->addOption('port', null, InputOption::VALUE_REQUIRED, 'Database port' . $configHint)
->addOption('user', null, InputOption::VALUE_REQUIRED, 'Database user' . $configHint)
->addOption('password', null, InputOption::VALUE_REQUIRED, 'Database password' . $configHint)
->addOption('database', null, InputOption::VALUE_REQUIRED, 'Database name' . $configHint);
->addOption('database', null, InputOption::VALUE_REQUIRED, 'Database name' . $configHint)
->addOption('dry-run', null, InputOption::VALUE_NONE, 'The command will validate the configuration file, but won\'t actually perform the dump');
// phpcs:enable Generic.Files.LineLength.TooLong
}

Expand Down Expand Up @@ -94,7 +95,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$this->dumpInfo->setOutput($output);
}

$this->dumper->dump($config);
$this->dumper->dump($config, $input->getOption('dry-run'));
} catch (Exception $e) {
if ($output->isVerbose()) {
throw $e;
Expand Down
2 changes: 1 addition & 1 deletion src/Dumper/DumperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface DumperInterface
/**
* Create a dump according to the configuration.
*/
public function dump(ConfigInterface $config): void;
public function dump(ConfigInterface $config, bool $dryRun = false): void;
}
10 changes: 6 additions & 4 deletions src/Dumper/MysqlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
/**
* @inheritdoc
*/
public function dump(ConfigInterface $config): void
public function dump(ConfigInterface $config, bool $dryRun = false): void
{
$database = $this->databaseFactory->create($config);

Expand Down Expand Up @@ -57,9 +57,11 @@ public function dump(ConfigInterface $config): void
// Close the Doctrine connection before proceeding to the dump creation (MySQLDump-PHP uses its own connection)
$database->getConnection()->close();

// Create the dump
$output = $config->getDumpOutput();
$dumper->start($output);
if (!$dryRun) {
// Create the dump
$dumper->start($config->getDumpOutput());
}

$this->eventDispatcher->dispatch(new DumpFinishedEvent($config));
}

Expand Down

0 comments on commit dd263a3

Please sign in to comment.