Skip to content
This repository was archived by the owner on Feb 3, 2022. It is now read-only.

Commit 31e46b2

Browse files
committed
Merge branch 'release/v1.4.0'
2 parents 963067b + 3c106e3 commit 31e46b2

File tree

4 files changed

+51
-48
lines changed

4 files changed

+51
-48
lines changed

src/Meanbee/Magedbm/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Application extends \Symfony\Component\Console\Application
1212
{
1313

1414
const APP_NAME = 'Magedbm';
15-
const APP_VERSION = '1.3.2';
15+
const APP_VERSION = '1.4.0';
1616

1717
protected $autoloader;
1818

src/Meanbee/Magedbm/Command/GetCommand.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ protected function configure()
3434
InputOption::VALUE_REQUIRED,
3535
'File to import, otherwise latest downloaded'
3636
)
37+
->addOption(
38+
'download-only',
39+
'-o',
40+
InputOption::VALUE_NONE,
41+
'Only download the backup to the current directory'
42+
)
3743
->addOption(
3844
'--force',
3945
'-f',
@@ -44,7 +50,7 @@ protected function configure()
4450
'--drop-tables',
4551
'-d',
4652
InputOption::VALUE_NONE,
47-
'Drop tables before import'
53+
'Drop tables before import. Deprecated since 1.4.0 as all exports now drop tables automatically.'
4854
)
4955
->addOption(
5056
'--region',
@@ -73,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7379
{
7480
// Import overwrites databases so ask for confirmation.
7581
$dialog = $this->getHelper('dialog');
76-
if (!$input->getOption('force')) {
82+
if (!$input->getOption('force') && !$input->getOption('download-only')) {
7783
if (!$dialog->askConfirmation(
7884
$output,
7985
'<question>Are you sure you wish to overwrite local database [y/n]?</question>',
@@ -94,7 +100,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
94100

95101
$this->downloadBackup($file, $s3, $config, $input);
96102

97-
$this->backupImport($file, $input);
103+
if ($input->getOption('download-only')) {
104+
$this->backupMove($file);
105+
} else {
106+
$this->backupImport($file, $input);
107+
}
98108
}
99109

100110
/**
@@ -188,10 +198,6 @@ protected function backupImport($file, $input)
188198
'--compression' => 'gzip',
189199
);
190200

191-
if ($input->getOption('drop-tables')) {
192-
$params['--drop-tables'] = true;
193-
}
194-
195201
try {
196202
if ($returnCode = $importCommand->run(new ArrayInput($params), $this->getOutput())) {
197203
$this->getOutput()->writeln('<error>magerun db:import failed to import database.</error>');
@@ -203,6 +209,22 @@ protected function backupImport($file, $input)
203209
$this->cleanUp();
204210
}
205211

212+
/**
213+
* Move backup from tmp directory to current working directory
214+
*
215+
* @param $file
216+
*/
217+
protected function backupMove($file)
218+
{
219+
$filename = $this->getFilePath($file);
220+
$newFilename = getcwd() . '/' . $file;
221+
if (rename($filename, $newFilename)) {
222+
$this->getOutput()->writeln("<info>Downloaded to $newFilename.</info>");
223+
} else {
224+
$this->getOutput()->writeln("<error>Failed to move backup to current working directory. Check $filename</error>");
225+
}
226+
}
227+
206228

207229
/**
208230
* Get filepath in tmp directory

src/Meanbee/Magedbm/Command/ListCommand.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function configure()
2222
->setDescription('List available backups')
2323
->addArgument(
2424
'name',
25-
InputArgument::REQUIRED,
25+
InputArgument::OPTIONAL,
2626
'Project identifier'
2727
)
2828
->addOption(
@@ -53,15 +53,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
5353
$s3 = $this->getS3Client($input->getOption('region'));
5454
$config = $this->getConfig($input);
5555

56+
$name = $input->getArgument('name') ?: '';
57+
5658
try {
5759
$results = $s3->getIterator(
5860
'ListObjects',
59-
array('Bucket' => $config['bucket'], 'Prefix' => $input->getArgument('name'))
61+
array('Bucket' => $config['bucket'], 'Prefix' => $name)
6062
);
6163

64+
$names = array();
6265
foreach ($results as $item) {
6366
$itemKeyChunks = explode('/', $item['Key']);
64-
$this->getOutput()->writeln(sprintf('%s %dMB', array_pop($itemKeyChunks), $item['Size'] / 1024 / 1024));
67+
68+
if ($name) {
69+
// If name presented, show downloads for that name
70+
$this->getOutput()->writeln(sprintf('%s %dMB', array_pop($itemKeyChunks), $item['Size'] / 1024 / 1024));
71+
} else {
72+
// Otherwise show uniqued list of available names
73+
if (!in_array($itemKeyChunks[0], $names)) {
74+
$names[] = $itemKeyChunks[0];
75+
$this->getOutput()->writeln($itemKeyChunks[0]);
76+
}
77+
}
6578
}
6679

6780
if (!$results->count()) {

src/Meanbee/Magedbm/Command/PutCommand.php

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -198,49 +198,15 @@ protected function cleanUp()
198198
}
199199

200200
/**
201-
* Create database backup in tmp directory.
202-
* Use magerun db:dump if available. Otherwise use php alternative if exec not available.
201+
* Database export without using exec.
203202
*
204203
* @param InputInterface $input
205204
* @param OutputInterface $output
206-
*
207205
* @throws \Exception
208206
*/
209207
private function createBackup(InputInterface $input, OutputInterface $output)
210208
{
211-
$magerun = $this->getMagerun();
212-
$filePath = $this->getFilePath($input);
213-
214-
try {
215-
/** @var \N98\Magento\Command\Database\DumpCommand $dumpCommand */
216-
$dumpCommand = $magerun->find("db:dump");
217-
218-
$stripOptions = $input->getOption('strip') ? : '@development';
219-
$dumpInput = new ArrayInput(array(
220-
'filename' => $filePath,
221-
'--strip' => $stripOptions,
222-
'--compression' => 'gzip',
223-
));
224-
225-
if ($dumpCommand->run($dumpInput, $output)) {
226-
throw new \Exception("magerun db:dump failed to create backup..");
227-
}
228-
} catch (\InvalidArgumentException $e) {
229-
$this->createBackupWithoutExec($input, $output);
230-
231-
$output->writeln('<info>Finished</info>');
232-
}
233-
}
234-
235-
/**
236-
* PHP alternative to dump database without exec
237-
*
238-
* @param InputInterface $input
239-
* @param OutputInterface $output
240-
* @throws \Exception
241-
*/
242-
private function createBackupWithoutExec(InputInterface $input, OutputInterface $output)
243-
{
209+
// Use Magerun for getting DB details
244210
$magerun = $this->getMagerun();
245211
$filePath = $this->getFilePath($input);
246212

@@ -291,13 +257,15 @@ private function createBackupWithoutExec(InputInterface $input, OutputInterface
291257
array(
292258
'include-tables' => $stripTables,
293259
'no-data' => true,
260+
'add-drop-table' => true,
294261
)
295262
);
296263

297264
$dumpStructure->start($filePath . '.structure');
298265

299266
$dump = new Mysqldump(sprintf('%s;dbname=%s', $dbHelper->dsn(), $dbName), $username, $password, array(
300-
'exclude-tables' => $stripTables
267+
'exclude-tables' => $stripTables,
268+
'add-drop-table' => true,
301269
));
302270

303271
$dump->start($filePath . '.data');

0 commit comments

Comments
 (0)