From b2c4c35bacf7c4be181e29fd3c03a6127fc128fd Mon Sep 17 00:00:00 2001 From: p-makowski Date: Wed, 22 Nov 2023 19:58:01 +0100 Subject: [PATCH] Make SQL definer replacement optional --- .../Magento/Command/Database/DumpCommand.php | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/N98/Magento/Command/Database/DumpCommand.php b/src/N98/Magento/Command/Database/DumpCommand.php index 8767233fa..df5f3a8a6 100644 --- a/src/N98/Magento/Command/Database/DumpCommand.php +++ b/src/N98/Magento/Command/Database/DumpCommand.php @@ -143,6 +143,12 @@ protected function configure() InputOption::VALUE_NONE, 'Keeps the Column Statistics table in SQL dump' ) + ->addOption( + 'keep-definer', + null, + InputOption::VALUE_NONE, + 'Do not remove DEFINER from dump' + ) ->setDescription('Dumps database with mysqldump cli client'); $help = <<add( '--no-data ' . $mysqlClientToolConnectionString . - ' ' . implode(' ', $stripTables) . $this->postDumpPipeCommands() + ' ' . implode(' ', $stripTables) . $this->postDumpPipeCommands($input) ); } @@ -346,7 +352,12 @@ private function createExecs(InputInterface $input, OutputInterface $output) $ignore .= '--ignore-table=' . $this->dbSettings['dbname'] . '.' . $ignoreTable . ' '; } - $execs->add($ignore . $mysqlClientToolConnectionString . $postDumpGitFriendlyPipeCommands . $this->postDumpPipeCommands()); + $execs->add( + $ignore + . $mysqlClientToolConnectionString + . $postDumpGitFriendlyPipeCommands + . $this->postDumpPipeCommands($input) + ); return $execs; } @@ -491,12 +502,15 @@ private function resolveDatabaseTables($list) /** * Commands which filter mysql data. Piped to mysqldump command * + * @param InputInterface $input * @return string */ - protected function postDumpPipeCommands() + protected function postDumpPipeCommands(InputInterface $input) { - return ' | LANG=C LC_CTYPE=C LC_ALL=C sed -E ' - . escapeshellarg('s/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g'); + return $input->getOption('keep-definer') + ? '' + : ' | LANG=C LC_CTYPE=C LC_ALL=C sed -E ' + . escapeshellarg('s/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g'); } /**