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

[chain] - [multisite:new] [site:install] - Executing chain fails #3197

Closed
brandonratz opened this issue Feb 21, 2017 · 9 comments
Closed

[chain] - [multisite:new] [site:install] - Executing chain fails #3197

brandonratz opened this issue Feb 21, 2017 · 9 comments

Comments

@brandonratz
Copy link

brandonratz commented Feb 21, 2017

Version: Drupal Console (1.0.0-rc16)

Problem

Using command: 'multisite:new' followed by 'site:install' via chain command fails.

Expected behavior

  1. Creates multisite directory
  2. Installs site via multisite uri

Actual Behavior

  1. Creates multisite directory
  2. ERROR: Invalid multisite error

Console Output

 // multisite:new

[OK] The new multisite structure was successfully created at "sites/test.example.com" and is ready for installation.

 // site:install

[ERROR] Invalid multisite, please create multisite using command drupal multisite:new test.example.com
         --site-uri=test.example.com`

Chain file example

commands:
  - command: 'multisite:new'
    options:
        learning: true
        uri: 'http://test.example.com'
    arguments:
        directory: 'test.example.com'
        uri: 'http://test.example.com'
  - command: 'site:install'
    options:
        langcode: en
        db-type: mysql
        db-host: localhost
        db-name: test_example_dev
        db-user: root
        db-pass: root
        db-port: '3306'
        site-name: 'Example Website'
        site-mail: admin@example.org
        account-name: admin
        account-mail: admin@example.org
        account-pass: password
        learning: true
        uri: 'http://test.example.com'
    arguments:
        profile: lightning
@michaellenahan
Copy link
Contributor

Hello there! I met @enzolutions in the sprint room at Drupalcamp Iceland, and asked if there was somehow I could help to get started contributing to DrupalConsole.

He pointed me to this ticket. I'm saying this to warn you I'm a newbie to contributing here ...

I have cloned drupal-console to ~/workspace/drupal-console and the drupal site I am running it from is ~/workspace/drupal.template.

When I run the command with the supplied chain file, I get the following output.

$ cd ~/workspace/drupal.template/.
$ ~/workspace/drupal-console/bin/drupal chain --file=~/workspace/chain.yml --debug
✔ Creating request
➤ Creating Drupal kernel


  [Symfony\Component\Console\Exception\CommandNotFoundException]
  The command "multisite:new" does not exist.

@michaellenahan
Copy link
Contributor

michaellenahan commented Mar 15, 2017

I'm not sure why I'm getting:

The command "multisite:new" does not exist.

After all I can see the multisite:new command in the Repo. (It was added with this PR https://github.com/hechoendrupal/drupal-console/pull/2335/files)

EDIT - it's not properly in the repo any more. A search for "multisite:new" brings up 2 results under translations, and only 1 result in the code itself at src/Command/Multisite/NewCommand.php:58

@brandonratz
Copy link
Author

@michaellenahan Do you have a Drupal codebase you're running this against?

composer create-project \
drupal-composer/drupal-project:8.x-dev \
drupal8.dev \
--prefer-dist \
--no-progress \
--no-interaction

What happens when you run ~/workspace/drupal-console/bin/drupal list

@michaellenahan
Copy link
Contributor

michaellenahan commented Mar 15, 2017

Could it be that there is something missing in the service discovery?

If we look here: https://github.com/hechoendrupal/drupal-console/tree/master/config/services/drupal-console we can not find any multisite.yml --- maybe that is why I am getting the error "command does not exist" ?

I've done a bit of investigation in the git repo.

multisite.yml was deleted here:
41da31c
... and "console.multisite_new" moved to ...
services-drupal-install.yml

... and here:
5a916d6

services-drupal-install.yml was renamed ...

services-drupal-install.yml → uninstall.services.yml

Right now there is a reference to "console.multisite_new" in uninstall.services.yml:23

... still don't know why it's not getting loaded though.

@michaellenahan
Copy link
Contributor

michaellenahan commented Mar 15, 2017

Hi, @brandonratz

"Do you have a Drupal codebase you're running this against?"

Yes, I have done the "composer create-project drupal-composer/drupal-project" thing and named the directory "drupal.template"

"What happens when you run ~/workspace/drupal-console/bin/drupal list"


 [ERROR] The specified database connection is not defined: default                                                      

Drupal Console version 1.0.0-rc16

Usage:
  command [options] [arguments]

Options:
  -h, --help             Display this help message
  -q, --quiet            Do not output any message
  -V, --version          Display this application version
      --ansi             Force ANSI output
      --no-ansi          Disable ANSI output
  -n, --no-interaction   Do not ask any interactive question
  -e, --env[=ENV]        The Environment name [default: "prod"]
      --root[=ROOT]      Define the Drupal root to be used in command execution
      --debug            application.options.debug
      --learning         Generate a verbose code output
  -c, --generate-chain   Shows command options and arguments as yaml output to be used in chain command
  -i, --generate-inline  Shows command options and arguments as inline command
  -d, --generate-doc     Shows command options and arguments as markdown
  -t, --target[=TARGET]  Site name you want to interact with (for local or remote sites)
  -l, --uri=URI          URI of the Drupal site to use (for multi-site environments or when running on an alternate port)
  -y, --yes              Skip confirmation and proceed
  -v|vv|vvv, --verbose   Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about                    Display basic information about Drupal Console project
  chain                    Chain command execution
  check                    System requirement checker
  exec                     Execute an external command.
  help                     Displays help for a command
  init                     Copy configuration files.
  list                     Lists all available commands
 chain
  chain:debug              List available chain files.
 settings
  settings:debug           List user Drupal Console settings.
  settings:set             Change a specific setting value in DrupalConsole config file
 site
  site:debug (sd)          List all known local and remote sites.
  site:new                 Download a new Drupal project
 yaml
  yaml:diff (yd)           Compare two YAML files in order to find differences between them.
  yaml:get:value           Get a value for a specific key in a YAML file.
  yaml:merge (ym)          Merge two or more YAML files in a new YAML file. Latest values are preserved.
  yaml:split (ys)          Split a YAML file using indent as separator criteria
  yaml:unset:key           Unset a YAML key in a YAML file.
  yaml:update:key (yu)     Replace a YAML key in a YAML file.
  yaml:update:value (yuv)  Update a value for a specific key in a YAML file.

 [WARNING] In order to list all of the available commands you should install drupal first.                              

@brandonratz
Copy link
Author

Ahh yes, this because you're not running the command against an initialized Drupal codebase. Sorry some of this is out of my realm of experience but I'll do my best to explain.

Drupal console needs to run as a dependency in your Drupal project. Installation docs are here: https://github.com/hechoendrupal/drupal-console

The project scaffold should look something like this:

./project/composer.json
./project/vendor
./project/console
./project/webroot (drupal codebase)

If you run vendor/drupal/console/bin/drupal list command inside this initialized directory (./project), you should see in addition:

 multisite
  multisite:debug          List all multisites available in system
  multisite:new            Sets up the files for a new multisite install.

If there is a database defined for default with a Drupal site installed, you'll get a myriad of other command options.

@michaellenahan
Copy link
Contributor

michaellenahan commented Mar 16, 2017

Thank you @brandonratz - it was exactly as you said - there was something wrong with my drupal installation - I re-downloaded https://github.com/drupal-composer/drupal-project and was able to see multisite:new in my list.

I was thus able to reproduce the problem you reported in your original post.

The problem is in src/Utils/Site.php:200

if (isset($sites[$uri]) && is_dir($this->appRoot . "/sites/" . $sites[$uri])) {

Specifically: $sites[$uri] is not set.

The reason for this is that $uri has a value of test.example.com, but the $sites array incorrectly has a key of http://test.example.com.

So where was this key incorrectly set?

The problem is with the previous command 'multisite:new'.

src/Command/Multisite/NewCommand.php:162

$sites_file_contents .= "\n\$sites['$uri'] = '$this->directory';";

This is incorrect because this adds the text:

$sites['http://test.example.com'] = 'test.example.com';

... to sites.php.

The correct text in sites.php should be:

$sites['test.example.com'] = 'test.example.com';

So the fix is to change src/Command/Multisite/NewCommand.php:162 to be the following:

$sites_file_contents .= "\n\$sites['$this->directory'] = '$this->directory';";

@michaellenahan
Copy link
Contributor

michaellenahan commented Mar 16, 2017

Pull request is here: #3232

michaellenahan pushed a commit to michaellenahan/drupal-console that referenced this issue Mar 16, 2017
@jmolivas
Copy link
Member

jmolivas commented Apr 8, 2017

Fixed with PR #3232

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

3 participants