fix: Repair certificate generation and listing functionality
- Fixed broken certificate manager class caused by corrupted debug statement removal - Cleaned up certificate manager by removing all debug logging statements - Restored proper PHP syntax and error handling in certificate system - Certificate generation should now work properly on Generate Certificates page - Certificate listing should now display correctly on Certificate Reports page - Deployed clean certificate manager to staging environment 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c2c5e2802e
commit
aa4d91e609
2 changed files with 1099 additions and 170 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -468,11 +468,6 @@ class HVAC_Certificate_Manager {
|
||||||
public function get_user_certificates($user_id, $args = array()) {
|
public function get_user_certificates($user_id, $args = array()) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('get_user_certificates called with user_id', $user_id);
|
|
||||||
hvac_debug_log('get_user_certificates args', $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20,
|
'per_page' => 20,
|
||||||
|
|
@ -486,19 +481,10 @@ class HVAC_Certificate_Manager {
|
||||||
|
|
||||||
$args = wp_parse_args($args, $defaults);
|
$args = wp_parse_args($args, $defaults);
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Args after parsing defaults', $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build WHERE clause
|
// Build WHERE clause
|
||||||
$where = array();
|
$where = array();
|
||||||
$where_values = array();
|
$where_values = array();
|
||||||
|
|
||||||
// Get event IDs authored by this user
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Creating WP_Query to get user events');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Use direct database query to get user's event IDs (bypassing TEC interference)
|
// Use direct database query to get user's event IDs (bypassing TEC interference)
|
||||||
$event_ids = $wpdb->get_col($wpdb->prepare(
|
$event_ids = $wpdb->get_col($wpdb->prepare(
|
||||||
|
|
@ -510,51 +496,26 @@ class HVAC_Certificate_Manager {
|
||||||
$user_id
|
$user_id
|
||||||
));
|
));
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Direct DB query completed, event_ids count', count($event_ids));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($event_ids)) {
|
if (empty($event_ids)) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('No events found for user, returning empty array');
|
|
||||||
}
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter by event ID if specified
|
// Filter by event ID if specified
|
||||||
if (!empty($args['event_id'])) {
|
if (!empty($args['event_id'])) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Filter by specific event ID', $args['event_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the specified event belongs to the user
|
// Check if the specified event belongs to the user
|
||||||
if (in_array($args['event_id'], $event_ids)) {
|
if (in_array($args['event_id'], $event_ids)) {
|
||||||
$where[] = "event_id = %d";
|
$where[] = "event_id = %d";
|
||||||
$where_values[] = $args['event_id'];
|
$where_values[] = $args['event_id'];
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Event belongs to user, adding to WHERE clause');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Event doesn't belong to this user
|
// Event doesn't belong to this user
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Event does not belong to user, returning empty array');
|
|
||||||
}
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Include all user's events
|
// Include all user's events
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Including all user events in query');
|
|
||||||
}
|
|
||||||
|
|
||||||
$event_ids_string = implode(',', array_map('intval', $event_ids));
|
$event_ids_string = implode(',', array_map('intval', $event_ids));
|
||||||
|
|
||||||
// Check if we have a valid string of event IDs
|
// Check if we have a valid string of event IDs
|
||||||
if (empty($event_ids_string)) {
|
if (empty($event_ids_string)) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Empty event_ids_string, returning empty array');
|
|
||||||
}
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -565,10 +526,6 @@ class HVAC_Certificate_Manager {
|
||||||
if (isset($args['revoked']) && $args['revoked'] !== null) {
|
if (isset($args['revoked']) && $args['revoked'] !== null) {
|
||||||
$where[] = "revoked = %d";
|
$where[] = "revoked = %d";
|
||||||
$where_values[] = (int) $args['revoked'];
|
$where_values[] = (int) $args['revoked'];
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Added revoked filter', $args['revoked']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build WHERE clause
|
// Build WHERE clause
|
||||||
|
|
@ -594,9 +551,6 @@ class HVAC_Certificate_Manager {
|
||||||
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
|
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
|
||||||
|
|
||||||
if (!$table_exists) {
|
if (!$table_exists) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Table does not exist: ' . $table_name);
|
|
||||||
}
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -641,10 +595,6 @@ class HVAC_Certificate_Manager {
|
||||||
$where_values[] = $search_term;
|
$where_values[] = $search_term;
|
||||||
$where_values[] = $search_term;
|
$where_values[] = $search_term;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Added attendee search filter', $args['search_attendee']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build WHERE clause
|
// Build WHERE clause
|
||||||
|
|
@ -653,35 +603,16 @@ class HVAC_Certificate_Manager {
|
||||||
// Build final query
|
// Build final query
|
||||||
$query = "SELECT * FROM {$wpdb->prefix}hvac_certificates $where_clause ORDER BY $order_by $limit_clause";
|
$query = "SELECT * FROM {$wpdb->prefix}hvac_certificates $where_clause ORDER BY $order_by $limit_clause";
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Final query before prepare', $query);
|
|
||||||
hvac_debug_log('Where values', $where_values);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare the query if we have where values
|
// Prepare the query if we have where values
|
||||||
if (!empty($where_values)) {
|
if (!empty($where_values)) {
|
||||||
$query = $wpdb->prepare($query, $where_values);
|
$query = $wpdb->prepare($query, $where_values);
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Prepared query', $query);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = $wpdb->get_results($query);
|
$results = $wpdb->get_results($query);
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Query executed, results count', is_array($results) ? count($results) : 'null');
|
|
||||||
if ($wpdb->last_error) {
|
|
||||||
hvac_debug_log('Database error', $wpdb->last_error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Exception in get_user_certificates', $e->getMessage());
|
|
||||||
}
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -697,11 +628,6 @@ class HVAC_Certificate_Manager {
|
||||||
public function get_user_certificate_count($user_id, $args = array()) {
|
public function get_user_certificate_count($user_id, $args = array()) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('get_user_certificate_count called with user_id', $user_id);
|
|
||||||
hvac_debug_log('get_user_certificate_count args', $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Use direct database query to get user's event IDs (bypassing TEC interference)
|
// Use direct database query to get user's event IDs (bypassing TEC interference)
|
||||||
$event_ids = $wpdb->get_col($wpdb->prepare(
|
$event_ids = $wpdb->get_col($wpdb->prepare(
|
||||||
|
|
@ -713,14 +639,7 @@ class HVAC_Certificate_Manager {
|
||||||
$user_id
|
$user_id
|
||||||
));
|
));
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Direct DB query for events completed, count', count($event_ids));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($event_ids)) {
|
if (empty($event_ids)) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('No events found for user, returning 0');
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -730,38 +649,20 @@ class HVAC_Certificate_Manager {
|
||||||
|
|
||||||
// Filter by event ID if specified
|
// Filter by event ID if specified
|
||||||
if (!empty($args['event_id'])) {
|
if (!empty($args['event_id'])) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Filter by event ID', $args['event_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the specified event belongs to the user
|
// Check if the specified event belongs to the user
|
||||||
if (in_array($args['event_id'], $event_ids)) {
|
if (in_array($args['event_id'], $event_ids)) {
|
||||||
$where[] = "event_id = %d";
|
$where[] = "event_id = %d";
|
||||||
$where_values[] = $args['event_id'];
|
$where_values[] = $args['event_id'];
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Event belongs to user, adding to WHERE clause');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Event doesn't belong to this user
|
// Event doesn't belong to this user
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Event does not belong to user, returning 0');
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Include all user's events
|
// Include all user's events
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Including all user events in query');
|
|
||||||
}
|
|
||||||
|
|
||||||
$event_ids_string = implode(',', array_map('intval', $event_ids));
|
$event_ids_string = implode(',', array_map('intval', $event_ids));
|
||||||
|
|
||||||
// Make sure we have event IDs
|
// Make sure we have event IDs
|
||||||
if (empty($event_ids_string)) {
|
if (empty($event_ids_string)) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Empty event_ids_string, returning 0');
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -772,10 +673,6 @@ class HVAC_Certificate_Manager {
|
||||||
if (isset($args['revoked']) && $args['revoked'] !== null) {
|
if (isset($args['revoked']) && $args['revoked'] !== null) {
|
||||||
$where[] = "revoked = %d";
|
$where[] = "revoked = %d";
|
||||||
$where_values[] = (int) $args['revoked'];
|
$where_values[] = (int) $args['revoked'];
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Added revoked filter', $args['revoked']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if table exists
|
// Check if table exists
|
||||||
|
|
@ -783,9 +680,6 @@ class HVAC_Certificate_Manager {
|
||||||
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
|
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
|
||||||
|
|
||||||
if (!$table_exists) {
|
if (!$table_exists) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Table does not exist: ' . $table_name);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -833,10 +727,6 @@ class HVAC_Certificate_Manager {
|
||||||
$where_values[] = $search_term;
|
$where_values[] = $search_term;
|
||||||
$where_values[] = $search_term;
|
$where_values[] = $search_term;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Added attendee search filter to count query', $args['search_attendee']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build WHERE clause
|
// Build WHERE clause
|
||||||
|
|
@ -845,34 +735,16 @@ class HVAC_Certificate_Manager {
|
||||||
// Build final query
|
// Build final query
|
||||||
$query = "SELECT COUNT(*) FROM {$wpdb->prefix}hvac_certificates $where_clause";
|
$query = "SELECT COUNT(*) FROM {$wpdb->prefix}hvac_certificates $where_clause";
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Final query before prepare', $query);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare the query if we have where values
|
// Prepare the query if we have where values
|
||||||
if (!empty($where_values)) {
|
if (!empty($where_values)) {
|
||||||
$query = $wpdb->prepare($query, $where_values);
|
$query = $wpdb->prepare($query, $where_values);
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Prepared query', $query);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = $wpdb->get_var($query);
|
$count = $wpdb->get_var($query);
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Query executed, count result', $count);
|
|
||||||
if ($wpdb->last_error) {
|
|
||||||
hvac_debug_log('Database error', $wpdb->last_error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return intval($count);
|
return intval($count);
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Exception in get_user_certificate_count', $e->getMessage());
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -887,10 +759,6 @@ class HVAC_Certificate_Manager {
|
||||||
public function get_user_certificate_stats($user_id) {
|
public function get_user_certificate_stats($user_id) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('get_user_certificate_stats called with user_id', $user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default empty stats
|
// Default empty stats
|
||||||
$empty_stats = array(
|
$empty_stats = array(
|
||||||
'total' => 0,
|
'total' => 0,
|
||||||
|
|
@ -905,9 +773,6 @@ class HVAC_Certificate_Manager {
|
||||||
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
|
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
|
||||||
|
|
||||||
if (!$table_exists) {
|
if (!$table_exists) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Table does not exist: ' . $table_name);
|
|
||||||
}
|
|
||||||
return $empty_stats;
|
return $empty_stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -921,14 +786,7 @@ class HVAC_Certificate_Manager {
|
||||||
$user_id
|
$user_id
|
||||||
));
|
));
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Direct DB query for events in stats, count', count($event_ids));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($event_ids)) {
|
if (empty($event_ids)) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('No events found for user in stats, returning empty stats');
|
|
||||||
}
|
|
||||||
return $empty_stats;
|
return $empty_stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -936,16 +794,9 @@ class HVAC_Certificate_Manager {
|
||||||
$event_ids_string = implode(',', array_map('intval', $event_ids));
|
$event_ids_string = implode(',', array_map('intval', $event_ids));
|
||||||
|
|
||||||
if (empty($event_ids_string)) {
|
if (empty($event_ids_string)) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Empty event_ids_string, returning empty stats');
|
|
||||||
}
|
|
||||||
return $empty_stats;
|
return $empty_stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Building statistics query for events', $event_ids_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "SELECT
|
$query = "SELECT
|
||||||
COUNT(*) as total,
|
COUNT(*) as total,
|
||||||
SUM(CASE WHEN revoked = 0 THEN 1 ELSE 0 END) as active,
|
SUM(CASE WHEN revoked = 0 THEN 1 ELSE 0 END) as active,
|
||||||
|
|
@ -954,27 +805,13 @@ class HVAC_Certificate_Manager {
|
||||||
FROM {$wpdb->prefix}hvac_certificates
|
FROM {$wpdb->prefix}hvac_certificates
|
||||||
WHERE event_id IN ($event_ids_string)";
|
WHERE event_id IN ($event_ids_string)";
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Statistics query', $query);
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $wpdb->get_row($query);
|
$result = $wpdb->get_row($query);
|
||||||
|
|
||||||
if ($wpdb->last_error) {
|
if ($wpdb->last_error) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Database error in get_user_certificate_stats', $wpdb->last_error);
|
|
||||||
}
|
|
||||||
return $empty_stats;
|
return $empty_stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Query executed, result', $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($result)) {
|
if (is_null($result)) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Null result returned, using empty stats');
|
|
||||||
}
|
|
||||||
return $empty_stats;
|
return $empty_stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -985,15 +822,8 @@ class HVAC_Certificate_Manager {
|
||||||
'emailed' => intval($result->emailed)
|
'emailed' => intval($result->emailed)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Returning stats', $stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $stats;
|
return $stats;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
if (function_exists('hvac_debug_log')) {
|
|
||||||
hvac_debug_log('Exception in get_user_certificate_stats', $e->getMessage());
|
|
||||||
}
|
|
||||||
return $empty_stats;
|
return $empty_stats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue