#!/bin/bash

echo "=== Reassigning Page Templates ==="

# SSH into staging and reassign templates
ssh roodev@146.190.76.204 << 'EOF'
cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html

# Get all HVAC pages and update their templates
echo "Finding and updating HVAC pages..."

# Update trainer registration page
wp post list --post_type=page --meta_key=_wp_page_template --meta_value=page-trainer-registration.php --field=ID | while read page_id; do
    echo "Updating page $page_id - Trainer Registration"
    wp post meta update $page_id _wp_page_template "page-trainer-registration.php"
done

# Update trainer dashboard
wp post list --post_type=page --name=dashboard --post_parent=5332 --field=ID | while read page_id; do
    echo "Updating page $page_id - Trainer Dashboard"
    wp post meta update $page_id _wp_page_template "page-trainer-dashboard.php"
done

# Update master dashboard
wp post list --post_type=page --name=dashboard --post_parent=5346 --field=ID | while read page_id; do
    echo "Updating page $page_id - Master Dashboard"
    wp post meta update $page_id _wp_page_template "page-master-dashboard.php"
done

# List all pages with their templates
echo -e "\nCurrent page templates:"
wp post list --post_type=page --meta_key=_wp_page_template --fields=ID,post_title,post_name --format=table | head -20

# Clear all caches
wp cache flush
wp breeze purge --cache=all

echo "Templates reassigned successfully!"
EOF