use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Config\Definition\Exception\Exception;
-use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Command\Command;
+use Drupal\Console\Core\Command\ContainerAwareCommand;
use Drupal\Core\Database\Database;
use Drupal\Core\Installer\Exception\AlreadyInstalledException;
-use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
use Drupal\Console\Command\Shared\DatabaseTrait;
use Drupal\Console\Core\Utils\ConfigurationManager;
use Drupal\Console\Extension\Manager;
-use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Console\Bootstrap\Drupal;
use Drupal\Console\Utils\Site;
-use DrupalFinder\DrupalFinder;
+use Drupal\Console\Core\Utils\DrupalFinder;
-class InstallCommand extends Command
+class InstallCommand extends ContainerAwareCommand
{
- use ContainerAwareCommandTrait;
use DatabaseTrait;
/**
'langcode',
null,
InputOption::VALUE_REQUIRED,
- $this->trans('commands.site.install.options.langcode')
+ $this->trans('commands.site.install.arguments.langcode')
)
->addOption(
'db-type',
null,
InputOption::VALUE_REQUIRED,
- $this->trans('commands.site.install.options.db-type')
+ $this->trans('commands.site.install.arguments.db-type')
)
->addOption(
'db-file',
null,
InputOption::VALUE_REQUIRED,
- $this->trans('commands.site.install.options.db-file')
+ $this->trans('commands.site.install.arguments.db-file')
)
->addOption(
'db-host',
'site-name',
null,
InputOption::VALUE_REQUIRED,
- $this->trans('commands.site.install.options.site-name')
+ $this->trans('commands.site.install.arguments.site-name')
)
->addOption(
'site-mail',
null,
InputOption::VALUE_REQUIRED,
- $this->trans('commands.site.install.options.site-mail')
+ $this->trans('commands.site.install.arguments.site-mail')
)
->addOption(
'account-name',
null,
InputOption::VALUE_REQUIRED,
- $this->trans('commands.site.install.options.account-name')
+ $this->trans('commands.site.install.arguments.account-name')
)
->addOption(
'account-mail',
null,
InputOption::VALUE_REQUIRED,
- $this->trans('commands.site.install.options.account-mail')
+ $this->trans('commands.site.install.arguments.account-mail')
)
->addOption(
'account-pass',
null,
InputOption::VALUE_REQUIRED,
- $this->trans('commands.site.install.options.account-pass')
+ $this->trans('commands.site.install.arguments.account-pass')
)
->addOption(
'force',
null,
InputOption::VALUE_NONE,
- $this->trans('commands.site.install.options.force')
- );
+ $this->trans('commands.site.install.arguments.force')
+ )
+ ->setAliases(['si']);
}
/**
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
-
// --profile option
$profile = $input->getArgument('profile');
if (!$profile) {
}
);
- $profile = $io->choice(
+ $profile = $this->getIo()->choice(
$this->trans('commands.site.install.questions.profile'),
array_values($profiles)
);
->getConfiguration()
->get('application.language');
- $langcode = $io->choiceNoList(
+ $langcode = $this->getIo()->choiceNoList(
$this->trans('commands.site.install.questions.langcode'),
$languages,
$languages[$defaultLanguage]
$dbType = $input->getOption('db-type');
if (!$dbType) {
$databases = $this->site->getDatabaseTypes();
- $dbType = $io->choice(
+ $dbType = $this->getIo()->choice(
$this->trans('commands.migrate.setup.questions.db-type'),
array_column($databases, 'name')
);
// --db-file option
$dbFile = $input->getOption('db-file');
if (!$dbFile) {
- $dbFile = $io->ask(
+ $dbFile = $this->getIo()->ask(
$this->trans('commands.migrate.execute.questions.db-file'),
'sites/default/files/.ht.sqlite'
);
// --db-host option
$dbHost = $input->getOption('db-host');
if (!$dbHost) {
- $dbHost = $this->dbHostQuestion($io);
+ $dbHost = $this->dbHostQuestion();
$input->setOption('db-host', $dbHost);
}
// --db-name option
$dbName = $input->getOption('db-name');
if (!$dbName) {
- $dbName = $this->dbNameQuestion($io);
+ $dbName = $this->dbNameQuestion();
$input->setOption('db-name', $dbName);
}
// --db-user option
$dbUser = $input->getOption('db-user');
if (!$dbUser) {
- $dbUser = $this->dbUserQuestion($io);
+ $dbUser = $this->dbUserQuestion();
$input->setOption('db-user', $dbUser);
}
// --db-pass option
$dbPass = $input->getOption('db-pass');
if (!$dbPass) {
- $dbPass = $this->dbPassQuestion($io);
+ $dbPass = $this->dbPassQuestion();
$input->setOption('db-pass', $dbPass);
}
// --db-port prefix
$dbPort = $input->getOption('db-port');
if (!$dbPort) {
- $dbPort = $this->dbPortQuestion($io);
+ $dbPort = $this->dbPortQuestion();
$input->setOption('db-port', $dbPort);
}
}
// --db-prefix
$dbPrefix = $input->getOption('db-prefix');
if (!$dbPrefix) {
- $dbPrefix = $this->dbPrefixQuestion($io);
+ $dbPrefix = $this->dbPrefixQuestion();
$input->setOption('db-prefix', $dbPrefix);
}
} else {
$input->setOption('db-pass', $database['default']['password']);
$input->setOption('db-port', $database['default']['port']);
$input->setOption('db-prefix', $database['default']['prefix']['default']);
- $io->info(
+ $this->getIo()->info(
sprintf(
$this->trans('commands.site.install.messages.using-current-database'),
$database['default']['driver'],
// --site-name option
$siteName = $input->getOption('site-name');
if (!$siteName) {
- $siteName = $io->ask(
+ $siteName = $this->getIo()->ask(
$this->trans('commands.site.install.questions.site-name'),
- 'Drupal 8'
+ $this->trans('commands.site.install.suggestions.site-name')
);
$input->setOption('site-name', $siteName);
}
// --site-mail option
$siteMail = $input->getOption('site-mail');
if (!$siteMail) {
- $siteMail = $io->ask(
+ $siteMail = $this->getIo()->ask(
$this->trans('commands.site.install.questions.site-mail'),
'admin@example.com'
);
// --account-name option
$accountName = $input->getOption('account-name');
if (!$accountName) {
- $accountName = $io->ask(
+ $accountName = $this->getIo()->ask(
$this->trans('commands.site.install.questions.account-name'),
'admin'
);
// --account-pass option
$accountPass = $input->getOption('account-pass');
if (!$accountPass) {
- $accountPass = $io->askHidden(
+ $accountPass = $this->getIo()->askHidden(
$this->trans('commands.site.install.questions.account-pass')
);
$input->setOption('account-pass', $accountPass);
// --account-mail option
$accountMail = $input->getOption('account-mail');
if (!$accountMail) {
- $accountMail = $io->ask(
+ $accountMail = $this->getIo()->ask(
$this->trans('commands.site.install.questions.account-mail'),
$siteMail
);
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
- $uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
+ $uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
if ($this->site->multisiteMode($uri)) {
if (!$this->site->validMultisite($uri)) {
- $io->error(
+ $this->getIo()->error(
sprintf($this->trans('commands.site.install.messages.invalid-multisite'), $uri, $uri)
);
exit(1);
'driver' => $dbType,
];
- if ($force && Database::getConnectionInfo()) {
+ if ($force && Database::isActiveConnection()) {
$schema = Database::getConnection()->schema();
$tables = $schema->findTables('%');
foreach ($tables as $table) {
try {
$drupalFinder = new DrupalFinder();
$drupalFinder->locateRoot(getcwd());
- $composerRoot = $drupalFinder->getComposerRoot();
- $drupalRoot = $drupalFinder->getDrupalRoot();
-
- $this->runInstaller($io, $input, $database, $uri);
+ $this->runInstaller($database, $uri);
$autoload = $this->container->get('class_loader');
- $drupal = new Drupal($autoload, $composerRoot, $drupalRoot);
+ $drupal = new Drupal(
+ $autoload,
+ $drupalFinder,
+ $this->configurationManager
+ );
$container = $drupal->boot();
$this->getApplication()->setContainer($container);
+ $this->getApplication()->validateCommands();
+ $this->getApplication()->loadCommands();
} catch (Exception $e) {
- $io->error($e->getMessage());
+ $this->getIo()->error($e->getMessage());
return 1;
}
- $this->restoreSitesFile($io);
+ $this->restoreSitesFile();
return 0;
}
* install files to be placed directly under /sites instead of the
* appropriate subdir when run from a script and a sites.php file exists.
*
- * @param DrupalStyle $output
- *
* @return boolean
*/
- protected function backupSitesFile(DrupalStyle $output)
+ protected function backupSitesFile()
{
if (!file_exists($this->appRoot . '/sites/sites.php')) {
return true;
$renamed = rename($this->appRoot . '/sites/sites.php', $this->appRoot . '/sites/backup.sites.php');
- $output->info($this->trans('commands.site.install.messages.sites-backup'));
+ $this->getIo()->info($this->trans('commands.site.install.messages.sites-backup'));
return $renamed;
}
/**
* Restores backup.sites.php to sites.php (if needed).
*
- * @param DrupalStyle $output
- *
* @return boolean
*/
- protected function restoreSitesFile(DrupalStyle $output)
+ protected function restoreSitesFile()
{
if (!file_exists($this->appRoot . '/sites/backup.sites.php')) {
return true;
$renamed = rename($this->appRoot . '/sites/backup.sites.php', $this->appRoot . '/sites/sites.php');
- $output->info($this->trans('commands.site.install.messages.sites-restore'));
+ $this->getIo()->info($this->trans('commands.site.install.messages.sites-restore'));
return $renamed;
}
- protected function runInstaller(
- DrupalStyle $io,
- InputInterface $input,
- $database,
- $uri
- ) {
+ protected function runInstaller($database, $uri) {
+ $input = $this->getIo()->getInput();
$this->site->loadLegacyFile('/core/includes/install.core.inc');
$driver = (string)$database['driver'];
];
if (!$this->site->multisiteMode($uri)) {
- $this->backupSitesFile($io);
+ $this->backupSitesFile();
}
- $io->newLine();
- $io->info($this->trans('commands.site.install.messages.installing'));
+ $this->getIo()->newLine();
+ $this->getIo()->info($this->trans('commands.site.install.messages.installing'));
try {
$autoload = $this->site->getAutoload();
install_drupal($autoload, $settings);
} catch (AlreadyInstalledException $e) {
- $io->error($this->trans('commands.site.install.messages.already-installed'));
+ $this->getIo()->error($this->trans('commands.site.install.messages.already-installed'));
return 1;
} catch (\Exception $e) {
- $io->error($e->getMessage());
+ $this->getIo()->error($e->getMessage());
return 1;
}
if (!$this->site->multisiteMode($uri)) {
- $this->restoreSitesFile($io);
+ $this->restoreSitesFile();
}
- $io->success($this->trans('commands.site.install.messages.installed'));
+ $this->getIo()->success($this->trans('commands.site.install.messages.installed'));
return 0;
}