- Document enhanced event creation testing improvements - Add Breeze cache clearing script and integration - Detail form field mapping discoveries - Note current validation issues with description field - Include multiple test approaches implemented - Update error handling and debugging capabilities
		
			
				
	
	
		
			301 lines
		
	
	
		
			No EOL
		
	
	
		
			9.5 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			301 lines
		
	
	
		
			No EOL
		
	
	
		
			9.5 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/bin/bash
 | |
| 
 | |
| # Exit on error
 | |
| set -e
 | |
| 
 | |
| # Source environment variables
 | |
| source .env
 | |
| 
 | |
| echo "Deploying dashboard fix to staging..."
 | |
| 
 | |
| # Create backup and upload fix directly via SSH
 | |
| echo "Creating fix on staging server..."
 | |
| 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/class-hvac-dashboard-data-fixed.php << 'EOF'
 | |
| <?php
 | |
| /**
 | |
|  * HVAC Community Events Dashboard Data Handler - Fixed Version
 | |
|  *
 | |
|  * Consistently queries by post_author for trainer's events
 | |
|  *
 | |
|  * @package    HVAC_Community_Events
 | |
|  * @subpackage Includes
 | |
|  * @since      1.1.0
 | |
|  */
 | |
| 
 | |
| if ( ! defined( 'ABSPATH' ) ) {
 | |
| 	exit;
 | |
| }
 | |
| 
 | |
| /**
 | |
|  * Class HVAC_Dashboard_Data
 | |
|  */
 | |
