Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a function to get the multisite name #4186

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/services/multisite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ services:
- { name: drupal.command }
console.multisite_update:
class: Drupal\Console\Command\Multisite\UpdateCommand
arguments: ['@app.root']
arguments: ['@app.root', '@console.site']
tags:
- { name: drupal.command }
4 changes: 2 additions & 2 deletions src/Command/Generate/ModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Check that it is an absolute path or otherwise create an absolute path using appRoot
$modulePath = $input->getOption('module-path');
if(is_null($modulePath)) {
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
$uri = $this->site->getMultisiteName($input);
$defaultModulePath = 'modules/custom';
$modulePath = $this->site->multisiteMode($uri)? 'sites/'.$this->site->getMultisiteDir($uri).'/'.$defaultModulePath : $defaultModulePath;
}
Expand Down Expand Up @@ -315,7 +315,7 @@ function ($machine_name) use ($validator) {

$modulePath = $input->getOption('module-path');
if (!$modulePath) {
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
$uri = $this->site->getMultisiteName($input);
$defaultModulePath = 'modules/custom';
$modulePath = $this->getIo()->ask(
$this->trans('commands.generate.module.questions.module-path'),
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Generate/ThemeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Check that it is an absolute path or otherwise create an absolute path using appRoot
$theme_path = $input->getOption('theme-path');
if(is_null($theme_path)) {
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
$uri = $this->site->getMultisiteName($input);
$defaultThemePath = 'themes/custom';
$theme_path = $this->site->multisiteMode($uri)? 'sites/'.$this->site->getMultisiteDir($uri).'/'.$defaultThemePath : $defaultThemePath;
}
Expand Down Expand Up @@ -291,7 +291,7 @@ function ($machine_name) {

$theme_path = $input->getOption('theme-path');
if (!$theme_path) {
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
$uri = $this->site->getMultisiteName($input);
$defaultThemePath = 'themes/custom';
$theme_path = $this->getIo()->ask(
$this->trans('commands.generate.theme.questions.theme-path'),
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Generate/ThemeSettingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$theme = $this->validator->validateModuleName($input->getOption('theme'));
$theme_path = $input->getOption('theme-path');
if (is_null($theme_path)) {
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
$uri = $this->site->getMultisiteName($input);
$defaultThemePath = 'themes/custom';
$theme_path = $this->site->multisiteMode($uri)? 'sites/'.$this->site->getMultisiteDir($uri).'/'.$defaultThemePath : $defaultThemePath;
}
$theme_path = Path::isAbsolute($theme_path) ? $theme_path : Path::makeAbsolute($theme_path, $this->appRoot);
$theme_path = $this->validator->validateModulePath($theme_path, true);

$favicon = $input->getOption('favicon');
$commentUserPicture = $input->getOption('comment-user-picture');
$commentUserVerification = $input->getOption('comment-user-verification');
Expand Down
14 changes: 11 additions & 3 deletions src/Command/Multisite/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Drupal\Console\Command\Multisite;

use Drupal\Console\Core\Command\Command;
use Drupal\Console\Utils\Site;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -23,14 +24,21 @@ class UpdateCommand extends Command
{
protected $appRoot;

/**
* @var Site
*/
protected $site;

/**
* DebugCommand constructor.
*
* @param $appRoot
* @param Site $site
*/
public function __construct($appRoot)
public function __construct($appRoot, Site $site)
{
$this->appRoot = $appRoot;
$this->site = $site;
parent::__construct();
}

Expand Down Expand Up @@ -81,7 +89,7 @@ public function configure()
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$this->uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
$this->uri = $this->site->getMultisiteName($input);

$sites = $this->getMultisite($this->uri);
if ($this->uri == "default") {
Expand Down Expand Up @@ -113,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->fs = new Filesystem();

if (empty($this->uri)) {
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
$uri = $this->site->getMultisiteName($input);
$sites = $this->getMultisite($uri);
$this->uri = $sites[$uri];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Site/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function ($profile) {
if ($dbType === 'sqlite') {
// --db-file option
if (!$input->getOption('db-file')) {
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
$uri = $this->site->getMultisiteName($input);
$uriPath = $this->site->multisiteMode($uri) ? $this->site->getMultisiteDir($uri) : 'default';
$dbFile = $this->getIo()->ask(
$this->trans('commands.migrate.execute.questions.db-file'),
Expand Down Expand Up @@ -383,7 +383,7 @@ function ($profile) {
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
$uri = $this->site->getMultisiteName($input);

if ($this->site->multisiteMode($uri)) {
if (!$this->site->validMultisite($uri)) {
Expand Down
15 changes: 15 additions & 0 deletions src/Utils/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ public function getAutoload()
return include $autoLoadFile;
}

/**
* @param InputInterface $input
* @return string
*/
public function getMultisiteName($input)
{
$uri = $input->getParameterOption(['--uri', '-l'], 'default');

if ($uri && !preg_match('/^(http|https):\/\//', $uri)) {
$uri = sprintf('http://%s', $uri);
}

return parse_url($uri, PHP_URL_HOST);
}

/**
* @return boolean
*/
Expand Down