From e9c3d6bfb79df284dd72b3bbff020b4e5c31b37f Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 17 Oct 2017 12:48:18 -0700 Subject: [PATCH] Full text search fixes - addresses laravel bug :( --- app/Http/Controllers/Api/AssetsController.php | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index b27fe9f0a..fbcf9f248 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -137,30 +137,61 @@ class AssetsController extends Controller // This is used by the sidenav, mostly + + // We switched from using query scopes here because of a Laravel bug + // related to fulltext searches on complex queries. + // I am sad. :( switch ($request->input('status')) { case 'Deleted': $assets->withTrashed()->Deleted(); break; case 'Pending': - $assets->Pending(); + $assets->join('status_labels',function ($join) { + $join->on('status_labels.id', "=", "assets.status_id") + ->where('status_labels.deployable','=',0) + ->where('status_labels.pending','=',1) + ->where('status_labels.archived', '=', 0); + }); break; case 'RTD': - $assets->RTD(); + $assets->join('status_labels',function ($join) { + $join->on('status_labels.id', "=", "assets.status_id") + ->where('status_labels.deployable','=',1) + ->where('status_labels.pending','=',0) + ->where('status_labels.archived', '=', 0); + }); break; case 'Undeployable': $assets->Undeployable(); break; case 'Archived': - $assets->Archived(); + $assets->join('status_labels',function ($join) { + $join->on('status_labels.id', "=", "assets.status_id") + ->where('status_labels.deployable','=',0) + ->where('status_labels.pending','=',0) + ->where('status_labels.archived', '=', 1); + }); break; case 'Requestable': - $assets->RequestableAssets(); + $assets->where('assets.requestable', '=', 1) + ->join('status_labels',function ($join) { + $join->on('status_labels.id', "=", "assets.status_id") + ->where('status_labels.deployable','=',1) + ->where('status_labels.pending','=',0) + ->where('status_labels.archived', '=', 0); + }); + break; case 'Deployed': - $assets->Deployed(); + // more sad, horrible workarounds for laravel bugs when doing full text searches + $assets->where('assets.assigned_to', '>', '0'); break; default: - $assets->NotArchived(); + // terrible workaround for complex-query Laravel bug in fulltext + $assets->join('status_labels',function ($join) { + $join->on('status_labels.id', "=", "assets.status_id") + ->where('status_labels.archived', '=', 0); + }); }