Loading
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 sameinstall_taskandinstall_timestate rule asinstall_begin_request(). A site whose install stopped partway through is not installed. Database errors are thrown to the caller. Its docblock andinstallationAttempted()'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,ServerCommandandInstallerRedirectTrait::shouldRedirectToInstaller()use the new method.InstallCommandandServerCommandcheck before booting the kernel.- A crashed install now resumes with
dr installinstead of reporting "Drupal is already installed", and a web request on one redirects to the installer. - New
DrupalApplication::getSitePath(), shared bybootstrap()and the new command.
Testing instructions
- In a project without an installed site, run
vendor/bin/dr is-installed; echo $?. It prints "Drupal is not installed." and1. - Run
vendor/bin/dr install minimal, then step 1 again. It prints "Drupal is installed." and0. - Run
vendor/bin/dr site:installed --quiet; echo $?. It prints only0. - Simulate a crashed install by setting the
install_taskstate value to another task and deletinginstall_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." and1, andvendor/bin/dr install minimalfinishes the install. - Make the database unreadable (for SQLite,
chmod 000 sites/default/files/.sqlite) and run step 1 again. It prints an error and2.
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.
Edited by Dave Reid