protected function InstallCommand::install in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Command/InstallCommand.php \Drupal\Core\Command\InstallCommand::install()
Installs Drupal with specified installation profile.
Parameters
object $class_loader: The class loader.
\Symfony\Component\Console\Style\SymfonyStyle $io: The Symfony output decorator.
string $profile: The installation profile to use.
string $langcode: The language to install the site in.
string $site_path: The path to install the site to, like 'sites/default'.
string $site_name: The site name.
Return value
int The command exit status.
Throws
\Exception Thrown when failing to create the $site_path directory or settings.php.
1 call to InstallCommand::install()
- InstallCommand::execute in core/
lib/ Drupal/ Core/ Command/ InstallCommand.php - Executes the current command.
File
- core/
lib/ Drupal/ Core/ Command/ InstallCommand.php, line 133
Class
- InstallCommand
- Installs a Drupal site for local testing/development.
Namespace
Drupal\Core\CommandCode
protected function install($class_loader, SymfonyStyle $io, $profile, $langcode, $site_path, $site_name) {
$password = Crypt::randomBytesBase64(12);
$parameters = [
'interactive' => FALSE,
'site_path' => $site_path,
'parameters' => [
'profile' => $profile,
'langcode' => $langcode,
],
'forms' => [
'install_settings_form' => [
'driver' => 'sqlite',
'sqlite' => [
'database' => $site_path . '/files/.sqlite',
],
],
'install_configure_form' => [
'site_name' => $site_name,
'site_mail' => 'drupal@localhost',
'account' => [
'name' => 'admin',
'mail' => 'admin@localhost',
'pass' => [
'pass1' => $password,
'pass2' => $password,
],
],
'enable_update_status_module' => TRUE,
// form_type_checkboxes_value() requires NULL instead of FALSE values
// for programmatic form submissions to disable a checkbox.
'enable_update_status_emails' => NULL,
],
],
];
// Create the directory and settings.php if not there so that the installer
// works.
if (!is_dir($site_path)) {
if ($io
->isVerbose()) {
$io
->writeln("Creating directory: {$site_path}");
}
if (!mkdir($site_path, 0775)) {
throw new \RuntimeException("Failed to create directory {$site_path}");
}
}
if (!file_exists("{$site_path}/settings.php")) {
if ($io
->isVerbose()) {
$io
->writeln("Creating file: {$site_path}/settings.php");
}
if (!copy('sites/default/default.settings.php', "{$site_path}/settings.php")) {
throw new \RuntimeException("Copying sites/default/default.settings.php to {$site_path}/settings.php failed.");
}
}
require_once 'core/includes/install.core.inc';
$progress_bar = $io
->createProgressBar();
install_drupal($class_loader, $parameters, function ($install_state) use ($progress_bar) {
static $started = FALSE;
if (!$started) {
$started = TRUE;
// We've already done 1.
$progress_bar
->setFormat("%current%/%max% [%bar%]\n%message%\n");
$progress_bar
->setMessage(t('Installing @drupal', [
'@drupal' => drupal_install_profile_distribution_name(),
]));
$tasks = install_tasks($install_state);
$progress_bar
->start(count($tasks) + 1);
}
$tasks_to_perform = install_tasks_to_perform($install_state);
$task = current($tasks_to_perform);
if (isset($task['display_name'])) {
$progress_bar
->setMessage($task['display_name']);
}
$progress_bar
->advance();
});
$success_message = t('Congratulations, you installed @drupal!', [
'@drupal' => drupal_install_profile_distribution_name(),
'@name' => 'admin',
'@pass' => $password,
], [
'langcode' => $langcode,
]);
$progress_bar
->setMessage('<info>' . $success_message . '</info>');
$progress_bar
->display();
$progress_bar
->finish();
$io
->writeln('<info>Username:</info> admin');
$io
->writeln("<info>Password:</info> {$password}");
return 0;
}