WordPress.org

Make WordPress Core

Opened 3 months ago

#53480 new enhancement

Existing config files lost when installing local-env

Reported by: iandunn Owned by:
Milestone: Awaiting Review Priority: low
Severity: normal Version:
Component: Build/Test Tools Keywords:
Focuses: Cc:

Description

Problem

npm run env:install overwrites existing wp-config.php and wp-tests-config.php files without warning. Those files aren't versioned, so they have to be restored from a local backup, if one exists.

That makes sense in hindsight, but it wasn't obvious to me before running the command.

I normally use a local nginx/php/mysql stack (via homebrew), but the unit tests don't work locally because I'm running PHP 8 (#46149), so I wanted to use local-env to run the tests. Running the install broke my normal environment, but luckily I had a backup.

Even if someone is only using local-env, they may have changes they want to preserve between installs. e.g., if they re-install to try and fix something that's not working.

Potential solution: manual intervention

One approach would be to remove the --force param when creating wp-config.php, so WP-CLI errors out. Folks could then manually backup/remove the file and run the command again.

For wp-tests-config.php, the install script could check if the file exists before creating it, and abort with a warning if it does.

That won't affect contributors installing for the first time.

Potential solution: automatic backups

To avoid manual intervention, another approach would be to rename existing files to wp-config.php.backup1, wp-config.php.backup2, so that each version is preserved.

Potential solution: prompt before running

A simpler solution might be to just print a warning to the console at the start of the script, and prompt the user to continue. That'd introduce unnecessary friction for new contributors, though.

At the very least, though, I think there should be a warning in the README.

Change History (0)

Note: See TracTickets for help on using tickets.