← All changes
|
app/Repositories/RecurringAvailabilityRepository.php
+14
-5
3.0.10
→
3.0.16
View file →
| @@ -230,22 +230,31 @@ | ||
| 230 | 230 | if (preg_match('/^(\d{4}-\d{2}-\d{2})/', $date, $m)) { |
| 231 | 231 | $date = $m[1]; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | + // Callers (notably CapacityService) take the FIRST row as the winning | |
| 235 | + // rule, so the ordering must be total — not just `priority DESC`. | |
| 236 | + // `priority` is not exposed in the rule editor, so every rule carries the | |
| 237 | + // same default and overlapping rules tied, leaving the winner to MySQL's | |
| 238 | + // arbitrary row order. A trip with an older wide rule (e.g. 25 seats) plus | |
| 239 | + // a newer, narrower one (e.g. 1 seat for a private group) could therefore | |
| 240 | + // resolve to the wrong capacity and silently fall back to the trip default. | |
| 241 | + // Break ties by most-recently-created, matching the ordering this same | |
| 242 | + // repository already uses for rule listings. | |
| 234 | 243 | $query = $this->wpdb->prepare( |
| 235 | - "SELECT * FROM `{$table}` | |
| 236 | - WHERE trip_id = %d | |
| 244 | + "SELECT * FROM `{$table}` | |
| 245 | + WHERE trip_id = %d | |
| 237 | 246 | AND status = 'active' |
| 238 | 247 | AND start_date <= %s |
| 239 | 248 | AND (end_date IS NULL OR end_date >= %s) |
| 240 | - ORDER BY priority DESC", | |
| 249 | + ORDER BY priority DESC, created_at DESC, id DESC", | |
| 241 | 250 | $tripId, |
| 242 | 251 | $date, |
| 243 | 252 | $date |
| 244 | 253 | ); |
| 245 | - | |
| 254 | + | |
| 246 | 255 | $results = $this->wpdb->get_results($query); |
| 247 | - | |
| 256 | + | |
| 248 | 257 | return array_map([$this, 'hydrateRule'], $results ?: []); |
| 249 | 258 | } |
| 250 | 259 | |
| 251 | 260 | /** |