diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index 9d7fdbf..b98def2 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -44,6 +44,9 @@ for arg in "$@"; do --parallel) ENABLE_PARALLEL=true ;; + --batch|--non-interactive) + BATCH_MODE=true + ;; --log) # Next argument should be the log file path # Will be set in the next iteration or default to /tmp @@ -59,12 +62,14 @@ for arg in "$@"; do echo "Options:" echo " --dry-run Run in dry-run mode (no actual changes)" echo " --parallel Enable parallel processing for multi-site ops" + echo " --batch Batch mode - skip all confirmations (for automation)" echo " --log [FILE] Enable logging to file (default: /tmp/wordpress-cron-manager-TIMESTAMP.log)" echo " --log=/path/to/file Log to specific file path" echo " --help Show this help message" echo "" echo "Examples:" echo " $0 --dry-run --parallel" + echo " $0 --batch --parallel (full automation)" echo " $0 --log" echo " $0 --log=/var/log/wp-cron-conversion.log" exit 0 @@ -94,6 +99,22 @@ declare -r WP_CRON_FILENAME="wp-cron.php" declare -r WP_CONFIG_MARKER="stop editing" declare -r WP_EDIT_START="/dev/null 2>&1; then + COMMAND_CACHE[$cmd]="found" + return 0 + else + COMMAND_CACHE[$cmd]="notfound" + return 1 + fi +} + +# OPTIMIZATION: ANSI Color Palette Constants (OPT-4) +# Centralized color definitions for consistent output +# Reduces 112 scattered color variable uses +declare -r COLOR_GREEN='\033[0;32m' +declare -r COLOR_RED='\033[0;31m' +declare -r COLOR_YELLOW='\033[0;33m' +declare -r COLOR_BLUE='\033[0;34m' +declare -r COLOR_CYAN='\033[0;36m' +declare -r COLOR_BOLD='\033[1m' +declare -r COLOR_RESET='\033[0m' + +# OPTIMIZATION: Batch mode helper (OPT-3) +# Skip confirmations and input prompts for automation +skip_confirmation() { + if [ "$BATCH_MODE" = "true" ]; then + return 0 # Skip confirmation + else + return 1 # Don't skip + fi +} + # OPTIMIZATION: Build cron command consistently # Centralizes cron command format (appears 4 times throughout script) # Returns: cron command string for wp-cron.php execution @@ -642,7 +705,7 @@ create_timestamped_backup() { # CRITICAL FIX: Check disk space before creating backup local available_kb=$(df "$(dirname "$wp_config")" 2>/dev/null | awk 'NR==2 {print $4}') - if [ -n "$available_kb" ] && [ "$available_kb" -lt 10240 ]; then + if [ -n "$available_kb" ] && [ "$available_kb" -lt "$MIN_DISK_SPACE" ]; then # Less than 10MB available print_error "Insufficient disk space (less than 10MB available) - cannot create backup" return 1 @@ -652,7 +715,7 @@ create_timestamped_backup() { if cp "$wp_config" "$backup_file" 2>/dev/null; then # CRITICAL SECURITY FIX: Set backup file permissions to 0600 (owner read/write only) # wp-config.php contains sensitive database credentials and should not be readable by other users - chmod 600 "$backup_file" 2>/dev/null || true + chmod "$CHMOD_SECURE_FILE" "$backup_file" 2>/dev/null || true echo "$backup_file" return 0 else