/** * @param InputInterface $input * @param OutputInterface $output * @param Compressor $compressor * * @return string */ protected function getFileName(InputInterface $input, OutputInterface $output, Compressor $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->getHelper('dialog'); $defaultName = VerifyOrDie::filename($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 InputInterface $input * @param OutputInterface $output * * @throws InvalidArgumentException */ protected function createDatabase(InputInterface $input, OutputInterface $output) { $dbOptions = array('--dbHost', '--dbUser', '--dbPass', '--dbName'); $dbOptionsFound = 0; foreach ($dbOptions as $dbOption) { foreach ($this->getCliArguments() as $definedCliOption) { if (BinaryString::startsWith($definedCliOption, $dbOption)) { $dbOptionsFound++; } } } $hasAllOptions = $dbOptionsFound == 4; // if all database options were passed in at cmd line if ($hasAllOptions) { $this->config['db_host'] = $input->getOption('dbHost'); $this->config['db_user'] = $input->getOption('dbUser'); $this->config['db_pass'] = $input->getOption('dbPass'); $this->config['db_name'] = VerifyOrDie::filename($input->getOption('dbName'), 'Database name is not portable'); $this->config['db_port'] = $input->getOption('dbPort'); $this->config['db_prefix'] = $input->getOption('dbPrefix'); $db = $this->validateDatabaseSettings($output, $input); if ($db === false) { throw new InvalidArgumentException("Database configuration is invalid"); } } else { /** @var DialogHelper $dialog */ $dialog = $this->getHelper('dialog'); do { $dbHostDefault = $input->getOption('dbHost') ? $input->getOption('dbHost') : 'localhost'; $this->config['db_host'] = $dialog->askAndValidate($output, '<question>Please enter the database host</question> <comment>[' . $dbHostDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbHostDefault); $dbUserDefault = $input->getOption('dbUser') ? $input->getOption('dbUser') : 'root'; $this->config['db_user'] = $dialog->askAndValidate($output, '<question>Please enter the database username</question> <comment>[' . $dbUserDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbUserDefault); $dbPassDefault = $input->getOption('dbPass') ? $input->getOption('dbPass') : ''; $this->config['db_pass'] = $dialog->ask($output, '<question>Please enter the database password</question> <comment>[' . $dbPassDefault . ']</comment>: ', $dbPassDefault); $dbNameDefault = $input->getOption('dbName') ? $input->getOption('dbName') : 'magento'; $this->config['db_name'] = $dialog->askAndValidate($output, '<question>Please enter the database name</question> <comment>[' . $dbNameDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbNameDefault); $dbPortDefault = $input->getOption('dbPort') ? $input->getOption('dbPort') : 3306; $this->config['db_port'] = $dialog->askAndValidate($output, '<question>Please enter the database port </question> <comment>[' . $dbPortDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbPortDefault); $dbPrefixDefault = $input->getOption('dbPrefix') ? $input->getOption('dbPrefix') : ''; $this->config['db_prefix'] = $dialog->ask($output, '<question>Please enter the table prefix</question> <comment>[' . $dbPrefixDefault . ']</comment>:', $dbPrefixDefault); $db = $this->validateDatabaseSettings($output, $input); } while ($db === false); } $this->config['db'] = $db; }