wp-search-replace: replace WP-CLI litespeed purge with filesystem purge of /var/www/webroot/.cache; keep transient and cache flush steps
parent
c83a7199cf
commit
0e9bced53c
|
|
@ -306,66 +306,33 @@ else
|
|||
warning "wp-config.php not found or not writable; skipped WP_HOME / WP_SITEURL update."
|
||||
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"
|
||||
FIX_TRUST_SCRIPT="/home/litespeed/mbmanager/scripts/fix-cert-trust.sh"
|
||||
|
||||
# First attempt with HTTPS
|
||||
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_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."
|
||||
# Purge LiteSpeed Cache by emptying the filesystem cache directory
|
||||
CACHE_DIR="/var/www/webroot/.cache"
|
||||
info "Purging LiteSpeed cache by emptying '$CACHE_DIR' …"
|
||||
if [[ -d "$CACHE_DIR" ]]; then
|
||||
# Build deletion command with root privileges if available
|
||||
DEL_CMD=()
|
||||
if [[ "$(id -u)" -eq 0 ]]; then
|
||||
:
|
||||
elif sudo -n true 2>/dev/null; then
|
||||
DEL_CMD=(sudo)
|
||||
elif [[ -w "$CACHE_DIR" ]]; then
|
||||
:
|
||||
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
|
||||
|
||||
# Retry HTTPS
|
||||
LS_CMD=()
|
||||
if [[ -n "$SUDO_CMD" ]]; then
|
||||
# shellcheck disable=SC2206
|
||||
LS_CMD=($SUDO_CMD)
|
||||
# Safely delete only the contents (including dotfiles) without removing the directory itself
|
||||
if [[ ${#DEL_CMD[@]} -gt 0 ]]; then
|
||||
"${DEL_CMD[@]}" find "$CACHE_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf {} + || \
|
||||
warning "Failed to fully clear '$CACHE_DIR'."
|
||||
else
|
||||
find "$CACHE_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf {} + || \
|
||||
warning "Failed to fully clear '$CACHE_DIR'."
|
||||
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 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."
|
||||
success "LiteSpeed cache directory cleared."
|
||||
else
|
||||
warning "LiteSpeed cache directory '$CACHE_DIR' does not exist; nothing to clear."
|
||||
fi
|
||||
|
||||
# Delete all transients – recommended after domain/URL migration
|
||||
|
|
|
|||
Loading…
Reference in New Issue