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

Multisite Uri Option Not Working? #2002

Closed
58bits opened this issue Mar 8, 2016 · 13 comments
Closed

Multisite Uri Option Not Working? #2002

58bits opened this issue Mar 8, 2016 · 13 comments

Comments

@58bits
Copy link

58bits commented Mar 8, 2016

Great tool, however I'm not sure that -l, or -uri options are working for multisite.

I have a sites directory with 'default' and 'my.site.com'. There is no active settings.php file in 'default'.

I have a sites.php file containing an alias to the 'my.site.com'

However when I try drupal list --uri=http://my.site.com - from the Drupal root, I receive a message saying that "[WARNING] In order to list all of the available commands you should install drupal first."

If I take a copy of the settings.php file from my.site.com, and temporarily place it in the 'default' site directory - drupal console works as expected.

@Anicky
Copy link

Anicky commented Mar 18, 2016

I have the same problem too. However, I don't have a multisite. But, even if there is only one site, I don't use "default" directory for my project.

The problem is in DrupalConsole/src/Helper/DrupalHelper.php.

    /**
     * @return bool
     */
    public function isConnectionInfo()
    {
        $settingsPath = sprintf('%s/%s', $this->root, self::DEFAULT_SETTINGS_PHP);
        if (!file_exists($settingsPath)) {
            return false;
        }
        if (Database::getConnectionInfo()) {
            return true;
        }
        return false;
    }

Instead of looking in the "default" directory, it would check first if there is settings.php in current directory.

@jmolivas
Copy link
Member

jmolivas commented Mar 31, 2016

@58bits Thanks a lot for filing this issue! We'll take a look at it as soon as possible!

@toabi
Copy link

toabi commented Apr 15, 2016

I have the same symptoms when using site:install … it always installs into the default directory, not respecting the sites.php which folder it should use.

@jonpugh
Copy link

jonpugh commented May 15, 2016

@jmolivas this is the issue I talked to you about at DrupalCon.

@mstenta
Copy link

mstenta commented May 16, 2016

I did a little testing, based on the comment by @Anicky above. I confirmed that the isConnectionInfo() method is always looking at sites/default/settings.php, even if you use the --uri parameter with your command.

I am specifically testing with the generate commands, but I would assume that all commands are affected. I did some digging to try to find a solution, but I'm not familiar enough with Symfony Console conventions to know how to pass input parameters to this DrupalHelper class. Is it possible?

As a separate question: I wonder if the generate commands should not require a database connection to work? They are not interacting with the site database, are they? Or perhaps the database connection assumption is so low-level that it would be hard to make an exception for certain commands like that? This can be a separate feature request perhaps... just brainstorming. :-)

@acrolyt
Copy link

acrolyt commented May 25, 2016

We encountered the same issue. Any news here?

@esolitos
Copy link
Contributor

esolitos commented May 25, 2016

I have also encountered this issue so, I'll just drop this here: at the moment I have work around this using a script that symlinks sites/default to the desired local site, it's not a solution, but it saves me quite some time. :)
Ref here: https://github.com/esolitos/drupal-utility/blob/feature/d8-relink-default-site/bin/symlink-default-site

@mstenta
Copy link

mstenta commented May 25, 2016

The workaround mentioned by @esolitos works for a normal Drupal multi-site installation. It does not work for multisites installed via Aegir, however. This is because Aegir takes an extra security precaution and does not store the database credentials in settings.php. See #2263

My workaround for that has been to create a simple settings.php file in the default folder with the actual database credentials hard-coded. This allows Console to find the database... but obviously it only works for one site in the multi-site platform.

@mickaelperrin
Copy link
Contributor

mickaelperrin commented Jun 22, 2016

The adequate settings.php file seems to be found and read during the drupal kernel booting.
I just commented out the test on file settings and got it working on a multisite install.

Why the Database::getConnectionInfo() is not sufficient ?

mickaelperrin added a commit to mickaelperrin/DrupalConsole that referenced this issue Oct 25, 2016
- PB: it looks like the uri parameter is not taken in account anymore and the multisite doesn't work
- FIX: read the uri option and generate a  symfony request accordingly before initializing the drupal container
@mickaelperrin
Copy link
Contributor

mickaelperrin commented Oct 25, 2016

@jmolivas it looks like that since my latest comment, things have been totally reworked. I didn't find anymore the use of the uri option and tried to resolve this issue in the #2850 PR.

jmolivas pushed a commit that referenced this issue Nov 2, 2016
- PB: it looks like the uri parameter is not taken in account anymore and the multisite doesn't work
- FIX: read the uri option and generate a  symfony request accordingly before initializing the drupal container
@mstenta
Copy link

mstenta commented Aug 30, 2017

@mickaelperrin Since #2850 was merged, does that mean that this issue is fixed?

@ao2
Copy link
Contributor

ao2 commented Mar 13, 2018

One issue I found about the the uri option is that it does not affect the site base path, for example, this command returns an unexpected result:

echo "base_path();" | ./vendor/bin/drupal --uri='http://example.net/~ao2/test_site/web' shell

I would expect it to return /~ao2/test_site/web/ but it always returns /.

This is because Drupal::boot() does not take into account the path when setting $_SERVER['REQUEST_URI']insrc/Bootstrap/Drupal.php`.

That is done in src/Command/Test/RunCommand.php BTW, maybe some duplication can be avoided too?

The issue affects also the drupal Url class when creating internal and base URLs.

For some details about why setting the base path correctly is important, look at a similar bug report for Drush: drush-ops/drush#3463

Should I file a separate issue for this base path problem?

@hjuarez20
Copy link
Contributor

hjuarez20 commented May 28, 2019

Hi @ao2, This PR should fix the base path #4064

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests