PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
← All changes | app/Repositories/RecurringAvailabilityRepository.php +21 -6 3.0.7trunk View file →
@@ -223,23 +223,38 @@
223 223 */
224 224 public function findActiveRulesForDate(int $tripId, string $date): array
225 225 {
226 226 $table = esc_sql($this->table);
227 -
227 +
228 + // Date-only compare: start_date/end_date are DATE columns, so a datetime
229 + // input would break the `end_date >= %s` boundary (DATE treated as midnight).
230 + if (preg_match('/^(\d{4}-\d{2}-\d{2})/', $date, $m)) {
231 + $date = $m[1];
232 + }
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.
228 243 $query = $this->wpdb->prepare(
229 - "SELECT * FROM `{$table}`
230 - WHERE trip_id = %d
244 + "SELECT * FROM `{$table}`
245 + WHERE trip_id = %d
231 246 AND status = 'active'
232 247 AND start_date <= %s
233 248 AND (end_date IS NULL OR end_date >= %s)
234 - ORDER BY priority DESC",
249 + ORDER BY priority DESC, created_at DESC, id DESC",
235 250 $tripId,
236 251 $date,
237 252 $date
238 253 );
239 -
254 +
240 255 $results = $this->wpdb->get_results($query);
241 -
256 +
242 257 return array_map([$this, 'hydrateRule'], $results ?: []);
243 258 }
244 259
245 260 /**