]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Get the most recent jobs by client and fileset or by clientid and filesetid
authorMarcin Haba <marcin.haba@bacula.pl>
Sun, 30 Jul 2017 12:34:45 +0000 (14:34 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sun, 30 Jul 2017 13:01:20 +0000 (15:01 +0200)
gui/baculum/protected/API/Class/JobManager.php
gui/baculum/protected/API/Pages/API/JobsRecent.php
gui/baculum/protected/API/endpoints.xml

index 0beb5f4396b6c28c1502d615c478f177751a1799..e138a71f665e08c7240c6a42552b0cdfac1c84da 100644 (file)
@@ -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';
index 31f402cdf71154527a383349ea6797cf707f4086..9048c029c8ac38fe68aa3e1d4d2414b9af5fba05 100644 (file)
@@ -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
 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
+?>
index 4d003682048fe98a66e4c41b1beb6ffa41c3a2d8..dc9aa05dbcd49f0f9aeffce8a92699334fb28da0 100644 (file)
@@ -59,7 +59,8 @@
        <url ServiceParameter="API.JobTasks" pattern="api/jobs/tasks/limit/{limit}/" parameters.limit="\d+" />
        <url ServiceParameter="API.Job" pattern="api/jobs/{id}/" parameters.id="\d+" />
        <url ServiceParameter="API.Jobs" pattern="api/jobs/limit/{limit}/" parameters.limit="\d+" />
-       <url ServiceParameter="API.JobsRecent" pattern="api/jobs/recent/{name}/{clientid}/" parameters.name="[a-zA-Z0-9:.\-_ ]+" parameters.clientid="\d+" />
+       <url ServiceParameter="API.JobsRecent" pattern="api/jobs/recent/{name}/client/{client}/fileset/{fileset}/" parameters.name="[a-zA-Z0-9:.\-_ ]+" parameters.client="[a-zA-Z0-9:.\-_ ]+" parameters.fileset="[a-zA-Z0-9:.\-_ ]+" />
+       <url ServiceParameter="API.JobsRecent" pattern="api/jobs/recent/{name}/clientid/{clientid}/filesetid/{filesetid}/" parameters.name="[a-zA-Z0-9:.\-_ ]+" parameters.clientid="\d+" parameters.filesetid="\d+" />
        <url ServiceParameter="API.JobEstimate" pattern="api/jobs/estimate/" />
        <url ServiceParameter="API.JobRun" pattern="api/jobs/run/" />
        <url ServiceParameter="API.JobCancel" pattern="api/jobs/cancel/{id}/" parameters.id="\d+"/>