diff --git a/scripts/wp-search-replace.sh b/scripts/wp-search-replace.sh index 89d79e4..e39deec 100644 --- a/scripts/wp-search-replace.sh +++ b/scripts/wp-search-replace.sh @@ -283,13 +283,35 @@ fi # Purge LiteSpeed Cache (if plugin installed) info "Attempting LiteSpeed Cache purge (wp litespeed-purge all)…" +PURGE_URL_HTTPS="$TARGET_URL" +PURGE_URL_HTTP="http://$HOST_ONLY" + +# First attempt with HTTPS LS_CMD=() if [[ -n "$SUDO_CMD" ]]; then # shellcheck disable=SC2206 LS_CMD=($SUDO_CMD) fi -LS_CMD+=("$WP_EXECUTABLE" "litespeed-purge" "all" "${WP_RUN_ARGS[@]}") -"${LS_CMD[@]}" || warning "LiteSpeed purge returned non-zero exit status (plugin may be inactive)." +LS_CMD+=("$WP_EXECUTABLE" "litespeed-purge" "all" "${WP_RUN_ARGS[@]}" "--url=$PURGE_URL_HTTPS") +PURGE_OUTPUT=$( "${LS_CMD[@]}" 2>&1 ) || true +printf "%s\n" "$PURGE_OUTPUT" + +# If SSL verification fails, retry over HTTP +if echo "$PURGE_OUTPUT" | grep -qiE "cURL error 60|SSL certificate problem"; then + warning "LiteSpeed purge failed due to SSL verification. Retrying over HTTP…" + LS_CMD=() + if [[ -n "$SUDO_CMD" ]]; then + # shellcheck disable=SC2206 + LS_CMD=($SUDO_CMD) + fi + LS_CMD+=("$WP_EXECUTABLE" "litespeed-purge" "all" "${WP_RUN_ARGS[@]}" "--url=$PURGE_URL_HTTP") + PURGE_OUTPUT=$( "${LS_CMD[@]}" 2>&1 ) || true + printf "%s\n" "$PURGE_OUTPUT" +fi + +if echo "$PURGE_OUTPUT" | grep -qiE "Error|Warning"; then + warning "LiteSpeed purge may not have completed successfully." +fi # Delete all transients – recommended after domain/URL migration info "Deleting all transients (wp transient delete --all)..."