feat(db): add robust support for WP_CLI_MYSQLDUMP override with fallback handling
This PR improves the SQL dump binary resolution logic used by wp db export.
What this change does
- Adds safe, explicit support for overriding the dump client via the
WP_CLI_MYSQLDUMPenvironment variable. - Correctly handles both:
- absolute executable paths
- plain command names resolved through
PATH
- Ignores invalid or non-executable absolute paths to avoid breaking
wp db export. - Falls back reliably to the appropriate default:
-
mariadb-dumpon MariaDB installs -
mysqldumpotherwise
-
Why this is useful
Many Docker-based or custom server environments provide only one of the dump
clients, or store it in a non-standard location. This update makes wp db export
more predictable and easier to configure across those setups.
Testing
The change was tested in multiple scenarios:
-
Valid absolute override
WP_CLI_MYSQLDUMP=/usr/bin/mysqldump→ export succeeds, correct binary selected. -
Invalid absolute override
Non-existent file → ignored, fallback selected correctly. -
No environment override
MariaDB installation correctly defaults tomariadb-dump.
All scenarios produced valid export files and correct debug messages.
Happy to adjust anything if needed. Thanks for reviewing!
Summary of Changes
Hello @manhphuc, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the wp db export command's ability to locate and utilize the correct SQL dump binary. By introducing support for the WP_CLI_MYSQLDUMP environment variable, it provides users with greater control and flexibility in specifying their preferred dump client. The changes ensure robust handling of various path types, intelligent error recovery for invalid overrides, and reliable fallbacks, making the wp db export functionality more adaptable and predictable across diverse server environments, especially those with non-standard dump client configurations.
Highlights
-
Environment Variable Override: Introduces explicit support for overriding the SQL dump client via the
WP_CLI_MYSQLDUMPenvironment variable, allowing users to specify a custom binary. -
Robust Path Handling: The system now correctly handles both absolute executable paths and plain command names (resolved through
PATH), providing flexibility in how the dump client is specified. -
Intelligent Fallback: Invalid or non-executable absolute paths provided via the environment variable are gracefully ignored, and the system reliably falls back to
mariadb-dumpfor MariaDB installations ormysqldumpotherwise. -
New Helper Function: A new function,
get_mysql_dump_binary(), has been added to encapsulate the logic for determining the appropriate SQL dump binary, improving code organization and maintainability.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.
Codecov Report
:x: Patch coverage is 0% with 33 lines in your changes missing coverage. Please review.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| php/utils.php | 0.00% | 33 Missing :warning: |
:loudspeaker: Thoughts on this report? Let us know!
Thanks for the suggestions! I've applied the refactor to use early returns and added a debug message for the non-executable absolute-path case. I also updated the final log line to clearly indicate that it’s using the default dump command. Let me know if you'd like any further adjustments.