diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index 4233b7d..7c82740 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -15,6 +15,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" [ -f "$SCRIPT_DIR/lib/common-functions.sh" ] && source "$SCRIPT_DIR/lib/common-functions.sh" || { echo "ERROR: common-functions.sh not found" >&2; exit 1; } [ -f "$SCRIPT_DIR/lib/system-detect.sh" ] && source "$SCRIPT_DIR/lib/system-detect.sh" || { echo "ERROR: system-detect.sh not found" >&2; exit 1; } +[ -f "$SCRIPT_DIR/lib/domain-discovery.sh" ] && source "$SCRIPT_DIR/lib/domain-discovery.sh" || { echo "ERROR: domain-discovery.sh not found" >&2; exit 1; } if [ "$EUID" -ne 0 ]; then print_error "This script must be run as root" @@ -247,26 +248,45 @@ function_get_description() { echo "${FUNCTION_REGISTRY[$func]}" } -# PERFORMANCE OPTIMIZATION: Extract control panel detection logic -# Reduces 6 repeated case statements to a single function -# Returns find pattern for WordPress installations based on control panel +# PERFORMANCE OPTIMIZATION: Use system domain discovery instead of find commands +# References already-discovered domains from main management system (much faster!) +# Returns wp-config.php paths for all WordPress installations get_wp_search_paths() { - local panel="$1" + local panel="${1:-$SYS_CONTROL_PANEL}" - case "$panel" in - cpanel) - find /home/*/public_html -name "wp-config.php" -type f 2>/dev/null - ;; - interworx) - find /home/*/*/html -name "wp-config.php" -type f 2>/dev/null - ;; - plesk) - find /var/www/vhosts/*/httpdocs -name "wp-config.php" -type f 2>/dev/null - ;; - *) - find /var/www/html -name "wp-config.php" -type f 2>/dev/null - ;; - esac + # Use domain discovery to get all domains (faster than find) + # This leverages discovery that's already done by the main management system + local all_domains + all_domains=$(list_all_domains 2>/dev/null) + + if [ -z "$all_domains" ]; then + # Fallback to find if domain discovery fails + case "$panel" in + cpanel) + find /home/*/public_html -name "wp-config.php" -type f 2>/dev/null + ;; + interworx) + find /home/*/*/html -name "wp-config.php" -type f 2>/dev/null + ;; + plesk) + find /var/www/vhosts/*/httpdocs -name "wp-config.php" -type f 2>/dev/null + ;; + *) + find /var/www/html -name "wp-config.php" -type f 2>/dev/null + ;; + esac + return + fi + + # For each domain, check its docroot for wp-config.php + while IFS= read -r domain; do + local docroot + docroot=$(get_domain_docroot "$domain" 2>/dev/null) + + if [ -n "$docroot" ] && [ -f "$docroot/$WP_CONFIG_FILENAME" ]; then + echo "$docroot/$WP_CONFIG_FILENAME" + fi + done <<< "$all_domains" } # OPTIMIZATION: Build home path based on control panel and username