-
-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logic to enable multisite installation (#3022)
* Add logic to enable multisite installation * Enable multisite command if Drupal is not installed
- Loading branch information
1 parent
328e0b8
commit 41da31c
Showing
4 changed files
with
86 additions
and
26 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
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; | ||
|
@@ -25,6 +26,7 @@ | |
use Drupal\Console\Utils\Site; | ||
use DrupalFinder\DrupalFinder; | ||
|
||
|
||
class InstallCommand extends Command | ||
{ | ||
use ContainerAwareCommandTrait; | ||
|
@@ -370,6 +372,19 @@ function ($profile) { | |
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$io = new DrupalStyle($input, $output); | ||
$uri = parse_url($input->getParameterOption(['--uri', '-l']) ?: 'default', PHP_URL_HOST); | ||
|
||
if($this->site->multisiteMode($uri)) { | ||
if(!$this->site->validMultisite($uri)) { | ||
$io->error( | ||
sprintf($this->trans('commands.site.install.messages.invalid-multisite'), $uri, $uri) | ||
); | ||
exit(1); | ||
} | ||
|
||
// Modify $_SERVER environment information to enable the Drupal installer use multisite configuration. | ||
$_SERVER['HTTP_HOST'] = $uri; | ||
} | ||
|
||
// Database options | ||
$dbType = $input->getOption('db-type')?:'mysql'; | ||
|
@@ -417,15 +432,15 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
} | ||
} | ||
|
||
$this->backupSitesFile($io); | ||
|
||
try { | ||
$this->runInstaller($io, $input, $database); | ||
|
||
$drupalFinder = new DrupalFinder(); | ||
$drupalFinder->locateRoot(getcwd()); | ||
$composerRoot = $drupalFinder->getComposerRoot(); | ||
$drupalRoot = $drupalFinder->getDrupalRoot(); | ||
|
||
$this->runInstaller($io, $input, $database, $uri); | ||
|
||
$autoload = $this->container->get('class_loader'); | ||
$drupal = new Drupal($autoload, $composerRoot, $drupalRoot); | ||
$container = $drupal->boot(); | ||
|
@@ -478,15 +493,18 @@ protected function restoreSitesFile(DrupalStyle $output) | |
protected function runInstaller( | ||
DrupalStyle $io, | ||
InputInterface $input, | ||
$database | ||
) { | ||
$database, | ||
$uri | ||
) | ||
{ | ||
$this->site->loadLegacyFile('/core/includes/install.core.inc'); | ||
|
||
$driver = (string) $database['driver']; | ||
$driver = (string)$database['driver']; | ||
|
||
$settings = [ | ||
'parameters' => [ | ||
'profile' => $input->getArgument('profile')?:'standard', | ||
'langcode' => $input->getOption('langcode')?:'en', | ||
'profile' => $input->getArgument('profile') ?: 'standard', | ||
'langcode' => $input->getOption('langcode') ?: 'en', | ||
], | ||
'forms' => [ | ||
'install_settings_form' => [ | ||
|
@@ -495,26 +513,30 @@ protected function runInstaller( | |
'op' => 'Save and continue', | ||
], | ||
'install_configure_form' => [ | ||
'site_name' => $input->getOption('site-name')?:'Drupal 8', | ||
'site_mail' => $input->getOption('site-mail')?:'[email protected]', | ||
'site_name' => $input->getOption('site-name') ?: 'Drupal 8', | ||
'site_mail' => $input->getOption('site-mail') ?: '[email protected]', | ||
'account' => [ | ||
'name' => $input->getOption('account-name')?:'admin', | ||
'mail' => $input->getOption('account-mail')?:'[email protected]', | ||
'name' => $input->getOption('account-name') ?: 'admin', | ||
'mail' => $input->getOption('account-mail') ?: '[email protected]', | ||
'pass' => [ | ||
'pass1' => $input->getOption('account-pass')?:'admin', | ||
'pass2' => $input->getOption('account-pass')?:'admin' | ||
'pass1' => $input->getOption('account-pass') ?: 'admin', | ||
'pass2' => $input->getOption('account-pass') ?: 'admin' | ||
], | ||
], | ||
'update_status_module' => [ | ||
1 => true, | ||
2 => true, | ||
], | ||
'clean_url' => true, | ||
'clean_url' => true, | ||
'op' => 'Save and continue', | ||
], | ||
] | ||
]; | ||
|
||
if (!$this->site->multisiteMode($uri)) { | ||
$this->backupSitesFile($io); | ||
} | ||
|
||
$io->newLine(); | ||
$io->info($this->trans('commands.site.install.messages.installing')); | ||
|
||
|
@@ -529,6 +551,10 @@ protected function runInstaller( | |
return; | ||
} | ||
|
||
if (!$this->site->multisiteMode($uri)) { | ||
$this->restoreSitesFile($io); | ||
} | ||
|
||
$io->success($this->trans('commands.site.install.messages.installed')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters