From e6953145912583a2957df82c96e333cdc590dc1b Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Tue, 15 Dec 2015 08:48:30 +0000 Subject: [PATCH 1/9] Touches 16: List command without a name argument now returns all backups. --- src/Meanbee/Magedbm/Command/ListCommand.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Meanbee/Magedbm/Command/ListCommand.php b/src/Meanbee/Magedbm/Command/ListCommand.php index 9d03e45..0ab0d85 100644 --- a/src/Meanbee/Magedbm/Command/ListCommand.php +++ b/src/Meanbee/Magedbm/Command/ListCommand.php @@ -22,7 +22,7 @@ protected function configure() ->setDescription('List available backups') ->addArgument( 'name', - InputArgument::REQUIRED, + InputArgument::OPTIONAL, 'Project identifier' ) ->addOption( @@ -53,10 +53,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $s3 = $this->getS3Client($input->getOption('region')); $config = $this->getConfig($input); + $name = $input->getArgument('name') ? : ''; + try { $results = $s3->getIterator( 'ListObjects', - array('Bucket' => $config['bucket'], 'Prefix' => $input->getArgument('name')) + array('Bucket' => $config['bucket'], 'Prefix' => $name) ); foreach ($results as $item) { From 96548602106fa61a02ffdcbe2fbf59f0f582a5d7 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Fri, 18 Dec 2015 09:45:15 +0000 Subject: [PATCH 2/9] Fixes 16: Unique the list of available names when using the `ls` command. --- src/Meanbee/Magedbm/Command/ListCommand.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Meanbee/Magedbm/Command/ListCommand.php b/src/Meanbee/Magedbm/Command/ListCommand.php index 0ab0d85..d60ba3c 100644 --- a/src/Meanbee/Magedbm/Command/ListCommand.php +++ b/src/Meanbee/Magedbm/Command/ListCommand.php @@ -61,9 +61,20 @@ protected function execute(InputInterface $input, OutputInterface $output) array('Bucket' => $config['bucket'], 'Prefix' => $name) ); + $names = array(); foreach ($results as $item) { $itemKeyChunks = explode('/', $item['Key']); - $this->getOutput()->writeln(sprintf('%s %dMB', array_pop($itemKeyChunks), $item['Size'] / 1024 / 1024)); + + if ($name) { + // If name presented, show downloads for that name + $this->getOutput()->writeln(sprintf('%s %dMB', array_pop($itemKeyChunks), $item['Size'] / 1024 / 1024)); + } else { + // Otherwise show uniqued list of available names + if (!in_array($itemKeyChunks[0], $names)) { + $names[] = $itemKeyChunks[0]; + $this->getOutput()->writeln($itemKeyChunks[0]); + } + } } if (!$results->count()) { From 7985b9a687e2b72e1c1b85806bc6eff3ca4076f6 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Fri, 18 Dec 2015 09:48:08 +0000 Subject: [PATCH 3/9] 16: Linting the LS function. --- src/Meanbee/Magedbm/Command/ListCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Meanbee/Magedbm/Command/ListCommand.php b/src/Meanbee/Magedbm/Command/ListCommand.php index d60ba3c..66f82d2 100644 --- a/src/Meanbee/Magedbm/Command/ListCommand.php +++ b/src/Meanbee/Magedbm/Command/ListCommand.php @@ -53,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $s3 = $this->getS3Client($input->getOption('region')); $config = $this->getConfig($input); - $name = $input->getArgument('name') ? : ''; + $name = $input->getArgument('name') ?: ''; try { $results = $s3->getIterator( From d07d36adce3a05156920ec33940d2ca394acf7ce Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Fri, 18 Dec 2015 10:45:52 +0000 Subject: [PATCH 4/9] Fixes #17: Add parameter to get command to only download the backup to the current working directory. --- src/Meanbee/Magedbm/Command/GetCommand.php | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Meanbee/Magedbm/Command/GetCommand.php b/src/Meanbee/Magedbm/Command/GetCommand.php index 1ef0157..af566f4 100644 --- a/src/Meanbee/Magedbm/Command/GetCommand.php +++ b/src/Meanbee/Magedbm/Command/GetCommand.php @@ -34,6 +34,12 @@ protected function configure() InputOption::VALUE_REQUIRED, 'File to import, otherwise latest downloaded' ) + ->addOption( + 'download-only', + '-o', + InputOption::VALUE_NONE, + 'Only download the backup to the current directory' + ) ->addOption( '--force', '-f', @@ -73,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { // Import overwrites databases so ask for confirmation. $dialog = $this->getHelper('dialog'); - if (!$input->getOption('force')) { + if (!$input->getOption('force') && !$input->getOption('download-only')) { if (!$dialog->askConfirmation( $output, 'Are you sure you wish to overwrite local database [y/n]?', @@ -94,7 +100,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->downloadBackup($file, $s3, $config, $input); - $this->backupImport($file, $input); + if ($input->getOption('download-only')) { + $this->backupMove($file); + } else { + $this->backupImport($file, $input); + } } /** @@ -203,6 +213,22 @@ protected function backupImport($file, $input) $this->cleanUp(); } + /** + * Move backup from tmp directory to specified location + * + * @param $file + */ + protected function backupMove($file) + { + $filename = $this->getFilePath($file); + $newFilename = getcwd() . '/' . $file; + if (rename($filename, $newFilename)) { + $this->getOutput()->writeln("Downloaded to $newFilename."); + } else { + $this->getOutput()->writeln("Failed to move backup to current working directory. Check $filename"); + } + } + /** * Get filepath in tmp directory From 8fd7cbe98d6f2e3a06344dea69b45196cf04cacd Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Fri, 18 Dec 2015 10:47:26 +0000 Subject: [PATCH 5/9] Update function documentation with latest functionality. --- src/Meanbee/Magedbm/Command/GetCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Meanbee/Magedbm/Command/GetCommand.php b/src/Meanbee/Magedbm/Command/GetCommand.php index af566f4..ffabaa1 100644 --- a/src/Meanbee/Magedbm/Command/GetCommand.php +++ b/src/Meanbee/Magedbm/Command/GetCommand.php @@ -214,7 +214,7 @@ protected function backupImport($file, $input) } /** - * Move backup from tmp directory to specified location + * Move backup from tmp directory to current working directory * * @param $file */ From 5bac9a7227d9017e9dfe52fdd207b94f844820b2 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Fri, 18 Dec 2015 11:35:09 +0000 Subject: [PATCH 6/9] Make sure non-exec dump drops tables. --- src/Meanbee/Magedbm/Command/PutCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Meanbee/Magedbm/Command/PutCommand.php b/src/Meanbee/Magedbm/Command/PutCommand.php index e5f697e..db5d77f 100644 --- a/src/Meanbee/Magedbm/Command/PutCommand.php +++ b/src/Meanbee/Magedbm/Command/PutCommand.php @@ -291,13 +291,15 @@ private function createBackupWithoutExec(InputInterface $input, OutputInterface array( 'include-tables' => $stripTables, 'no-data' => true, + 'add-drop-table' => true, ) ); $dumpStructure->start($filePath . '.structure'); $dump = new Mysqldump(sprintf('%s;dbname=%s', $dbHelper->dsn(), $dbName), $username, $password, array( - 'exclude-tables' => $stripTables + 'exclude-tables' => $stripTables, + 'add-drop-table' => true, )); $dump->start($filePath . '.data'); From df40271c6883acd9b4e801c98a472492b4d09069 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Fri, 18 Dec 2015 11:38:32 +0000 Subject: [PATCH 7/9] Deprecate drop tables option on import as all database dumps will now do this. --- src/Meanbee/Magedbm/Command/GetCommand.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Meanbee/Magedbm/Command/GetCommand.php b/src/Meanbee/Magedbm/Command/GetCommand.php index 1ef0157..c20a5af 100644 --- a/src/Meanbee/Magedbm/Command/GetCommand.php +++ b/src/Meanbee/Magedbm/Command/GetCommand.php @@ -44,7 +44,7 @@ protected function configure() '--drop-tables', '-d', InputOption::VALUE_NONE, - 'Drop tables before import' + 'Drop tables before import. Deprecated since 1.4.0 as all exports now drop tables automatically.' ) ->addOption( '--region', @@ -188,10 +188,6 @@ protected function backupImport($file, $input) '--compression' => 'gzip', ); - if ($input->getOption('drop-tables')) { - $params['--drop-tables'] = true; - } - try { if ($returnCode = $importCommand->run(new ArrayInput($params), $this->getOutput())) { $this->getOutput()->writeln('magerun db:import failed to import database.'); From c4ce4cc39b97198dff7bc00ef912f22cc4511095 Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Fri, 18 Dec 2015 11:49:19 +0000 Subject: [PATCH 8/9] Fixes #24: Remove magerun db:dump command usage. --- src/Meanbee/Magedbm/Command/PutCommand.php | 38 ++-------------------- 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/src/Meanbee/Magedbm/Command/PutCommand.php b/src/Meanbee/Magedbm/Command/PutCommand.php index e5f697e..c4eecf6 100644 --- a/src/Meanbee/Magedbm/Command/PutCommand.php +++ b/src/Meanbee/Magedbm/Command/PutCommand.php @@ -198,49 +198,15 @@ protected function cleanUp() } /** - * Create database backup in tmp directory. - * Use magerun db:dump if available. Otherwise use php alternative if exec not available. + * Database export without using exec. * * @param InputInterface $input * @param OutputInterface $output - * * @throws \Exception */ private function createBackup(InputInterface $input, OutputInterface $output) { - $magerun = $this->getMagerun(); - $filePath = $this->getFilePath($input); - - try { - /** @var \N98\Magento\Command\Database\DumpCommand $dumpCommand */ - $dumpCommand = $magerun->find("db:dump"); - - $stripOptions = $input->getOption('strip') ? : '@development'; - $dumpInput = new ArrayInput(array( - 'filename' => $filePath, - '--strip' => $stripOptions, - '--compression' => 'gzip', - )); - - if ($dumpCommand->run($dumpInput, $output)) { - throw new \Exception("magerun db:dump failed to create backup.."); - } - } catch (\InvalidArgumentException $e) { - $this->createBackupWithoutExec($input, $output); - - $output->writeln('Finished'); - } - } - - /** - * PHP alternative to dump database without exec - * - * @param InputInterface $input - * @param OutputInterface $output - * @throws \Exception - */ - private function createBackupWithoutExec(InputInterface $input, OutputInterface $output) - { + // Use Magerun for getting DB details $magerun = $this->getMagerun(); $filePath = $this->getFilePath($input); From 3c106e3c3afe96e21ba46b394aeca1f4a020c83e Mon Sep 17 00:00:00 2001 From: Tom Robertshaw Date: Fri, 18 Dec 2015 12:17:57 +0000 Subject: [PATCH 9/9] Bump version number to 1.4.0 --- src/Meanbee/Magedbm/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Meanbee/Magedbm/Application.php b/src/Meanbee/Magedbm/Application.php index 9797575..215c884 100644 --- a/src/Meanbee/Magedbm/Application.php +++ b/src/Meanbee/Magedbm/Application.php @@ -12,7 +12,7 @@ class Application extends \Symfony\Component\Console\Application { const APP_NAME = 'Magedbm'; - const APP_VERSION = '1.3.2'; + const APP_VERSION = '1.4.0'; protected $autoloader;