function InstallCommand::execute
Same name in other branches
- 9 core/lib/Drupal/Core/Command/InstallCommand.php \Drupal\Core\Command\InstallCommand::execute()
- 8.9.x core/lib/Drupal/Core/Command/InstallCommand.php \Drupal\Core\Command\InstallCommand::execute()
- 11.x core/lib/Drupal/Core/Command/InstallCommand.php \Drupal\Core\Command\InstallCommand::execute()
File
-
core/
lib/ Drupal/ Core/ Command/ InstallCommand.php, line 64
Class
- InstallCommand
- Installs a Drupal site for local testing/development.
Namespace
Drupal\Core\CommandCode
protected function execute(InputInterface $input, OutputInterface $output) : int {
$io = new SymfonyStyle($input, $output);
if (!extension_loaded('pdo_sqlite')) {
$io->getErrorStyle()
->error('You must have the pdo_sqlite PHP extension installed. See core/INSTALL.sqlite.txt for instructions.');
return 1;
}
// Change the directory to the Drupal root.
chdir(dirname(__DIR__, 5));
// Check whether there is already an installation.
if ($this->isDrupalInstalled()) {
// Do not fail if the site is already installed so this command can be
// chained with ServerCommand.
$output->writeln('<info>Drupal is already installed.</info> If you want to reinstall, remove sites/default/files and sites/default/settings.php.');
return 0;
}
$install_profile_or_recipe = $input->getArgument('install-profile-or-recipe');
if (!$install_profile_or_recipe) {
// User did not provide a recipe or install profile.
$install_profile = $this->selectProfile($io);
}
elseif ($this->validateProfile($install_profile_or_recipe)) {
// User provided an install profile.
$install_profile = $install_profile_or_recipe;
}
elseif ($this->validateRecipe($install_profile_or_recipe)) {
// User provided a recipe.
$recipe = $install_profile_or_recipe;
}
else {
$error_msg = sprintf("'%s' is not a valid install profile or recipe.", $install_profile_or_recipe);
// If it does not look like a path make suggestions based upon available
// profiles.
if (!str_contains('/', $install_profile_or_recipe)) {
$alternatives = [];
foreach (array_keys($this->getProfiles(TRUE, FALSE)) as $profile_name) {
$lev = levenshtein($install_profile_or_recipe, $profile_name);
if ($lev <= strlen($profile_name) / 4 || str_contains($profile_name, $install_profile_or_recipe)) {
$alternatives[] = $profile_name;
}
}
if (!empty($alternatives)) {
$error_msg .= sprintf(" Did you mean '%s'?", implode("' or '", $alternatives));
}
}
$io->getErrorStyle()
->error($error_msg);
return 1;
}
return $this->install($this->classLoader, $io, $install_profile ?? '', $input->getOption('langcode'), $this->getSitePath(), $input->getOption('site-name'), $recipe ?? '');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.