From b2a5d86e30c54a51d14b6c04658dd9ec09de6338 Mon Sep 17 00:00:00 2001 From: Tobias Regnery Date: Wed, 8 May 2024 09:34:35 +0200 Subject: [PATCH] Fixes #14701 - wrong total asset count The total asset count in the sidenav shows the ready to deploy count instead of the total count. Fix this by adjusting the query to all assets. Also respect the setting for archived assets. Add a default value for total assets, since we are now using the settings-variable, which is not available during the setup process. While at it, move the block for total assets before the ready to deploy assets to match the ordering of the sidenav. Signed-off-by: Tobias Regnery --- app/Http/Middleware/AssetCountForSidebar.php | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Http/Middleware/AssetCountForSidebar.php b/app/Http/Middleware/AssetCountForSidebar.php index e529f75ef..9d81eca93 100644 --- a/app/Http/Middleware/AssetCountForSidebar.php +++ b/app/Http/Middleware/AssetCountForSidebar.php @@ -21,25 +21,36 @@ class AssetCountForSidebar /** * This needs to be set for the /setup process, since the tables might not exist yet */ + $total_assets = 0; $total_due_for_checkin = 0; $total_overdue_for_checkin = 0; $total_due_for_audit = 0; $total_overdue_for_audit = 0; try { - $total_rtd_sidebar = Asset::RTD()->count(); - view()->share('total_rtd_sidebar', $total_rtd_sidebar); + $settings = Setting::getSettings(); + view()->share('settings', $settings); } catch (\Exception $e) { \Log::debug($e); } try { - $total_assets = Asset::RTD()->count(); + $total_assets = Asset::all()->count(); + if ($settings->show_archived_in_list != '1') { + $total_assets -= Asset::Archived()->count(); + } view()->share('total_assets', $total_assets); } catch (\Exception $e) { \Log::debug($e); } + try { + $total_rtd_sidebar = Asset::RTD()->count(); + view()->share('total_rtd_sidebar', $total_rtd_sidebar); + } catch (\Exception $e) { + \Log::debug($e); + } + try { $total_deployed_sidebar = Asset::Deployed()->count(); view()->share('total_deployed_sidebar', $total_deployed_sidebar); @@ -75,13 +86,6 @@ class AssetCountForSidebar \Log::debug($e); } - try { - $settings = Setting::getSettings(); - view()->share('settings', $settings); - } catch (\Exception $e) { - \Log::debug($e); - } - try { $total_due_for_audit = Asset::DueForAudit($settings)->count(); view()->share('total_due_for_audit', $total_due_for_audit);