PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.17
Yatra – Travel Booking & Tour Operator Software v3.0.17
3.0.17 3.0.16 3.0.15 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 All 85 releases
← All changes | app/Repositories/AvailabilityRepository.php +28 -7 3.0.7 → 3.0.17 View file →
@@ -72,9 +72,15 @@
72 72 */
73 73 public function findByTripIdAndDate(int $tripId, string $departureDate): ?object
74 74 {
75 75 $table = esc_sql($this->table);
76 -
76 +
77 + // departure_date is a DATE column — strip any time component so a datetime
78 + // input still matches (avoids date-vs-datetime string-compare misses).
79 + if (preg_match('/^(\d{4}-\d{2}-\d{2})/', $departureDate, $m)) {
80 + $departureDate = $m[1];
81 + }
82 +
77 83 $result = $this->wpdb->get_row($this->wpdb->prepare(
78 84 "SELECT * FROM `{$table}`
79 85 WHERE trip_id = %d
80 86 AND departure_date = %s
@@ -178,21 +184,25 @@
178 184
179 185 return $results ?: [];
180 186 }
181 187
182 - public function existsForTripDateTime(int $tripId, string $departureDate, ?string $departureTime): bool
188 + public function existsForTripDateTime(int $tripId, string $departureDate, ?string $departureTime, ?int $excludeId = null): bool
183 189 {
184 190 $table = esc_sql($this->table);
185 191
192 + // Optional so update() can ignore the row it is editing; omitted, behaviour
193 + // is exactly as before for existing callers.
194 + $exclude = $excludeId !== null ? $this->wpdb->prepare(' AND id <> %d', $excludeId) : '';
195 +
186 196 if ($departureTime === null || $departureTime === '') {
187 197 $count = (int) $this->wpdb->get_var($this->wpdb->prepare(
188 - "SELECT COUNT(*) FROM `{$table}` WHERE trip_id = %d AND departure_date = %s AND departure_time IS NULL",
198 + "SELECT COUNT(*) FROM `{$table}` WHERE trip_id = %d AND departure_date = %s AND departure_time IS NULL{$exclude}",
189 199 $tripId,
190 200 $departureDate
191 201 ));
192 202 } else {
193 203 $count = (int) $this->wpdb->get_var($this->wpdb->prepare(
194 - "SELECT COUNT(*) FROM `{$table}` WHERE trip_id = %d AND departure_date = %s AND departure_time = %s",
204 + "SELECT COUNT(*) FROM `{$table}` WHERE trip_id = %d AND departure_date = %s AND departure_time = %s{$exclude}",
195 205 $tripId,
196 206 $departureDate,
197 207 $departureTime
198 208 ));
@@ -336,15 +346,26 @@
336 346 if (!empty($insertData['original_price']) && !empty($insertData['discounted_price']) && empty($data['discount_percentage'])) {
337 347 $insertData['discount_percentage'] = round((($insertData['original_price'] - $insertData['discounted_price']) / $insertData['original_price']) * 100, 2);
338 348 }
339 349
340 - $this->wpdb->insert($table, $insertData, [
350 + $inserted = $this->wpdb->insert($table, $insertData, [
341 351 '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d',
342 352 '%s', '%f', '%f', '%f', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d',
343 353 '%d', '%s', '%d',
344 354 ]);
345 -
346 - return $this->wpdb->insert_id;
355 +
356 + // A rejected insert used to be swallowed: insert_id stays 0, the caller
357 + // looks up row 0, gets null, and trips its own return type with a fatal
358 + // TypeError. Fail loudly instead so the caller can report something useful.
359 + if ($inserted === false) {
360 + throw new \RuntimeException(
361 + $this->wpdb->last_error !== ''
362 + ? $this->wpdb->last_error
363 + : 'Could not save the availability date.'
364 + );
365 + }
366 +
367 + return (int) $this->wpdb->insert_id;
347 368 }
348 369
349 370 /**
350 371 * Update availability date