diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index 816d1cc..33a26e3 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -273,6 +273,28 @@ show_installation_status() { echo "Total installations: $count" } +# Function to create timestamped backup of wp-config.php +# Returns 0 on success, 1 on failure +# Also returns the backup filename +create_timestamped_backup() { + local wp_config="$1" + local backup_timestamp=$(date +%Y%m%d-%H%M%S) + local backup_file="${wp_config}.backup-${backup_timestamp}" + + # Verify source file exists + if [ ! -f "$wp_config" ]; then + return 1 + fi + + # Create backup + if cp "$wp_config" "$backup_file" 2>/dev/null; then + echo "$backup_file" + return 0 + else + return 1 + fi +} + # Function to generate staggered cron time # Distributes jobs across 60 minutes to avoid load spikes generate_staggered_cron() { @@ -681,12 +703,38 @@ case "$choice" in fi echo "" - echo "All validation checks passed. Proceeding with configuration..." + echo "All validation checks passed. Ready to make changes..." echo "" - # Backup wp-config.php - cp "$wp_config" "${wp_config}.backup-$(date +%Y%m%d-%H%M%S)" - echo -e "${GREEN}✓${NC} Backed up wp-config.php" + # CREATE BACKUP WITH TIMESTAMP + echo -e "${BOLD}BACKUP CREATION:${NC}" + backup_file=$(create_timestamped_backup "$wp_config") + if [ $? -ne 0 ] || [ -z "$backup_file" ]; then + print_error "Failed to create backup of wp-config.php" + echo " Cannot proceed without backup" + press_enter + exit 1 + fi + + echo -e "${GREEN}✓${NC} Backup created successfully" + echo -e "${CYAN}Location:${NC} $backup_file" + echo -e "${CYAN}Timestamp:${NC} $(date '+%Y-%m-%d %H:%M:%S')" + echo "" + + # User confirmation to proceed with modification + echo -e "${YELLOW}IMPORTANT:${NC} This will modify your wp-config.php file" + echo "" + echo -n "Proceed with modification? (y/n) [y]: " + read -r confirm + if [ "$confirm" = "n" ] || [ "$confirm" = "N" ]; then + echo "Operation cancelled. Backup preserved at: $backup_file" + press_enter + exit 0 + fi + + echo "" + echo "Modifying wp-config.php..." + echo "" # Safely disable wp-cron in wp-config.php if disable_wpcron_in_config "$wp_config"; then @@ -695,11 +743,16 @@ case "$choice" in # CRITICAL: Verify syntax after modification if ! validate_wp_config_syntax "$wp_config"; then print_error "CRITICAL: wp-config.php syntax became invalid after modification!" - echo " Attempting to restore backup..." - backup_file=$(find "${wp_config}.backup-"* 2>/dev/null | sort -r | head -1) - if [ -n "$backup_file" ]; then - cp "$backup_file" "$wp_config" - echo -e "${GREEN}✓${NC} Restored from backup" + echo " Restoring backup..." + if cp "$backup_file" "$wp_config"; then + echo -e "${GREEN}✓${NC} Restored from backup: $backup_file" + echo "" + echo "Your original wp-config.php has been restored." + echo "Backup (with attempted modification) kept at: ${backup_file}.failed" + cp "$backup_file" "${backup_file}.failed" + else + print_error "CRITICAL: Could not restore from backup!" + echo "Original backup location: $backup_file" fi press_enter exit 1