Skip to content

Commit b21607f

Browse files
hjuarez20enzolutions
authored andcommitted
Create a function to get the multisite name (#4186)
1 parent 1b806b9 commit b21607f

File tree

7 files changed

+35
-12
lines changed

7 files changed

+35
-12
lines changed

config/services/multisite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ services:
66
- { name: drupal.command }
77
console.multisite_update:
88
class: Drupal\Console\Command\Multisite\UpdateCommand
9-
arguments: ['@app.root']
9+
arguments: ['@app.root', '@console.site']
1010
tags:
1111
- { name: drupal.command }

src/Command/Generate/ModuleCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
199199
// Check that it is an absolute path or otherwise create an absolute path using appRoot
200200
$modulePath = $input->getOption('module-path');
201201
if(is_null($modulePath)) {
202-
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
202+
$uri = $this->site->getMultisiteName($input);
203203
$defaultModulePath = 'modules/custom';
204204
$modulePath = $this->site->multisiteMode($uri)? 'sites/'.$this->site->getMultisiteDir($uri).'/'.$defaultModulePath : $defaultModulePath;
205205
}
@@ -315,7 +315,7 @@ function ($machine_name) use ($validator) {
315315

316316
$modulePath = $input->getOption('module-path');
317317
if (!$modulePath) {
318-
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
318+
$uri = $this->site->getMultisiteName($input);
319319
$defaultModulePath = 'modules/custom';
320320
$modulePath = $this->getIo()->ask(
321321
$this->trans('commands.generate.module.questions.module-path'),

src/Command/Generate/ThemeCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
195195
// Check that it is an absolute path or otherwise create an absolute path using appRoot
196196
$theme_path = $input->getOption('theme-path');
197197
if(is_null($theme_path)) {
198-
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
198+
$uri = $this->site->getMultisiteName($input);
199199
$defaultThemePath = 'themes/custom';
200200
$theme_path = $this->site->multisiteMode($uri)? 'sites/'.$this->site->getMultisiteDir($uri).'/'.$defaultThemePath : $defaultThemePath;
201201
}
@@ -291,7 +291,7 @@ function ($machine_name) {
291291

292292
$theme_path = $input->getOption('theme-path');
293293
if (!$theme_path) {
294-
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
294+
$uri = $this->site->getMultisiteName($input);
295295
$defaultThemePath = 'themes/custom';
296296
$theme_path = $this->getIo()->ask(
297297
$this->trans('commands.generate.theme.questions.theme-path'),

src/Command/Generate/ThemeSettingCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
170170
$theme = $this->validator->validateModuleName($input->getOption('theme'));
171171
$theme_path = $input->getOption('theme-path');
172172
if (is_null($theme_path)) {
173-
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
173+
$uri = $this->site->getMultisiteName($input);
174174
$defaultThemePath = 'themes/custom';
175175
$theme_path = $this->site->multisiteMode($uri)? 'sites/'.$this->site->getMultisiteDir($uri).'/'.$defaultThemePath : $defaultThemePath;
176176
}
177177
$theme_path = Path::isAbsolute($theme_path) ? $theme_path : Path::makeAbsolute($theme_path, $this->appRoot);
178178
$theme_path = $this->validator->validateModulePath($theme_path, true);
179-
179+
180180
$favicon = $input->getOption('favicon');
181181
$commentUserPicture = $input->getOption('comment-user-picture');
182182
$commentUserVerification = $input->getOption('comment-user-verification');

src/Command/Multisite/UpdateCommand.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Drupal\Console\Command\Multisite;
99

1010
use Drupal\Console\Core\Command\Command;
11+
use Drupal\Console\Utils\Site;
1112
use Symfony\Component\Console\Input\InputInterface;
1213
use Symfony\Component\Console\Input\InputOption;
1314
use Symfony\Component\Console\Output\OutputInterface;
@@ -23,14 +24,21 @@ class UpdateCommand extends Command
2324
{
2425
protected $appRoot;
2526

27+
/**
28+
* @var Site
29+
*/
30+
protected $site;
31+
2632
/**
2733
* DebugCommand constructor.
2834
*
2935
* @param $appRoot
36+
* @param Site $site
3037
*/
31-
public function __construct($appRoot)
38+
public function __construct($appRoot, Site $site)
3239
{
3340
$this->appRoot = $appRoot;
41+
$this->site = $site;
3442
parent::__construct();
3543
}
3644

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

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

115123
if (empty($this->uri)) {
116-
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
124+
$uri = $this->site->getMultisiteName($input);
117125
$sites = $this->getMultisite($uri);
118126
$this->uri = $sites[$uri];
119127
}

src/Command/Site/InstallCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function ($profile) {
287287
if ($dbType === 'sqlite') {
288288
// --db-file option
289289
if (!$input->getOption('db-file')) {
290-
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
290+
$uri = $this->site->getMultisiteName($input);
291291
$uriPath = $this->site->multisiteMode($uri) ? $this->site->getMultisiteDir($uri) : 'default';
292292
$dbFile = $this->getIo()->ask(
293293
$this->trans('commands.migrate.execute.questions.db-file'),
@@ -383,7 +383,7 @@ function ($profile) {
383383
*/
384384
protected function execute(InputInterface $input, OutputInterface $output)
385385
{
386-
$uri = parse_url($input->getParameterOption(['--uri', '-l'], 'default'), PHP_URL_HOST);
386+
$uri = $this->site->getMultisiteName($input);
387387

388388
if ($this->site->multisiteMode($uri)) {
389389
if (!$this->site->validMultisite($uri)) {

src/Utils/Site.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ public function getAutoload()
179179
return include $autoLoadFile;
180180
}
181181

182+
/**
183+
* @param InputInterface $input
184+
* @return string
185+
*/
186+
public function getMultisiteName($input)
187+
{
188+
$uri = $input->getParameterOption(['--uri', '-l'], 'default');
189+
190+
if ($uri && !preg_match('/^(http|https):\/\//', $uri)) {
191+
$uri = sprintf('http://%s', $uri);
192+
}
193+
194+
return parse_url($uri, PHP_URL_HOST);
195+
}
196+
182197
/**
183198
* @return boolean
184199
*/

0 commit comments

Comments
 (0)