]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/baculum/protected/API/Pages/API/FileSets.php
baculum: API endpoints code refactor
[bacula/bacula] / gui / baculum / protected / API / Pages / API / FileSets.php
index c0406356428103723eed6f5628a569dc385f228a..cb59e7be922df4b17b39facc6d800136aad89fb6 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 FileSets extends BaculumAPIServer {
        public function get() {
                $directors = $this->getModule('bconsole')->getDirectors();
-               if($directors->exitcode === 0) {
-                       $filesets = array();
-                       $error = false;
-                       $error_obj = null;
-                       for($i = 0; $i < count($directors->output); $i++) {
-                               $filesetsshow = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'fileset'), $this->user);
-                               if ($filesetsshow->exitcode != 0) {
-                                       $error_obj = $filesetsshow;
-                                       $error = true;
-                                       break;
-                               }
-                               $filesets[$directors->output[$i]] = array();
-                               
-                               for($j = 0; $j < count($filesetsshow->output); $j++) {
-                                       if(preg_match('/^FileSet:\ name=(.+?(?=\s\S+\=.+)|.+$)/i', $filesetsshow->output[$j], $match) === 1) {
-                                               $filesets[$directors->output[$i]][] = $match[1];
-                                       }
-                               }
+               if($directors->exitcode != 0) {
+                       $this->output = $directors->output;
+                       $this->error = $directors->exitcode;
+                       return;
+               }
+
+               $filesets = array();
+               $error = false;
+               $error_obj = null;
+               for($i = 0; $i < count($directors->output); $i++) {
+                       $result = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'fileset'));
+                       if ($result->exitcode != 0) {
+                               $error_obj = $result;
+                               $error = true;
+                               break;
                        }
+                       $filesets[$directors->output[$i]] = array();
 
-                       if ($error === true) {
-                               $this->output = $error_obj->output;
-                               $this->error = $error_obj->exitcode;
-                       } else {
-                               $this->output = $filesets;
-                               $this->error =  BconsoleError::ERROR_NO_ERRORS;
+                       for($j = 0; $j < count($result->output); $j++) {
+                               if(preg_match('/^FileSet:\ name=(.+?(?=\s\S+\=.+)|.+$)/i', $result->output[$j], $match) === 1) {
+                                       $filesets[$directors->output[$i]][] = $match[1];
+                               }
                        }
+               }
+
+               if ($error === true) {
+                       $this->output = $error_obj->output;
+                       $this->error = $error_obj->exitcode;
                } else {
-                       $this->output = $directors->output;
-                       $this->error = $directors->exitcode;
+                       $this->output = $filesets;
+                       $this->error =  BconsoleError::ERROR_NO_ERRORS;
                }
        }
 }