From a4128931fa5a65b53a0278c2c3eae42f5bee74be Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Sun, 30 Jul 2017 14:34:45 +0200 Subject: [PATCH] baculum: Get the most recent jobs by client and fileset or by clientid and filesetid --- .../protected/API/Class/JobManager.php | 4 +- .../protected/API/Pages/API/JobsRecent.php | 44 +++++++++++++++---- gui/baculum/protected/API/endpoints.xml | 3 +- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/gui/baculum/protected/API/Class/JobManager.php b/gui/baculum/protected/API/Class/JobManager.php index 0beb5f4396..e138a71f66 100644 --- a/gui/baculum/protected/API/Class/JobManager.php +++ b/gui/baculum/protected/API/Class/JobManager.php @@ -65,8 +65,8 @@ class JobManager extends APIModule { return JobRecord::finder()->deleteByjobid($id); } - public function getRecentJobids($jobname, $clientid) { - $sql = "name='$jobname' AND clientid='$clientid' AND jobstatus IN ('T', 'W') AND level IN ('F', 'I', 'D')"; + public function getRecentJobids($jobname, $clientid, $filesetid) { + $sql = "name='$jobname' AND clientid='$clientid' AND filesetid='$filesetid' AND jobstatus IN ('T', 'W') AND level IN ('F', 'I', 'D')"; $finder = JobRecord::finder(); $criteria = new TActiveRecordCriteria; $order = 'EndTime'; diff --git a/gui/baculum/protected/API/Pages/API/JobsRecent.php b/gui/baculum/protected/API/Pages/API/JobsRecent.php index 31f402cdf7..9048c029c8 100644 --- a/gui/baculum/protected/API/Pages/API/JobsRecent.php +++ b/gui/baculum/protected/API/Pages/API/JobsRecent.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -23,16 +23,42 @@ class JobsRecent extends BaculumAPIServer { public function get() { $jobname = $this->Request['name']; - $clientid = intval($this->Request['clientid']); - $jobs = $this->getModule('job')->getRecentJobids($jobname, $clientid); - if(!is_null($jobs)) { - $this->output = $jobs; - $this->error = JobError::ERROR_NO_ERRORS; + $clientid = null; + if ($this->Request->contains('clientid')) { + $clientid = intval($this->Request['clientid']); + } elseif ($this->Request->contains('client') && $this->getModule('misc')->isValidName($this->Request['client'])) { + $client = $this->Request['client']; + $client_row = $this->getModule('client')->getClientByName($client); + $clientid = is_object($client_row) ? $client_row->clientid : null; + } + $filesetid = null; + if ($this->Request->contains('filesetid')) { + $filesetid = intval($this->Request['filesetid']); + } elseif ($this->Request->contains('fileset') && $this->getModule('misc')->isValidName($this->Request['fileset'])) { + $fileset = $this->Request['fileset']; + $fileset_row = $this->getModule('fileset')->getFileSetByName($fileset); + $filesetid = is_object($fileset_row) ? $fileset_row->filesetid : null; + } + + if (is_int($clientid)) { + if (is_int($filesetid)) { + $jobs = $this->getModule('job')->getRecentJobids($jobname, $clientid, $filesetid); + if(!is_null($jobs)) { + $this->output = $jobs; + $this->error = JobError::ERROR_NO_ERRORS; + } else { + $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS; + } + } else { + $this->output = FileSetError::MSG_ERROR_FILESET_DOES_NOT_EXISTS; + $this->error = FileSetError::ERROR_FILESET_DOES_NOT_EXISTS; + } } else { - $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS; + $this->output = ClientError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS; + $this->error = ClientError::ERROR_CLIENT_DOES_NOT_EXISTS; } } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/endpoints.xml b/gui/baculum/protected/API/endpoints.xml index 4d00368204..dc9aa05dbc 100644 --- a/gui/baculum/protected/API/endpoints.xml +++ b/gui/baculum/protected/API/endpoints.xml @@ -59,7 +59,8 @@ - + + -- 2.39.5