]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/baculum/protected/Pages/API/JobTasks.php
baculum: Assign Baculum copyright to Kern Sibbald
[bacula/bacula] / gui / baculum / protected / Pages / API / JobTasks.php
index 689a1d508a656a843e7f4e94f0022f4a80840ff5..64c17efbc04da9cd968c7bf22be80623c4f629b3 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2015 Marcin Haba
+ * Copyright (C) 2013-2016 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -26,19 +26,31 @@ class JobTasks extends BaculumAPI {
                $directors = $this->getModule('bconsole')->getDirectors();
                if($directors->exitcode === 0) {
                        $jobs = array();
+                       $error = false;
+                       $error_obj = null;
                        for($i = 0; $i < count($directors->output); $i++) {
-                               $jobsList = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('.jobs'), $this->user)->output;
-                               $jobsshow = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'jobs'), $this->user)->output;
+                               $jobsList = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('.jobs'), $this->user);
+                               if ($jobsList->exitcode != 0) {
+                                       $error_obj = $jobsList;
+                                       $error = true;
+                                       break;
+                               }
+                               $jobsshow = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'jobs'), $this->user);
+                               if ($jobsshow->exitcode != 0) {
+                                       $error_obj = $jobsshow;
+                                       $error = true;
+                                       break;
+                               }
                                $jobs[$directors->output[$i]] = array();
-                               for($j = 0; $j < count($jobsList); $j++) {
+                               for($j = 0; $j < count($jobsList->output); $j++) {
                                        /**
                                         * Checking by "show job" command is ugly way to be sure that is reading jobname but not some 
                                         * random output (eg. "You have messages." or debugging).
                                         * For now I did not find nothing better for be sure that output contains job.
                                         */
-                                       for($k = 0; $k < count($jobsshow); $k++) {
-                                               if(preg_match('/^Job: name=' . $jobsList[$j] . '.*/', $jobsshow[$k]) === 1) {
-                                                       $jobs[$directors->output[$i]][] = $jobsList[$j];
+                                       for($k = 0; $k < count($jobsshow->output); $k++) {
+                                               if(preg_match('/^Job: name=' . $jobsList->output[$j] . '.*/', $jobsshow->output[$k]) === 1) {
+                                                       $jobs[$directors->output[$i]][] = $jobsList->output[$j];
                                                        break;
                                                }
                                        }
@@ -48,13 +60,18 @@ class JobTasks extends BaculumAPI {
                                        }
                                }
                        }
-                       $this->output = $jobs;
-                       $this->error =  BconsoleError::ERROR_NO_ERRORS;
+                       if ($error === true) {
+                               $this->output = $error_obj->output;
+                               $this->error = $error_obj->exitcode;
+                       } else {
+                               $this->output = $jobs;
+                               $this->error =  BconsoleError::ERROR_NO_ERRORS;
+                       }
                } else {
-                       $this->output = BconsoleError::MSG_ERROR_BCONSOLE_CONNECTION_PROBLEM;
-                       $this->error = BconsoleError::ERROR_BCONSOLE_CONNECTION_PROBLEM;
+                       $this->output = $directors->output;
+                       $this->error = $directors->exitcode;
                }
        }
 }
 
-?>
\ No newline at end of file
+?>