From: Marcin Haba Date: Fri, 29 Sep 2023 11:09:58 +0000 (+0200) Subject: baculum: Add job name and fileset to status client endpoint X-Git-Tag: Beta-15.0.1~106 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90da32b8b22e29600abbd5b2cb5507b70d720251;p=thirdparty%2Fbacula.git baculum: Add job name and fileset to status client endpoint --- diff --git a/gui/baculum/protected/API/Pages/API/ClientStatus.php b/gui/baculum/protected/API/Pages/API/ClientStatus.php index ba6bc3449..2babd55ea 100644 --- a/gui/baculum/protected/API/Pages/API/ClientStatus.php +++ b/gui/baculum/protected/API/Pages/API/ClientStatus.php @@ -21,6 +21,7 @@ */ use Baculum\API\Modules\ConsoleOutputPage; +use Baculum\API\Modules\StatusClient; use Baculum\Common\Modules\Errors\ClientError; use Baculum\Common\Modules\Errors\GenericError; @@ -65,6 +66,7 @@ class ClientStatus extends ConsoleOutputPage { 'client' => $client->name, 'type' => $type ]); + $this->addExtraProperties($type, $out); } $this->output = $out['output']; $this->error = $out['error']; @@ -96,6 +98,44 @@ class ClientStatus extends ConsoleOutputPage { $params['type'] ); } + + /** + * Add extra properties to JSON status client output. + * + * @param string $type output type (running, terminated...) + * @param string $result client output JSON results (be careful - reference) + */ + private function addExtraProperties($type, &$result) { + if ($type == StatusClient::OUTPUT_TYPE_RUNNING) { + $jobids = []; + for ($i = 0; $i < count($result['output']); $i++) { + $jobids[] = $result['output'][$i]['jobid']; + } + if (count($jobids) == 0) { + // no jobs, no extra props + return; + } + $params = [ + 'Job.JobId' => [[ + 'operator' => 'IN', + 'vals' => $jobids + ]] + ]; + $jobs = $this->getModule('job')->getJobs( + $params + ); + for ($i = 0; $i < count($jobids); $i++) { + for ($j = 0; $j < count($jobs); $j++) { + if ($jobids[$i] != $jobs[$j]->jobid) { + continue; + } + $result['output'][$i]['name'] = $jobs[$j]->name; + $result['output'][$i]['fileset'] = $jobs[$j]->fileset; + break; + } + } + } + } } ?>