From ca1145751760486f3f40ddf40ce6c6083fdcc252 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 28 Aug 2025 20:16:01 -0400 Subject: [PATCH 1/4] Fix database restore to use mariadb client directly Replace wp-cli database import with mariadb client to avoid SSL connection errors. The mariadb client with --skip-ssl flag properly handles the database connection without requiring SSL certificates. Changes: - Update restore_db function to use mariadb client instead of wp-cli - Add proper stdin handling for SQL dump file import - Add necessary imports for File and Stdio --- wp_cli/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/wp_cli/src/lib.rs b/wp_cli/src/lib.rs index 09b0b923e..ec320a291 100644 --- a/wp_cli/src/lib.rs +++ b/wp_cli/src/lib.rs @@ -1,4 +1,9 @@ -use std::{collections::HashMap, ffi::OsStr, process::Command}; +use std::{ + collections::HashMap, + ffi::OsStr, + fs::File, + process::{Command, Stdio}, +}; mod wp_cli_categories; mod wp_cli_comments; @@ -17,7 +22,19 @@ pub use wp_cli_users::*; const BACKUP_PATH: &str = "/var/www/html/wp-content/dump.sql"; pub fn restore_db() -> std::process::Output { - run_wp_cli_command(["db", "import", BACKUP_PATH]) + Command::new("mariadb") + .arg("--skip-ssl") + .arg("-h") + .arg("database") + .arg("-u") + .arg("wordpress") + .arg("-pwordpress") + .arg("wordpress") + .stdin(Stdio::from( + File::open(BACKUP_PATH).expect("Failed to open backup file"), + )) + .output() + .expect("Failed to restore db") } fn run_wp_cli_command(args: I) -> std::process::Output From 26eace3fdd4f735a14cb83cbc2bb3d46d3c30e9d Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 28 Aug 2025 20:16:47 -0400 Subject: [PATCH 2/4] Improve log output for make test-server command Suppress verbose curl responses during WordPress setup to reduce log clutter while preserving error messages for debugging. Added descriptive echo statements to track setup progress. Changes: - Redirect curl stdout to /dev/null for template creation - Redirect curl stdout to /dev/null for post revision generation - Add progress messages for template and revision setup steps --- scripts/setup-test-site.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/setup-test-site.sh b/scripts/setup-test-site.sh index e019ce0f7..078e296a2 100755 --- a/scripts/setup-test-site.sh +++ b/scripts/setup-test-site.sh @@ -123,15 +123,15 @@ create_test_credentials () { # Trash the post wp post delete "$TRASHED_POST_ID" - # Create a custom template - curl --user "$ADMIN_USERNAME":"$ADMIN_PASSWORD" -H "Content-Type: application/json" -d '{"slug":"INTEGRATION_TEST_CUSTOM_TEMPLATE", "content": "Integration test custom template content"}' http://localhost/wp-json/wp/v2/templates + echo "Creating a custom template for integration tests.." + curl --silent --user "$ADMIN_USERNAME":"$ADMIN_PASSWORD" -H "Content-Type: application/json" -d '{"slug":"INTEGRATION_TEST_CUSTOM_TEMPLATE", "content": "Integration test custom template content"}' http://localhost/wp-json/wp/v2/templates > /dev/null INTEGRATION_TEST_CUSTOM_TEMPLATE_ID="twentytwentyfour//integration_test_custom_template" - # Setup a post with post revisions for integration tests + echo "Setting up a post with 10 revisions for integration tests.." REVISIONED_POST_ID="$(wp post create --post_type=post --post_title=Revisioned_POST_FOR_INTEGRATION_TESTS --porcelain)" for i in {1..10}; do - curl --silent --user "$ADMIN_USERNAME":"$ADMIN_PASSWORD" -H "Content-Type: application/json" -d "{\"content\":\"content_revision_$i\", \"author\": $ADMIN_USER_ID}" "http://localhost/wp-json/wp/v2/posts/$REVISIONED_POST_ID" + curl --silent --user "$ADMIN_USERNAME":"$ADMIN_PASSWORD" -H "Content-Type: application/json" -d "{\"content\":\"content_revision_$i\", \"author\": $ADMIN_USER_ID}" "http://localhost/wp-json/wp/v2/posts/$REVISIONED_POST_ID" > /dev/null done # Generating revisions don't return an id, but since we just created the `REVISIONED_POST_ID`, we can use it to calculate the revision id REVISION_ID_FOR_REVISIONED_POST_ID=$((REVISIONED_POST_ID + 1)) From df9de223f2db7265f03fb0f96222c2612c9808b5 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 28 Aug 2025 20:34:08 -0400 Subject: [PATCH 3/4] Add comments to wp_cli::restore_db --- wp_cli/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wp_cli/src/lib.rs b/wp_cli/src/lib.rs index ec320a291..8872ad5f7 100644 --- a/wp_cli/src/lib.rs +++ b/wp_cli/src/lib.rs @@ -23,13 +23,23 @@ const BACKUP_PATH: &str = "/var/www/html/wp-content/dump.sql"; pub fn restore_db() -> std::process::Output { Command::new("mariadb") + // Disable SSL to avoid connection errors .arg("--skip-ssl") + // Host flag .arg("-h") + // MySQL/MariaDB container hostname .arg("database") + // Username flag .arg("-u") + // Database username .arg("wordpress") - .arg("-pwordpress") + // Password flag + .arg("-p") + // Database password .arg("wordpress") + // Database name to connect to + .arg("wordpress") + // Pipe SQL dump file contents to stdin .stdin(Stdio::from( File::open(BACKUP_PATH).expect("Failed to open backup file"), )) From 34892fc1fd502312543cb0db171354a77e0e9df7 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 28 Aug 2025 20:59:45 -0400 Subject: [PATCH 4/4] Combine password flag in restore_db --- wp_cli/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/wp_cli/src/lib.rs b/wp_cli/src/lib.rs index 8872ad5f7..366c44c32 100644 --- a/wp_cli/src/lib.rs +++ b/wp_cli/src/lib.rs @@ -33,10 +33,8 @@ pub fn restore_db() -> std::process::Output { .arg("-u") // Database username .arg("wordpress") - // Password flag - .arg("-p") // Database password - .arg("wordpress") + .arg("-pwordpress") // Database name to connect to .arg("wordpress") // Pipe SQL dump file contents to stdin