/** * @param InputInterface $input * @param OutputInterface $output * @param AbstractCompressor $compressor * * @return string */ protected function getFileName(InputInterface $input, OutputInterface $output, AbstractCompressor $compressor) { $namePrefix = ''; $nameSuffix = ''; if ($input->getOption('xml')) { $nameExtension = '.xml'; } else { $nameExtension = '.sql'; } if ($input->getOption('add-time') !== false) { $timeStamp = date('Y-m-d_His'); if ($input->getOption('add-time') == 'suffix') { $nameSuffix = '_' . $timeStamp; } else { $namePrefix = $timeStamp . '_'; } } if ((($fileName = $input->getArgument('filename')) === null || ($isDir = is_dir($fileName))) && !$input->getOption('stdout')) { /** @var DialogHelper $dialog */ $dialog = $this->getHelperSet()->get('dialog'); $defaultName = $namePrefix . $this->dbSettings['dbname'] . $nameSuffix . $nameExtension; if (isset($isDir) && $isDir) { $defaultName = rtrim($fileName, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $defaultName; } if (!$input->getOption('force')) { $fileName = $dialog->ask($output, '<question>Filename for SQL dump:</question> [<comment>' . $defaultName . '</comment>]', $defaultName); } else { $fileName = $defaultName; } } else { if ($input->getOption('add-time')) { $pathParts = pathinfo($fileName); $fileName = ($pathParts['dirname'] == '.' ? '' : $pathParts['dirname'] . DIRECTORY_SEPARATOR) . $namePrefix . $pathParts['filename'] . $nameSuffix . '.' . $pathParts['extension']; } } $fileName = $compressor->getFileName($fileName); return $fileName; }
/** * @param string $type of compression: "gz" | "gzip" | "none" | null */ public function setCompression($type) { $this->compressor = AbstractCompressor::create($type); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void * @throws Exception */ 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 = AbstractCompressor::create($input->getOption('compression')); // 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('optimize')) { if ($input->getOption('compression')) { throw new Exception('Options --compression and --optimize are not compatible'); } $output->writeln('<comment>Optimizing <info>' . $fileName . '</info> to temporary file'); $fileName = $this->optimize($fileName); } 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); } }
/** * @param string $type * @return AbstractCompressor * @deprecated Since 1.1.12; use AbstractCompressor::create() instead */ protected function getCompressor($type) { return AbstractCompressor::create($type); }