From 898cf73af88694cd32f57269619faa82d88be623 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Sat, 13 May 2023 15:52:54 +0100 Subject: [PATCH 1/3] fix: consider request time for stand requests --- app/Allocator/Stand/AbstractArrivalStandAllocator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Allocator/Stand/AbstractArrivalStandAllocator.php b/app/Allocator/Stand/AbstractArrivalStandAllocator.php index 33267e5bd..0ae82a5fd 100644 --- a/app/Allocator/Stand/AbstractArrivalStandAllocator.php +++ b/app/Allocator/Stand/AbstractArrivalStandAllocator.php @@ -5,6 +5,7 @@ use App\Models\Aircraft\Aircraft; use App\Models\Stand\Stand; use App\Models\Vatsim\NetworkAircraft; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Query\JoinClause; @@ -59,7 +60,8 @@ private function applyBaseOrderingToStandsQuery(Builder $query, NetworkAircraft ->leftJoin('stand_requests as other_stand_requests', function (JoinClause $join) use ($aircraft) { // Prefer stands that haven't been requested by someone else $join->on('stands.id', '=', 'other_stand_requests.stand_id') - ->on('other_stand_requests.user_id', '<>', $join->raw($aircraft->cid)); + ->on('other_stand_requests.user_id', '<>', $join->raw($aircraft->cid)) + ->on('other_stand_requests.requested_time', '>', Carbon::now()); }) ->orderByRaw('other_stand_requests.id IS NULL') ->inRandomOrder(); From ef6747f93e3a0320d76fe37660963244b1b9b403 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Sat, 13 May 2023 16:09:59 +0100 Subject: [PATCH 2/3] fix: query escaping --- app/Allocator/Stand/AbstractArrivalStandAllocator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Allocator/Stand/AbstractArrivalStandAllocator.php b/app/Allocator/Stand/AbstractArrivalStandAllocator.php index 0ae82a5fd..71c3c0ac0 100644 --- a/app/Allocator/Stand/AbstractArrivalStandAllocator.php +++ b/app/Allocator/Stand/AbstractArrivalStandAllocator.php @@ -61,7 +61,7 @@ private function applyBaseOrderingToStandsQuery(Builder $query, NetworkAircraft // Prefer stands that haven't been requested by someone else $join->on('stands.id', '=', 'other_stand_requests.stand_id') ->on('other_stand_requests.user_id', '<>', $join->raw($aircraft->cid)) - ->on('other_stand_requests.requested_time', '>', Carbon::now()); + ->on('other_stand_requests.requested_time', '>', $join->raw(Carbon::now())); }) ->orderByRaw('other_stand_requests.id IS NULL') ->inRandomOrder(); From 0a88bcb8b6eb35c172d8d84e8c077a8431eb3429 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Sat, 13 May 2023 16:29:48 +0100 Subject: [PATCH 3/3] fix: query escaping --- app/Allocator/Stand/AbstractArrivalStandAllocator.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Allocator/Stand/AbstractArrivalStandAllocator.php b/app/Allocator/Stand/AbstractArrivalStandAllocator.php index 71c3c0ac0..35efcb1e6 100644 --- a/app/Allocator/Stand/AbstractArrivalStandAllocator.php +++ b/app/Allocator/Stand/AbstractArrivalStandAllocator.php @@ -61,7 +61,16 @@ private function applyBaseOrderingToStandsQuery(Builder $query, NetworkAircraft // Prefer stands that haven't been requested by someone else $join->on('stands.id', '=', 'other_stand_requests.stand_id') ->on('other_stand_requests.user_id', '<>', $join->raw($aircraft->cid)) - ->on('other_stand_requests.requested_time', '>', $join->raw(Carbon::now())); + ->on( + 'other_stand_requests.requested_time', + '>', + $join->raw( + sprintf( + '\'%s\'', + Carbon::now() + ) + ) + ); }) ->orderByRaw('other_stand_requests.id IS NULL') ->inRandomOrder();