feat: #3641324 Add a way for dr to report whether Drupal is installed

Description

Adds a dr site:installed command, with the alias is-installed, so scripts can check whether Drupal is installed before it boots.

Issue: https://www.drupal.org/project/drupal/issues/3641324

  • New InstallerKernel::isSiteInstalled(?Connection $connection = NULL): bool: TRUE when the current site's settings.php has connection info and the installer finished, by the same install_task and install_time state rule as install_begin_request(). A site whose install stopped partway through is not installed. Database errors are thrown to the caller. Its docblock and installationAttempted()'s say when to use each.
  • New default command site:installed (is-installed): exits 0 when installed, 1 when not installed, and 2 when the database can't be checked. It does not boot the kernel.
  • InstallCommand, ServerCommand and InstallerRedirectTrait::shouldRedirectToInstaller() use the new method. InstallCommand and ServerCommand check before booting the kernel.
  • A crashed install now resumes with dr install instead of reporting "Drupal is already installed", and a web request on one redirects to the installer.
  • New DrupalApplication::getSitePath(), shared by bootstrap() and the new command.

Testing instructions

  1. In a project without an installed site, run vendor/bin/dr is-installed; echo $?. It prints "Drupal is not installed." and 1.
  2. Run vendor/bin/dr install minimal, then step 1 again. It prints "Drupal is installed." and 0.
  3. Run vendor/bin/dr site:installed --quiet; echo $?. It prints only 0.
  4. Simulate a crashed install by setting the install_task state value to another task and deleting install_time (for SQLite: sqlite3 sites/default/files/.sqlite "UPDATE key_value SET value = 's:23:\"install_profile_modules\";' WHERE collection = 'state' AND name = 'install_task'; DELETE FROM key_value WHERE collection = 'state' AND name = 'install_time'"). Step 1 prints "Drupal is not installed." and 1, and vendor/bin/dr install minimal finishes the install.
  5. Make the database unreadable (for SQLite, chmod 000 sites/default/files/.sqlite) and run step 1 again. It prints an error and 2.

Remaining tasks

  • Review the command name and exit codes.
  • Change record.

AI disclosure

Generated with the help of an LLM.

Claude Code wrote the code and tests from a plan I directed: the separate command, its name and alias, where the shared method lives, and that it should catch installs that crashed partway through. I checked the exit codes by hand in DDEV, and ran the new kernel test, InstallerRedirectTraitTest, the QuickStart build tests, phpcs, phpstan and CSpell locally.

🤖 Generated with Claude Code

Edited by Dave Reid

Merge request reports

Loading
Loading