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 --skip-* options to lower flags #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
51 changes: 36 additions & 15 deletions src/Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@

class DumpCommand extends Command
{
// Options that can be negated through skip-[option], allows to have
// defaults to true with explicit disablement.
private static $skipable_options = [
'add-drop-table',
'add-locks',
'disable-keys',
'extended-insert',
'lock-tables',
'quote-names',
'opt'
];

protected function configure()
{
Expand Down Expand Up @@ -70,9 +81,9 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
'Default charset. Defaults to utf8mb4.', 'utf8mb4')
->addOption('disable-keys', null, InputOption::VALUE_NONE,
'Adds disable-keys statements for faster dump execution. Defaults to on, use no-disable-keys to switch off.')
'Adds disable-keys statements for faster dump execution. Defaults to on, use skip-disable-keys to switch off.')
->addOption('extended-insert', 'e', InputOption::VALUE_NONE,
'Write INSERT statements using multiple-row syntax that includes several VALUES lists. This results in a smaller dump file and speeds up inserts when the file is reloaded. Defaults to on, use no-extended-insert to switch off.')
'Write INSERT statements using multiple-row syntax that includes several VALUES lists. This results in a smaller dump file and speeds up inserts when the file is reloaded. Defaults to on, use skip-extended-insert to switch off.')
->addOption('events', null, InputOption::VALUE_NONE,
'Dump events from dumped databases ')
->addOption('hex-blob', null, InputOption::VALUE_NONE,
Expand All @@ -89,16 +100,6 @@ protected function configure()
'Dump stored routines (procedures and functions) from dumped databases.')
->addOption('single-transaction', null, InputOption::VALUE_NONE,
'Issue a BEGIN SQL statement before dumping data from server.')
->addOption('skip-triggers', null, InputOption::VALUE_NONE,
'Do not dump triggers.')
->addOption('skip-tz-utc', null, InputOption::VALUE_NONE,
'Turn off tz-utc.')
->addOption('skip-comments', null, InputOption::VALUE_NONE,
'Do not add comments to dump file.')
->addOption('skip-dump-date', null, InputOption::VALUE_NONE,
'Skip dump date to better compare dumps.')
->addOption('skip-definer', null, InputOption::VALUE_NONE,
'Omit DEFINER and SQL SECURITY clauses from the CREATE statements for views and stored programs.')
->addOption('where', null, InputOption::VALUE_OPTIONAL,
'Dump only rows selected by given WHERE condition.')
->addOption('gdpr-expressions', null, InputOption::VALUE_OPTIONAL,
Expand All @@ -113,9 +114,24 @@ protected function configure()
//->addOption('databases', NULL, InputOption::VALUE_OPTIONAL|InputOption::VALUE_IS_ARRAY, 'Dump several databases. Normally, mysqldump treats the first name argument on the command line as a database name and following names as table names. With this option, it treats all name arguments as database names.')
// Add some options that e.g. drush expects.
->addOption('quote-names', 'Q', InputOption::VALUE_NONE,
'Currently ignored.')
'Currently ignored (hardcoded to on in mysqldump-php).')
->addOption('opt', null, InputOption::VALUE_NONE,
'Implies --add-drop-table --add-locks --disable-keys --extended-insert --hex-blob --no-autocommit --single-transaction.');
'Implies --add-drop-table --add-locks --disable-keys --extended-insert --hex-blob --no-autocommit --single-transaction.')
->addOption('skip-triggers', null, InputOption::VALUE_NONE,
'Do not dump triggers.')
->addOption('skip-tz-utc', null, InputOption::VALUE_NONE,
'Turn off tz-utc.')
->addOption('skip-comments', null, InputOption::VALUE_NONE,
'Do not add comments to dump file.')
->addOption('skip-dump-date', null, InputOption::VALUE_NONE,
'Skip dump date to better compare dumps.')
->addOption('skip-definer', null, InputOption::VALUE_NONE,
'Omit DEFINER and SQL SECURITY clauses from the CREATE statements for views and stored programs.');

foreach(self::$skipable_options as $option) {
$this->addOption("skip-$option", null, InputOption::VALUE_NONE,
"Inhibits any previous explicit or implicit $option option.");
}
}

/**
Expand Down Expand Up @@ -171,7 +187,7 @@ public function getEffectivePassword(
protected function execute(InputInterface $input, OutputInterface $output)
{
$dumpSettings =
$this->getOptOptions($input->getOption('opt'))
$this->getOptOptions($input->getOption('opt') && !$input->getOption('skip-opt'))
+ $this->getDefaults($input->getOption('defaults-file'))
+ array_filter($input->getArguments())
+ array_filter($input->getOptions())
Expand All @@ -185,6 +201,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
], null);
$user = $dumpSettings['user'];

foreach(self::$skipable_options as $option) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after foreach

if($input->getOption("skip-$option")) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after if

$dumpSettings[$option] = false;
}
}

$dumpSettings['password'] = $this->getEffectivePassword($input, $output, $dumpSettings['password']);
$password = $dumpSettings['password'];
Expand Down