Skip to main content

Rentiva v4.58.1 — Critical: Double-Booking Fix on Same-Day Returns

· 2 min read
MaxHandMade
Maintainer

AutoComplete cron compared dropoff_date < NOW() at date-only granularity. MySQL cast YYYY-MM-DD to YYYY-MM-DD 00:00:00, so any confirmed booking with a same-day dropoff was auto-completed at midnight — long before the actual return time. has_overlap() then skipped these wrongly-completed bookings (status filter excluded 'completed'), allowing the same vehicle to be double-booked for the remaining rental hours. This release fixes the cron, adds defense-in-depth at has_overlap(), opens a completed → in_progress Status transition, and ships a maintenance script to revert already-contaminated bookings.

Optional after upgrade

A maintenance script lives in the GitHub repository at bin/cleanup-early-completed-bookings.php (intentionally not bundled in the production ZIP). If you suspect contaminated bookings (status completed while the real end_ts is still in the future), copy the file onto a deployed site and run:

# dry-run (default)
wp eval-file plugins/mhm-rentiva/bin/cleanup-early-completed-bookings.php

# revert to in_progress
wp eval-file plugins/mhm-rentiva/bin/cleanup-early-completed-bookings.php apply

The script routes through Status::update_status(), so audit hooks fire and the cache invalidates per fix. Idempotent — re-running after apply finds zero rows.

What's New

Critical Fix

  • AutoComplete cron now uses datetime. Primary signal: _mhm_end_ts (UNIX timestamp). Fallback: CONCAT(_mhm_dropoff_date, ' ', _mhm_dropoff_time), with 23:59:59 if dropoff_time is missing — never auto-completes mid-day. Legacy _mhm_end_date fallback preserved.

Defense-in-Depth

  • has_overlap() now flags 'completed' bookings whose end_ts is still in the future, blocking availability even if a future cron bug or manual mishap marks a booking complete early.

Feature

  • Status transition matrix allows completedin_progress for early-completion correction (required by the cleanup script's audited update chain).

Tools

  • bin/cleanup-early-completed-bookings.phpwp eval-file script. Default is dry-run; positional apply reverts contaminated rows via Status::update_status() so mhm_rentiva_booking_status_changed fires for audit/cache invalidation. Idempotent.

Tests

11 new PHPUnit tests across AutoCompleteCronDatetime, HasOverlapStatusFilter, and StatusTransition suites — total 1,231 tests / 3,726 assertions, 7 documented saas_block env-quota baseline failures, 15 skipped. No regression.