From ecee271ac11f90905d24a1d8ce9cde8f4fc80534 Mon Sep 17 00:00:00 2001 From: Mark Unwin Date: Tue, 6 Feb 2024 21:41:39 +1000 Subject: [PATCH] Fix Collector Dashboard. --- app/Config/Routes.php | 2 +- app/Controllers/Help.php | 7 +++++-- app/Models/TasksModel.php | 7 ++++++- app/Views/dashboardsCollector.php | 12 ++++++------ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c17a44145..4916bdbcc 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -81,7 +81,7 @@ $routes->get('features', 'Help::features', ['filter' => \App\Filters\Session::class, 'as' => 'features']); $routes->get('prereq', 'Help::prereq', ['filter' => \App\Filters\Session::class, 'as' => 'prereq']); $routes->get('welcome', 'Help::welcome', ['filter' => \App\Filters\Session::class, 'as' => 'welcome']); -$routes->get('dashboards/collector', 'Help::collector', ['filter' => \App\Filters\Session::class, 'as' => 'dashboardCollector']); +$routes->get('collector', 'Help::collector', ['filter' => \App\Filters\Session::class, 'as' => 'dashboardCollector']); $routes->get('appLicenses', 'Help::licenses', ['filter' => \App\Filters\Session::class, 'as' => 'appLicenses']); $routes->get('getting_started', 'Help::gettingStarted', ['filter' => \App\Filters\Session::class, 'as' => 'getting_started']); $routes->get('discovery_issues/(:num)', 'Help::discoveryIssues/$1', ['filter' => \App\Filters\Session::class, 'as' => 'discoveryIssues']); diff --git a/app/Controllers/Help.php b/app/Controllers/Help.php index c62cfac2e..1a4f95e39 100644 --- a/app/Controllers/Help.php +++ b/app/Controllers/Help.php @@ -69,10 +69,13 @@ public function about() */ public function collector() { + if (empty($this->config->servers)) { + return redirect()->route('home'); + } $tasksModel = new \App\Models\TasksModel(); - $tasks = $tasksModel->collection(); + $tasks = $tasksModel->listAll(); foreach ($tasks as $task) { - if ($task->attributes->type === 'collector') { + if ($task->type === 'collector') { $this->resp->data[] = $task; } } diff --git a/app/Models/TasksModel.php b/app/Models/TasksModel.php index 0a6b3e14c..a83163526 100644 --- a/app/Models/TasksModel.php +++ b/app/Models/TasksModel.php @@ -119,7 +119,12 @@ public function includedRead(int $id = 0): array { $result = $this->builder->getWhere(['id' => intval($id)])->getResult()[0]; $type = ucfirst($result->type); - $namespace = "\\App\\Models\\" . $type . "Model"; + if ($type != 'Collector') { + $namespace = "\\App\\Models\\" . $type . "Model"; + } + if ($type === 'Collector') { + $namespace = "\\App\\Models\\CollectorsModel"; + } $typeModel = new $namespace; $included[strtolower($type)] = $typeModel->listUser(); diff --git a/app/Views/dashboardsCollector.php b/app/Views/dashboardsCollector.php index 44790f98e..feb680222 100644 --- a/app/Views/dashboardsCollector.php +++ b/app/Views/dashboardsCollector.php @@ -3,11 +3,11 @@ # SPDX-License-Identifier: AGPL-3.0-or-later include 'shared/collection_functions.php'; $every = ''; -if (stripos($data[0]->{'attributes'}->{'hour'}, '*/') !== false) { - $every = str_replace('*/', '', $data[0]->{'attributes'}->{'hour'}) . ' hours'; +if (stripos($data[0]->{'hour'}, '*/') !== false) { + $every = str_replace('*/', '', $data[0]->{'hour'}) . ' hours'; } -if (stripos($data[0]->{'attributes'}->{'minute'}, '*/') !== false) { - $minute = str_replace('*/', '', $data[0]->{'attributes'}->{'minute'}); +if (stripos($data[0]->{'minute'}, '*/') !== false) { + $minute = str_replace('*/', '', $data[0]->{'minute'}); if ($every != "") { $every .= ', ' . $minute . ' minutes'; } else { @@ -29,8 +29,8 @@


This collector requests tasks every .

- {'attributes'}->{'last_run'} != "2000-01-01 00:00:00") { ?> - The last time this task was run was {'attributes'}->{'last_run'}; ?>.

+ {'last_run'} != "2000-01-01 00:00:00") { ?> + The last time this task was run was {'last_run'}; ?>.

This task has not yet been run.