Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat(db): refine WP_CLI_MYSQLDUMP handling and logging
  • Loading branch information
manhphuc committed Dec 10, 2025
commit b3bfe0c4e152b0568f69bdff36082cb02094e25b
52 changes: 35 additions & 17 deletions php/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@
// Get curl error code safely - only if curl is available and handle is valid.
$curl_errno = null;
if ( function_exists( 'curl_errno' ) && ( is_resource( $curl_handle ) || ( is_object( $curl_handle ) && $curl_handle instanceof \CurlHandle ) ) ) {
$curl_errno = curl_errno( $curl_handle );

Check failure on line 908 in php/utils.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

Parameter #1 $handle of function curl_errno expects CurlHandle, CurlHandle|resource given.
}
// CURLE_SSL_CACERT = 60
$is_ssl_cacert_error = null !== $curl_errno && 60 === $curl_errno;
Expand All @@ -927,7 +927,7 @@
// Get curl error code safely - only if curl is available and handle is valid.
$curl_errno = null;
if ( function_exists( 'curl_errno' ) && ( is_resource( $curl_handle ) || ( is_object( $curl_handle ) && $curl_handle instanceof \CurlHandle ) ) ) {
$curl_errno = curl_errno( $curl_handle );

Check failure on line 930 in php/utils.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

Parameter #1 $handle of function curl_errno expects CurlHandle, CurlHandle|resource given.
}
// CURLE_SSL_CONNECT_ERROR = 35, CURLE_SSL_CERTPROBLEM = 58, CURLE_SSL_CACERT_BADFILE = 77
$is_ssl_error = null !== $curl_errno && in_array( $curl_errno, [ 35, 58, 77 ], true );
Expand Down Expand Up @@ -2058,34 +2058,52 @@
// Honour explicit override when provided.
if ( is_string( $env ) && '' !== $env ) {

// Command name override: allow system PATH resolution.
if ( ! is_path_absolute( $env ) ) {
WP_CLI::debug(
sprintf(
'Using dump command from WP_CLI_MYSQLDUMP via PATH: %s',
$env
),
'db'
);

return $env;
}

// Absolute path override: only trust when executable.
if ( is_path_absolute( $env ) ) {
if ( is_executable( $env ) ) {
WP_CLI::debug( sprintf(
if ( is_executable( $env ) ) {
WP_CLI::debug(
sprintf(
'Using dump command from WP_CLI_MYSQLDUMP: %s',
$env
), 'db' );

return $env;
}
} else {
// Command name override: allow system PATH resolution.
WP_CLI::debug( sprintf(
'Using dump command from WP_CLI_MYSQLDUMP via PATH: %s',
$env
), 'db' );
),
'db'
);

return $env;
}
Comment thread
swissspidy marked this conversation as resolved.

// Absolute path but not executable → log skip so users know why it was ignored.
WP_CLI::debug(
sprintf(
'Ignoring non-executable dump command from WP_CLI_MYSQLDUMP: %s',
$env
),
'db'
);
}

// Fallback: detect DB type and choose the appropriate default binary.
$binary = ( 'mariadb' === get_db_type() ) ? 'mariadb-dump' : 'mysqldump';

WP_CLI::debug( sprintf(
'Final MySQL command: %s',
$binary
), 'db' );
WP_CLI::debug(
sprintf(
'Using default dump command: %s',
$binary
),
'db'
);

return $binary;
}
Expand Down
Loading