In a project that contains Drush 9, line 170 of Drupal\config_installer\Form\SiteConfigureForm calls \Drush\Drush::redispatchOptions() but the Drush container is not initialized and Drush ends up throwing a RuntimeException on line 140 of \Drush\Drush.

Everything works fine if I invoke the installation directly from Drush using drush site-install config_installer. I only see this problem if I try to use php core/scripts/drupal install config_installer.

Comments

balsama created an issue. See original summary.

balazswmann’s picture

The problem is caused by composer based projects. If Drush is installed with composer it will be placed into the vendor directory somewhere. Now, the class_exists('\Drush\Drush') check is not suitable in these cases because the autoloader will load the class anyway even if there is no Drush context (the site is being installed through the UI).

The solution is to check the Drush context first (with function_exists('drush_get_option')) and then use \Drush\Utils\StringUtils::generatePassword() or drush_generate_password() according to the specific Drush version.

balazswmann’s picture

Status: Active » Needs review
balazswmann’s picture

By the way, this bug affects not just UI installation but automated testing also. Integration tests which rely on config_installer get stuck in an infinite loop due to the runtime exception.

balazswmann’s picture

Version: 8.x-1.8 » 8.x-1.x-dev
balsama’s picture

StatusFileSize
new2.56 KB
new741 bytes

Thanks! I think we also need an default for the name, pass, and email in case Drush isn't around. This patch just adds that.

alexpott’s picture

@balsama nah we don;'t need the defaults this is about filing in info from drush.

alexpott’s picture

+++ b/src/Form/SiteConfigureForm.php
@@ -164,25 +164,18 @@ class SiteConfigureForm extends FormBase {
+      if (class_exists('\Drush\Utils\StringUtils')) {
+        $form['admin_account']['account']['pass']['#default_value'] = \Drush\Utils\StringUtils::generatePassword();
+      }
+      // Targets Drush 8 or lower.
+      elseif (function_exists('drush_generate_password')) {
+        $form['admin_account']['account']['pass']['#default_value'] = drush_get_option('account-pass', drush_generate_password());
+      }

The drush 9 version also need to use drush_get_option('account-pass', too in-case the user has provided one on the command line.

alexpott’s picture

StatusFileSize
new1.51 KB
new2.18 KB

Like so

alexpott’s picture

Status: Needs review » Fixed

  • alexpott committed 9b65c9b on 8.x-1.x authored by balazswmann
    Issue #2991182 by balazswmann, balsama, alexpott: Using with `core/...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.