protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectDbSettings($output);
$this->writeSection($output, 'Import MySQL Database');
$dbHelper = $this->getHelper('database');
$fileName = $this->checkFilename($input);
$compressor = $this->getCompressor($input->getOption('compression'));
if ($input->getOption('optimize')) {
if ($input->getOption('only-command')) {
throw new InvalidArgumentException('Options --only-command and --optimize are not compatible');
}
if ($input->getOption('compression')) {
throw new InvalidArgumentException('Options --compression and --optimize are not compatible');
}
$output->writeln('<comment>Optimizing <info>' . $fileName . '</info> to temporary file');
$fileName = $this->optimize($fileName);
}
// create import command
$exec = $compressor->getDecompressingCommand('mysql ' . $dbHelper->getMysqlClientToolConnectionString(), $fileName);
if ($input->getOption('only-command')) {
$output->writeln($exec);
return;
} else {
if ($input->getOption('only-if-empty') && count($dbHelper->getTables()) > 0) {
$output->writeln('<comment>Skip import. Database is not empty</comment>');
return;
}
}
if ($input->getOption('drop')) {
$dbHelper->dropDatabase($output);
$dbHelper->createDatabase($output);
}
if ($input->getOption('drop-tables')) {
$dbHelper->dropTables($output);
}
$this->doImport($output, $fileName, $exec);
if ($input->getOption('optimize')) {
unlink($fileName);
}
}