wp-search-replace: replace WP-CLI litespeed purge with filesystem purge of /var/www/webroot/.cache; keep transient and cache flush steps

main
Anthony 2025-08-13 02:03:26 +08:00
parent c83a7199cf
commit 0e9bced53c
1 changed files with 23 additions and 56 deletions

View File

@ -306,66 +306,33 @@ else
warning "wp-config.php not found or not writable; skipped WP_HOME / WP_SITEURL update." warning "wp-config.php not found or not writable; skipped WP_HOME / WP_SITEURL update."
fi fi
# Purge LiteSpeed Cache (if plugin installed) # Purge LiteSpeed Cache by emptying the filesystem cache directory
info "Attempting LiteSpeed Cache purge (wp litespeed-purge all)…" CACHE_DIR="/var/www/webroot/.cache"
PURGE_URL_HTTPS="$TARGET_URL" info "Purging LiteSpeed cache by emptying '$CACHE_DIR' …"
PURGE_URL_HTTP="http://$HOST_ONLY" if [[ -d "$CACHE_DIR" ]]; then
FIX_TRUST_SCRIPT="/home/litespeed/mbmanager/scripts/fix-cert-trust.sh" # Build deletion command with root privileges if available
DEL_CMD=()
# First attempt with HTTPS if [[ "$(id -u)" -eq 0 ]]; then
LS_CMD=() :
if [[ -n "$SUDO_CMD" ]]; then elif sudo -n true 2>/dev/null; then
# shellcheck disable=SC2206 DEL_CMD=(sudo)
LS_CMD=($SUDO_CMD) elif [[ -w "$CACHE_DIR" ]]; then
fi :
if [[ ${#ENV_PREFIX[@]} -gt 0 ]]; then
LS_CMD+=("${ENV_PREFIX[@]}")
fi
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, attempt trust repair, retry HTTPS, then fallback to HTTP
if echo "$PURGE_OUTPUT" | grep -qiE "cURL error 60|SSL certificate problem"; then
warning "LiteSpeed purge failed due to SSL verification. Attempting to repair trust and retry over HTTPS…"
if [[ -x "$FIX_TRUST_SCRIPT" ]]; then
"$FIX_TRUST_SCRIPT" "$HOST_ONLY" "/var/lib/jelastic/keys" || warning "Trust repair script encountered an error."
else else
warning "Trust repair script not found at $FIX_TRUST_SCRIPT; skipping repair." warning "Insufficient permissions to modify '$CACHE_DIR'. Please run this script as root or with passwordless sudo."
fi fi
# Retry HTTPS # Safely delete only the contents (including dotfiles) without removing the directory itself
LS_CMD=() if [[ ${#DEL_CMD[@]} -gt 0 ]]; then
if [[ -n "$SUDO_CMD" ]]; then "${DEL_CMD[@]}" find "$CACHE_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf {} + || \
# shellcheck disable=SC2206 warning "Failed to fully clear '$CACHE_DIR'."
LS_CMD=($SUDO_CMD) else
find "$CACHE_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf {} + || \
warning "Failed to fully clear '$CACHE_DIR'."
fi fi
if [[ ${#ENV_PREFIX[@]} -gt 0 ]]; then success "LiteSpeed cache directory cleared."
LS_CMD+=("${ENV_PREFIX[@]}") else
fi warning "LiteSpeed cache directory '$CACHE_DIR' does not exist; nothing to clear."
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 HTTPS still fails due to SSL, fallback to HTTP
if echo "$PURGE_OUTPUT" | grep -qiE "cURL error 60|SSL certificate problem"; then
warning "HTTPS purge still failing. Retrying over HTTP…"
LS_CMD=()
if [[ -n "$SUDO_CMD" ]]; then
# shellcheck disable=SC2206
LS_CMD=($SUDO_CMD)
fi
if [[ ${#ENV_PREFIX[@]} -gt 0 ]]; then
LS_CMD+=("${ENV_PREFIX[@]}")
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
fi
if echo "$PURGE_OUTPUT" | grep -qiE "Error|Warning"; then
warning "LiteSpeed purge may not have completed successfully."
fi fi
# Delete all transients recommended after domain/URL migration # Delete all transients recommended after domain/URL migration