Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a dry-run option #137

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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