| class HVAC_Dashboard_Data {
 | |
| 
 | |
| 	/**
 | |
| 	 * The ID of the trainer user.
 | |
| 	 *
 | |
| 	 * @var int
 | |
| 	 */
 | |
| 	private int \$user_id;
 | |
| 
 | |
| 	/**
 | |
| 	 * Constructor.
 | |
| 	 *
 | |
| 	 * @param int \$user_id The ID of the trainer user.
 | |
| 	 */
 | |
| 	public function __construct( int \$user_id ) {
 | |
| 		\$this->user_id = \$user_id;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Get the total number of events created by the trainer.
 | |
| 	 *
 | |
| 	 * @return int
 | |
| 	 */
 | |
| 	public function get_total_events_count() : int {
 | |
| 		\$args = array(
 | |
| 			'post_type'      => Tribe__Events__Main::POSTTYPE,
 | |
| 			'author'         => \$this->user_id,
 | |
| 			'post_status'    => array( 'publish', 'future', 'draft', 'pending', 'private' ),
 | |
| 			'posts_per_page' => -1,
 | |
| 			'fields'         => 'ids',
 | |
| 		);
 | |
| 		\$query = new WP_Query( \$args );
 | |
| 		return (int) \$query->found_posts;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Get the number of upcoming events for the trainer.
 | |
| 	 *
 | |
| 	 * @return int
 | |
| 	 */
 | |
| 	public function get_upcoming_events_count() : int {
 | |
| 		\$today = current_time( 'mysql' );
 | |
| 		\$args  = array(
 | |
| 			'post_type'      => Tribe__Events__Main::POSTTYPE,
 | |
| 			'author'         => \$this->user_id, // Use author consistently
 | |
| 			'post_status'    => array( 'publish', 'future' ),
 | |
| 			'posts_per_page' => -1,
 | |
| 			'fields'         => 'ids',
 | |
| 			'meta_query'     => array(
 | |
| 				array(
 | |
| 					'key'     => '_EventStartDate',
 | |
| 					'value'   => \$today,
 | |
| 					'compare' => '>=',
 | |
| 					'type'    => 'DATETIME',
 | |
| 				),
 | |
| 			),
 | |
| 			'orderby'        => 'meta_value',
 | |
| 			'meta_key'       => '_EventStartDate',
 | |
| 			'order'          => 'ASC',
 | |
| 		);
 | |
| 		\$query = new WP_Query( \$args );
 | |
| 		return (int) \$query->found_posts;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Get the number of past events for the trainer.
 | |
| 	 *
 | |
| 	 * @return int
 | |
| 	 */
 | |
| 	public function get_past_events_count() : int {
 | |
| 		\$today = current_time( 'mysql' );
 | |
| 		\$args  = array(
 | |
| 			'post_type'      => Tribe__Events__Main::POSTTYPE,
 | |
| 			'author'         => \$this->user_id, // Use author consistently
 | |
| 			'post_status'    => array( 'publish', 'private' ),
 | |
| 			'posts_per_page' => -1,
 | |
| 			'fields'         => 'ids',
 | |
| 			'meta_query'     => array(
 | |
| 				array(
 | |
| 					'key'     => '_EventEndDate',
 | |
| 					'value'   => \$today,
 | |
| 					'compare' => '<',
 | |
| 					'type'    => 'DATETIME',
 | |
| 				),
 | |
| 			),
 | |
| 		);
 | |
| 		\$query = new WP_Query( \$args );
 | |
| 		return (int) \$query->found_posts;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Get the total number of tickets sold across all the trainer's events.
 | |
| 	 *
 | |
| 	 * @return int
 | |
| 	 */
 | |
| 	public function get_total_tickets_sold() : int {
 | |
| 		\$total_tickets = 0;
 | |
| 		\$args = array(
 | |
| 			'post_type'      => Tribe__Events__Main::POSTTYPE,
 | |
| 			'author'         => \$this->user_id, // Use author consistently
 | |
| 			'post_status'    => array( 'publish', 'future', 'draft', 'pending', 'private' ),
 | |
| 			'posts_per_page' => -1,
 | |
| 			'fields'         => 'ids',
 | |
| 		);
 | |
| 		\$event_ids = get_posts( \$args );
 | |
| 
 | |
| 		if ( ! empty( \$event_ids ) ) {
 | |
| 			foreach ( \$event_ids as \$event_id ) {
 | |
| 				\$sold = get_post_meta( \$event_id, '_tribe_tickets_sold', true );
 | |
| 				if ( is_numeric( \$sold ) ) {
 | |
| 					\$total_tickets += (int) \$sold;
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		return \$total_tickets;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Get the total revenue generated across all the trainer's events.
 | |
| 	 *
 | |
| 	 * @return float
 | |
| 	 */
 | |
| 	public function get_total_revenue() : float {
 | |
| 		\$total_revenue = 0.0;
 | |
| 		\$args = array(
 | |
| 			'post_type'      => Tribe__Events__Main::POSTTYPE,
 | |
| 			'author'         => \$this->user_id, // Use author consistently
 | |
| 			'post_status'    => array( 'publish', 'future', 'draft', 'pending', 'private' ),
 | |
| 			'posts_per_page' => -1,
 | |
| 			'fields'         => 'ids',
 | |
| 		);
 | |
| 		\$event_ids = get_posts( \$args );
 | |
| 
 | |
| 		if ( ! empty( \$event_ids ) ) {
 | |
| 			foreach ( \$event_ids as \$event_id ) {
 | |
| 				\$revenue = get_post_meta( \$event_id, '_tribe_revenue_total', true );
 | |
| 				if ( is_numeric( \$revenue ) ) {
 | |
| 					\$total_revenue += (float) \$revenue;
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		return \$total_revenue;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Get the annual revenue target set by the trainer.
 | |
| 	 *
 | |
| 	 * @return float|null Returns the target as a float, or null if not set.
 | |
| 	 */
 | |
| 	public function get_annual_revenue_target() : ?float {
 | |
| 		\$target = get_user_meta( \$this->user_id, 'annual_revenue_target', true );
 | |
| 		return ! empty( \$target ) && is_numeric( \$target ) ? (float) \$target : null;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Get the data needed for the events table on the dashboard.
 | |
| 	 *
 | |
| 	 * @param string \$filter_status The status to filter events by.
 | |
| 	 * @return array An array of event data arrays.
 | |
| 	 */
 | |
| 	public function get_events_table_data( string \$filter_status = 'all' ) : array {
 | |
| 		\$events_data = [];
 | |
| 		\$valid_statuses = array( 'publish', 'future', 'draft', 'pending', 'private' );
 | |
| 		\$post_status = ( 'all' === \$filter_status || ! in_array( \$filter_status, \$valid_statuses, true ) )
 | |
| 			? \$valid_statuses
 | |
| 			: array( \$filter_status );
 | |
| 
 | |
| 		\$args = array(
 | |
| 			'post_type'      => Tribe__Events__Main::POSTTYPE,
 | |
| 			'author'         => \$this->user_id, // Use author consistently
 | |
| 			'post_status'    => \$post_status,
 | |
| 			'posts_per_page' => -1,
 | |
| 			'orderby'        => 'meta_value',
 | |
| 			'meta_key'       => '_EventStartDate',
 | |
| 			'order'          => 'DESC',
 | |
| 		);
 | |
| 
 | |
| 		\$query = new WP_Query( \$args );
 | |
| 
 | |
| 		if ( \$query->have_posts() ) {
 | |
| 			while ( \$query->have_posts() ) {
 | |
| 				\$query->the_post();
 | |
| 				\$event_id = get_the_ID();
 | |
| 
 | |
| 				// Get Capacity
 | |
| 				\$total_capacity = 0;
 | |
| 				if ( function_exists( 'tribe_get_tickets' ) ) {
 | |
| 					\$tickets = tribe_get_tickets( \$event_id );
 | |
| 					if ( \$tickets ) {
 | |
| 						foreach ( \$tickets as \$ticket ) {
 | |
| 							\$capacity = \$ticket->capacity();
 | |
| 							if ( \$capacity === -1 ) {
 | |
| 								\$total_capacity = -1;
 | |
| 								break;
 | |
| 							}
 | |
| 							if ( is_numeric( \$capacity ) ) {
 | |
| 								\$total_capacity += \$capacity;
 | |
| 							}
 | |
| 						}
 | |
| 					}
 | |
| 				}
 | |
| 
 | |
| 				\$sold = get_post_meta( \$event_id, '_tribe_tickets_sold', true );
 | |
| 				\$revenue = get_post_meta( \$event_id, '_tribe_revenue_total', true );
 | |
| 
 | |
| 				\$events_data[] = array(
 | |
| 					'id'        => \$event_id,
 | |
| 					'status'    => get_post_status( \$event_id ),
 | |
| 					'name'      => get_the_title(),
 | |
| 					'link'      => get_permalink( \$event_id ),
 | |
| 					'start_date_ts' => strtotime( get_post_meta( \$event_id, '_EventStartDate', true ) ),
 | |
| 					'organizer_id' => (int) get_post_meta( \$event_id, '_EventOrganizerID', true ),
 | |
| 					'capacity'  => ( \$total_capacity === -1 ) ? 'Unlimited' : (int) \$total_capacity,
 | |
| 					'sold'      => is_numeric( \$sold ) ? (int) \$sold : 0,
 | |
| 					'revenue'   => is_numeric( \$revenue ) ? (float) \$revenue : 0.0,
 | |
| 				);
 | |
| 			}
 | |
| 			wp_reset_postdata();
 | |
| 		}
 | |
| 
 | |
| 		return \$events_data;
 | |
| 	}
 | |
| }
 | |
| EOF"
 | |
| 
 | |
| # Backup original
 | |
| echo "Backing up original file..."
 | |
| sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && cp wp-content/plugins/hvac-community-events/includes/class-hvac-dashboard-data.php wp-content/plugins/hvac-community-events/includes/class-hvac-dashboard-data.php.bak"
 | |
| 
 | |
| # Replace with fixed version
 | |
| echo "Replacing with fixed version..."
 | |
| sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && cp wp-content/plugins/hvac-community-events/includes/class-hvac-dashboard-data-fixed.php wp-content/plugins/hvac-community-events/includes/class-hvac-dashboard-data.php"
 | |
| 
 | |
| # Clear cache
 | |
| echo "Clearing cache..."
 | |
| sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && wp cache flush"
 | |
| 
 | |
| # Test the fix
 | |
| echo -e "\nTesting the fix..."
 | |
| sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && cat > test-dashboard-fix.php << 'EOF'
 | |
| <?php
 | |
| require_once('wp-load.php');
 | |
| 
 | |
| \$user_id = get_user_by('login', 'test_trainer')->ID;
 | |
| echo \"User ID: \$user_id\\n\";
 | |
| 
 | |
| \$dashboard_data = new HVAC_Dashboard_Data(\$user_id);
 | |
| 
 | |
| echo \"Total Events: \" . \$dashboard_data->get_total_events_count() . \"\\n\";
 | |
| echo \"Upcoming Events: \" . \$dashboard_data->get_upcoming_events_count() . \"\\n\";
 | |
| echo \"Past Events: \" . \$dashboard_data->get_past_events_count() . \"\\n\";
 | |
| echo \"Total Tickets: \" . \$dashboard_data->get_total_tickets_sold() . \"\\n\";
 | |
| echo \"Total Revenue: \" . \$dashboard_data->get_total_revenue() . \"\\n\";
 | |
| 
 | |
| // Check event table data
 | |
| \$events = \$dashboard_data->get_events_table_data();
 | |
| echo \"\\nEvents in table: \" . count(\$events) . \"\\n\";
 | |
| foreach (\$events as \$event) {
 | |
|     echo \"  - \" . \$event['name'] . \" (\" . \$event['status'] . \")\\n\";
 | |
| }
 | |
| EOF"
 | |
| 
 | |
| sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && php test-dashboard-fix.php"
 | |
| 
 | |
| # Clean up test file
 | |
| sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && rm test-dashboard-fix.php"
 | |
| 
 | |
| echo -e "\nDashboard fix deployed. You should now see the correct stats at: https://wordpress-974670-5399585.cloudwaysapps.com/hvac-dashboard/" |