| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | declare(strict_types=1); |
| 4 | 4 | |
| 5 | 5 | namespace Yatra\Repositories; |
| 6 | 6 | |
| 7 | +use Yatra\Database\Tables\BookingsTable; | |
| 7 | 8 | use Yatra\Database\Tables\DiscountsTable; |
| 8 | 9 | |
| 9 | 10 | /** |
| 10 | 11 | * Discount Repository |
| @@ -137,17 +138,14 @@ | ||
| 137 | 138 | */ |
| 138 | 139 | public function countUsage(string $code): int |
| 139 | 140 | { |
| 140 | 141 | global $wpdb; |
| 141 | - | |
| 142 | - // Try new bookings table first, then fallback to old table | |
| 143 | - $bookingsTable = $wpdb->prefix . 'yatra_new_bookings'; | |
| 144 | - $tableExists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $bookingsTable)); | |
| 145 | - | |
| 146 | - if (!$tableExists) { | |
| 147 | - $bookingsTable = $wpdb->prefix . 'yatra_bookings'; | |
| 148 | - } | |
| 149 | - | |
| 142 | + | |
| 143 | + // Canonical bookings table — post 3.0.5 rename. Previous code had | |
| 144 | + // a fallback probe for `yatra_new_bookings`; that's no longer | |
| 145 | + // needed since the migration guarantees the canonical name. | |
| 146 | + $bookingsTable = BookingsTable::getTableName(); | |
| 147 | + | |
| 150 | 148 | $count = $wpdb->get_var( |
| 151 | 149 | $wpdb->prepare( |
| 152 | 150 | "SELECT COUNT(*) FROM `{$bookingsTable}` |
| 153 | 151 | WHERE discount_code = %s |
| @@ -159,9 +157,9 @@ | ||
| 159 | 157 | return (int) ($count ?? 0); |
| 160 | 158 | } |
| 161 | 159 | |
| 162 | 160 | /** |
| 163 | - * Status counts for admin toolbar (matches wp_yatra_new_discounts.status values). | |
| 161 | + * Status counts for admin toolbar (matches wp_yatra_discounts.status values). | |
| 164 | 162 | * |
| 165 | 163 | * @return array{all: int, publish: int, draft: int, trash: int, expired: int} |
| 166 | 164 | */ |
| 167 | 165 | public function getAdminStatusCounts(): array |