Problem/Motivation

Working on core requires almost certainly drush or console to make it easy to reinstall the site or just install/uninstall a specific module.
At the same time, it became hard to install drush/console globally, for good reasons. They need to sync up the dependencies with core, especially when you switch from 8.3.x to 8.4.x for example.

Proposed resolution

Given that I propose to ship with command line applications for the following three tasks, which are helpful for developing on core. Note the difference to a general command line application useful for working on actual sites.

  1. Install drupal
  2. Install/uninstall a module
  3. Rebuild all caches

This proposal is designed to be limited in scope: Not a generic framework for commands, no discovery method ...
https://symfony.com/doc/current/components/console/single_command_tool.html or http://robo.li/ might help here.

Remaining tasks

  • Agree that this is useful
  • Ensure that we limit the scope
  • Sign off
  • Implement it
  • Get it in

User interface changes

API changes

Data model changes

Issue fork drupal-2894476

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dawehner created an issue. See original summary.

larowlan’s picture

Makefile

dawehner’s picture

@larowlan
Do you mind to elaborate a bit? What do you mean exactly with that.

larowlan’s picture

berdir’s picture

Such a makefile is just a neat way of storing aliases.

The point of this issue is to have core offer a replacement for drush en some_module (for example) that doesn't actually require drush. A Makefile isn't going to help here as you need something to bootstrap Drupal and call the module installer with the provided argument. Your makefile could just offer a shorter way of calling that command then although it should be as simple as ./scripts/enable-module views.

larowlan’s picture

right, I've missed the point then - carry on :)

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mradcliffe’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new3.16 KB

Here's the start of a patch that adds an optional db-url option to the wonderful install command that's already done. The default is the current sqlite usage.

Probably this should be split into an issue for each command. I couldn't find another issue that is more recent.

My reason to come back to this is that it's getting hard to juggle local drush/console and core development for novice contributors. I think this would help a lot to simplify quicksprint tools. In that use case, the environment is setup already and a script runs commands for the user to install the site (requested by mentors that novices have the environment with Drupal already installed).

mradcliffe’s picture

Status: Needs review » Needs work

Back to needs work because it's not complete even though it passes current tests.

+++ b/core/lib/Drupal/Core/Command/InstallCommand.php
@@ -51,6 +51,7 @@ protected function configure() {
+      ->addOption('db-url', NULL, InputOption::VALUE_OPTIONAL, 'Set the database to use for the install. This is an advanced option suitable for Drupal core development.', 'sqlite://localhost/files/.sqlite')

Should be sqlite://localhost/.sqlite as site path will get prefixed anyway.

prabha1997’s picture

Assigned: Unassigned » prabha1997

I am working on this issue

prabha1997’s picture

Assigned: prabha1997 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.04 KB
new3.15 KB
mradcliffe’s picture

StatusFileSize
new3.26 KB

I re-rolled #15 because I wasn't able to apply the patch on 8.9.x anymore. I'm going to try to work on a test for this today.

mradcliffe’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Command/InstallCommand.php
@@ -51,6 +51,7 @@ protected function configure() {
+      ->addOption('db-url', NULL, InputOption::VALUE_OPTIONAL, 'Set the database to use for the install. This is an advanced option suitable for Drupal core development.', 'sqlite://localhost/.sqlite')

Looking at how we would be able to get a test written. I think that db-url is probably not the right parameter name because it does not give a chance to add prefix.

I think there was a movement to get rid of db urls in general so it probably wouldn't make sense to introduce it here.

A JSON string isn't really usable so I guess multiple options for

driver, user, password, port, host, database name and prefix.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

mradcliffe’s picture

Status: Needs work » Needs review
StatusFileSize
new6.09 KB
new5.96 KB

I updated the patch to splits db-url option into the parts that can be set in the core installer tasks form. I'm getting 1 fail locally so flipping to Needs review to see if I can replicate on the testbot and then back to Needs work if it passes.

I tried to refactor QuickStartTest::tearDown per the @todo in #2926633: Provide a script to install a Drupal testsite for writing a InstallCommandTestBase that could test each core driver functionally, but I didn't get too far.

@xjm suggested creating issues for each common command in #3089277: Provide core CLI commands for the most common features of Drush (#36) so maybe just focusing on quick-start / install refactor and additional tests would be good scope for this issue? Most of the commands are implemented with the separate console app in #2242947: Integrate Symfony Console component to natively support command line operations.

mradcliffe’s picture

Status: Needs review » Needs work

Mysql and Sqlite don't have any test regressions though on the testbot, yay. Back to Needs work for tests.

mradcliffe’s picture

Status: Needs work » Needs review
StatusFileSize
new12.95 KB
new7.28 KB

It looks like I couldn't instantiate and run the TestSiteApplication class directly without phpunit AbstractPhpProcess dying. I followed the only usage in core by running test-site.php in a separate process.

This patch refactors QuickStartTest to use new InstallCommandTestBase base test class.

mradcliffe’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Command/InstallCommand.php
    @@ -50,9 +50,17 @@ protected function configure() {
    +      ->addOption('database-driver', 'db-driver', InputOption::VALUE_REQUIRED, 'Sets the database driver to use.', 'sqlite')
    +      ->addOption('database-username', 'db-user', InputOption::VALUE_REQUIRED, 'Sets the database user.', '')
    +      ->addOption('database-password', 'db-pass', InputOption::VALUE_REQUIRED, 'Sets the database password.', '')
    +      ->addOption('database-host', 'db-host', InputOption::VALUE_REQUIRED, 'Sets the database host name.', 'localhost')
    +      ->addOption('database-port', 'db-port', InputOption::VALUE_REQUIRED, 'Sets the database port.', '')
    +      ->addOption('database-name', 'db-name', InputOption::VALUE_REQUIRED, 'Sets the database to use either a database name or file path.', 'drupal')
    +      ->addOption('database-prefix', 'db-prefix', InputOption::VALUE_REQUIRED, 'Sets an optional database prefix.', '')
    

    Shortcuts are short options, not aliases. Maybe just leave NULL for now since there are a lot of short options to come up with letters and numbers for.

  2. +++ b/core/lib/Drupal/Core/Command/InstallCommand.php
    @@ -141,9 +169,16 @@ protected function install($class_loader, SymfonyStyle $io, $profile, $langcode,
    +            'advanced_options' => [
    ...
    +            ],
    

    Form name is collapsed as "DRIVER[host]" not "DRIVER[advanced_options][host]".

mradcliffe’s picture

Status: Needs work » Needs review
StatusFileSize
new18.49 KB
new8.56 KB

- Added a basic install command tests for mysql and pgsql drivers.
- Fixed issues in #23.

Need to add functional tests to assert error messages returned from missing or bad options.

mradcliffe’s picture

StatusFileSize
new18.59 KB
new1.56 KB
+++ b/core/tests/Drupal/Tests/Core/Command/InstallMysqlCommandTest.php
@@ -0,0 +1,83 @@
+ * @requires extension pdo_mysql

+++ b/core/tests/Drupal/Tests/Core/Command/InstallPgsqlCommandTest.php
@@ -0,0 +1,83 @@
+ * @requires extension pdo_pgsql

I guess this fails the test rather than skipping it. Maybe should change to an extension_loaded check?

The last submitted patch, 24: 2894476-24.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 25: 2894476-25.patch, failed testing. View results

mradcliffe’s picture

Status: Needs work » Needs review
StatusFileSize
new15.75 KB
new8.11 KB

Maybe instead of making multiple (skipped) tests for each driver, it should just be one test and our test infrastructure ensures it works for each core driver...

It looks like I forgot to pass in host. That'll be a good negative test case to add.

Status: Needs review » Needs work

The last submitted patch, 28: 2894476-28.patch, failed testing. View results

mradcliffe’s picture

Status: Needs work » Needs review
StatusFileSize
new15.8 KB
new1.13 KB

This should resolve getting the test started on drupalci.

Status: Needs review » Needs work

The last submitted patch, 30: 2894476-30.patch, failed testing. View results

mradcliffe’s picture

Status: Needs work » Needs review
StatusFileSize
new20.09 KB
new6.49 KB

I'm not sure why it's getting stock on the language page. This isn't happening on the quick start test though quick-start is always passing in langcode. However, I was able to reproduce the test failure locally and passing langcode didn't help. It doesn't seem to be an issue with the InputOption::VALUE_OPTIONAL (which should be VALUE_REQUIRED because an input options are always optional and that state means that langcode _could_ be NULL if --langcode is provided). But despite all of that the test is still getting stuck on the Choose language page.

I also added a second test to test Spanish in order to expand the test coverage.

Both are probably going to fail at the language page, but QuickStartTest still succeeds (probably because the wrapped command passes langcode as an InputArray?).

Status: Needs review » Needs work

The last submitted patch, 32: 2894476-32.patch, failed testing. View results

mradcliffe’s picture

  1. +++ b/core/tests/Drupal/Tests/Core/Command/InstallCommandTest.php
    @@ -0,0 +1,149 @@
    +    $base_url = getenv('SIMPLETEST_BASE_URL');
    ...
    +    define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
    ...
    +    $response = $guzzle->get($base_url, ['cookies' => $cookieJar]);
    ...
    +    $base_url = getenv('SIMPLETEST_BASE_URL');
    ...
    +    define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
    ...
    +    $response = $guzzle->get($base_url, ['cookies' => $cookieJar]);
    

    I had figured that the installer wasn't working at all, but it was, and the request redirected to the install page because it didn't detect a valid install.

    Removing the tearDown reveals a valid site that works when doing ln -s sites/simpletest/MY_PREFIX/settings.php sites/default/settings.php

    So something mus tbe wrong with the base url used or detecting that the site should use a the test database.

  2. +++ b/core/tests/Drupal/Tests/Core/Command/InstallCommandTestBase.php
    @@ -0,0 +1,87 @@
    +        $command_line = $this->php . ' core/scripts/test-site.php tear-down ' . $prefix . ' --db-url "' . $db_url . '" --keep-lock';
    
    +++ b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php
    @@ -23,63 +19,13 @@
    -        // @todo use the tear down command from
    -        //   https://www.drupal.org/project/drupal/issues/2926633
    

    A consequence of this change is that run-tests.sh --keep-results and --die-on-fail are no longer viable as the tearDown method will remove the site.

mradcliffe’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new15.14 KB
new18.11 KB

Patch no longer applies. After I re-rolled, I stumbled across the misnamed QuickStartTestBase and the BuildTests test suite. If we write the install command tests based on that test suite, then we won't need to worry about as much cleanup! Unfortunately (and ironically) QuickStartTest can't be migrated to use QuickStartTestBase because BuildTests creates a php server on its own. It might be worth it to do it as a follow-up. I reverted that part of #32, and focused soley on InstallCommandTest.

Note that despite its name QuickStartTestBase only uses the install command and not the quick-start command. I changed the documentation to be less confusing.

mradcliffe’s picture

  1. +++ b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
    @@ -302,21 +302,25 @@ public function assertCommandExitCode($expected_code) {
    -   * @param string $working_dir
    +   * @param null $working_dir
    

    PhpStorm autocorrected this incorrectly, and it should be reverted :(

  2. +++ b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
    @@ -302,21 +302,25 @@ public function assertCommandExitCode($expected_code) {
    +  public function executeCommand($command_line, $working_dir = NULL, $timeout = 300, $idleTimeout = 300) {
    ...
    -      ->setTimeout(300)
    -      ->setIdleTimeout(300);
    +      ->setTimeout($timeout)
    +      ->setIdleTimeout($idleTimeout);
    

    I was going to bump the timeout of the process, but it looks like things are passing for me locally.

    This probably can be reverted or maybe put into use?

mradcliffe’s picture

This patch removes changes from BuildTestBase, moves the pdo_sqlite extension requirement into the QuickStart command rather than the InstallCommand, and adds InstallCommandTest coverage for site already installed. I removed the explicit langcode option as it should come across as the default option for InstallCommand.

Status: Needs review » Needs work

The last submitted patch, 37: drupal-install-command-2894476-37.patch, failed testing. View results

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

+++ b/core/tests/Drupal/BuildTests/QuickStart/QuickStartTestBase.php
@@ -6,7 +6,7 @@
- * Helper methods for using the quickstart feature of Drupal.
+ * Helper methods for using the install feature of Drupal.

@@ -25,7 +25,7 @@ abstract class QuickStartTestBase extends BuildTestBase {
-   * Install a Drupal site using the quick start feature.
+   * Installs a Drupal site using the install feature.

this kind of fixes better off to separate issue

yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new152.12 KB
new15.31 KB
new2.31 KB

Addressed nitpicks mentioned in #40 & resolved custom commands failures in provided patch

Status: Needs review » Needs work

The last submitted patch, 41: 2894476-41.patch, failed testing. View results

mradcliffe’s picture

+++ b/core/tests/Drupal/BuildTests/Core/Command/InstallCommandTest.php
@@ -119,8 +119,8 @@ public function testInstallWithLangcode() {
-      '--langcode=es',
-      "--site-name='Prueba del Sitio {$this->testDb->getDatabasePrefix()}'",
+      '--langcode=en',
+      "--site-name='Test site {$this->testDb->getDatabasePrefix()}'",

@@ -135,11 +135,11 @@ public function testInstallWithLangcode() {
-    $this->assertErrorOutputContains('¡Enhorabuena, ha instalado Drupal!');
+    $this->assertErrorOutputContains('Congratulations, you installed Drupal!');
...
-    $this->assertStringContainsString('Prueba del Sitio ' . $this->testDb->getDatabasePrefix(), $content);
+    $this->assertStringContainsString('Test site ' . $this->testDb->getDatabasePrefix(), $content);

This isn't right. We do want to test the install in a different language using a non-default langcode. This should be reverted.

The major issue with the patch is that test classes don't create an environment correctly and the test environment is mutated.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mradcliffe’s picture

Issue tags: +Portland2022

Hiding patches after opening merge request.

Applied a suggestion from @Mile23.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

mradcliffe’s picture

Title: Provide commands which are helpful for core development » [PP-1] Provide commands which are helpful for core development
Status: Needs work » Postponed
Related issues: +#3453474: CLI entry point in Drupal Core

I think this should be postponed on #3453474: CLI entry point in Drupal Core, and possibly closed as duplicate in favor of multiple issues per command to reduce scope.

mradcliffe’s picture

Status: Postponed » Closed (outdated)

Closing as outdated. Some of the work on the install refactor I did probably can be used in a child issue of #3582246: [meta] CLI in Core community initiative.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.