#!/bin/bash # Exit on error set -e # Source environment variables source .env echo "Debugging dashboard template data..." # Create a debug version of the dashboard template sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && cat > wp-content/plugins/hvac-community-events/templates/template-hvac-dashboard-debug.php << 'EOF' get_total_events_count(); \$upcoming_events = \$dashboard_data->get_upcoming_events_count(); \$past_events = \$dashboard_data->get_past_events_count(); \$total_sold = \$dashboard_data->get_total_tickets_sold(); \$total_revenue = \$dashboard_data->get_total_revenue(); \$revenue_target = \$dashboard_data->get_annual_revenue_target(); // Debug output echo '
';
echo 'User ID: ' . \$user_id . \"\\n\";
echo 'Total Events: ' . \$total_events . \"\\n\";
echo 'Upcoming Events: ' . \$upcoming_events . \"\\n\";
echo 'Past Events: ' . \$past_events . \"\\n\";
echo 'Total Sold: ' . \$total_sold . \"\\n\";
echo 'Total Revenue: ' . \$total_revenue . \"\\n\";
echo 'Revenue Target: ' . \$revenue_target . \"\\n\\n\";

// Direct database query test
global \$wpdb;
\$direct_count = \$wpdb->get_var(\$wpdb->prepare(
    \"SELECT COUNT(ID) FROM wp_posts WHERE post_type = %s AND post_author = %d AND post_status IN ('publish', 'future', 'draft', 'pending', 'private')\",
    'tribe_events',
    \$user_id
));
echo 'Direct Count: ' . \$direct_count . \"\\n\\n\";

// Get actual events with details
\$events_query = new WP_Query(array(
    'post_type' => 'tribe_events',
    'post_author' => \$user_id,
    'post_status' => array('publish', 'future', 'draft', 'pending', 'private'),
    'posts_per_page' => -1
));

echo 'WP_Query found posts: ' . \$events_query->found_posts . \"\\n\";
echo 'Events:\\n';
foreach (\$events_query->posts as \$event) {
    echo '  - ID: ' . \$event->ID . ', Title: ' . \$event->post_title . ', Status: ' . \$event->post_status . \"\\n\";
}

// Get the SQL query
echo \"\\nGenerated SQL:\\n\";
echo \$events_query->request . \"\\n\";

echo '
'; // Include the original template include HVAC_CE_PLUGIN_DIR . 'templates/template-hvac-dashboard.php'; EOF" # Create a page that uses this debug template echo -e "\nCreating debug page..." sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && wp post create --post_type=page --post_title='Dashboard Debug' --post_name='dashboard-debug' --post_status=publish --post_content='Debug Dashboard Page'" # Update the template loading to use debug version temporarily sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && cat > wp-content/plugins/hvac-community-events/includes/debug-template-loader.php << 'EOF' > wp-content/plugins/hvac-community-events/hvac-community-events.php" echo -e "\nDebug page created. Visit: https://wordpress-974670-5399585.cloudwaysapps.com/dashboard-debug/"