diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index f1f6e49..dccb8e4 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -722,6 +722,46 @@ declare -r ERR_ALREADY_DISABLED=9 # WP-Cron already disabled declare -r ERR_ALREADY_RUNNING=10 # Another instance running declare -r ERR_CANCELLED=11 # User cancelled operation +# OPTIMIZATION: Conditional Logic Library (OPT-15) +# Consolidates 165 if statements with complex conditions into readable predicates +# Makes conditions self-documenting and reusable +is_file_valid() { + local file="$1" + [ -f "$file" ] && [ -r "$file" ] +} + +is_user_valid() { + local user="$1" + id "$user" >/dev/null 2>&1 +} + +is_wp_configured() { + local wp_config="$1" + [ -f "$wp_config" ] && grep -q "DB_NAME" "$wp_config" +} + +is_wp_cron_disabled() { + local wp_config="$1" + grep -q "define.*$WP_CRON_DISABLED_VAR.*true" "$wp_config" +} + +is_cron_job_exists() { + local cron_command="$1" + crontab -l 2>/dev/null | grep -qF "$cron_command" +} + +has_sufficient_disk_space() { + local path="$1" + local min_kb="${2:-$MIN_DISK_SPACE}" + local available_kb=$(df "$path" 2>/dev/null | awk 'NR==2 {print $4}') + [ "$available_kb" -gt "$min_kb" ] +} + +is_wordpress_directory() { + local path="$1" + [ -d "$path" ] && [ -f "$path/$WP_CRON_FILENAME" ] +} + # OPTIMIZATION: Build cron command consistently # Centralizes cron command format (appears 4 times throughout script) # Returns: cron command string for wp-cron.php execution