]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Improve errors handling in API restore pages
authorMarcin Haba <marcin.haba@bacula.pl>
Sat, 3 Jun 2017 17:35:40 +0000 (19:35 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 3 Jun 2017 17:48:49 +0000 (19:48 +0200)
gui/baculum/protected/API/Pages/API/BVFSRestore.php
gui/baculum/protected/API/Pages/API/JobEstimate.php
gui/baculum/protected/API/Pages/API/JobRun.php
gui/baculum/protected/API/Pages/API/RestoreRun.php
gui/baculum/protected/Common/Class/Errors.php

index 02b2298aa96451d1683f8e6de21ce1799b5eb293..0d16ce1d1938a08ecc56aab8289bda4504468287 100644 (file)
@@ -30,14 +30,18 @@ class BVFSRestore extends BaculumAPIServer {
                $path = property_exists($params, 'path') ? $params->path : null;
 
                $is_valid = true;
-               $jobidsList = explode(',', $jobids);
-               if(is_array($jobidsList)) {
-                       for($i = 0; $i < count($jobidsList); $i++) {
-                               $job = $this->getModule('job')->getJobById($jobidsList[$i]);
-                               if(is_null($job)) {
-                                       $is_valid = false;
-                                       break;
+               if (!is_null($jobids)) {
+                       $jobidsList = explode(',', $jobids);
+                       if(is_array($jobidsList)) {
+                               for($i = 0; $i < count($jobidsList); $i++) {
+                                       $job = $this->getModule('job')->getJobById($jobidsList[$i]);
+                                       if(is_null($job)) {
+                                               $is_valid = false;
+                                               break;
+                                       }
                                }
+                       } else {
+                               $is_valid = false;
                        }
                } else {
                        $is_valid = false;
index 5ffb976fc2611fa5268af9c368d426410485a5b1..f42caada9ee8a5781d85abc01e8c699f9282c9dc 100644 (file)
@@ -71,12 +71,12 @@ class JobEstimate extends BaculumAPIServer {
                                                $this->output = $estimation->output;
                                                $this->error = (integer)$estimation->exitcode;
                                        } else {
-                                               $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
-                                               $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
+                                               $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
+                                               $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS;
                                        }
                                } else {
-                                       $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
-                                       $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
+                                       $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS;
+                                       $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS;
                                }
                        } else {
                                $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
index ed4e2305647c551ab9c6b7782c3567fe7adbfb20..36d9436bc20ea582dfb6523e8d5f35197c5e95e7 100644 (file)
@@ -96,20 +96,20 @@ class JobRun extends BaculumAPIServer {
                                                                $this->output = $run->output;
                                                                $this->error = (integer)$run->exitcode;
                                                        } else {
-                                                               $this->output = JobError::MSG_ERROR_POOLID_DOES_NOT_EXISTS;
-                                                               $this->error = JobError::ERROR_POOLID_DOES_NOT_EXISTS;
+                                                               $this->output = JobError::MSG_ERROR_POOL_DOES_NOT_EXISTS;
+                                                               $this->error = JobError::ERROR_POOL_DOES_NOT_EXISTS;
                                                        }
                                                } else {
-                                                       $this->output = JobError::MSG_ERROR_STORAGEID_DOES_NOT_EXISTS;
-                                                       $this->error = JobError::ERROR_STORAGEID_DOES_NOT_EXISTS;
+                                                       $this->output = JobError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS;
+                                                       $this->error = JobError::ERROR_STORAGE_DOES_NOT_EXISTS;
                                                }
                                        } else {
-                                               $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
-                                               $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
+                                               $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
+                                               $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS;
                                        }
                                } else {
-                                       $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
-                                       $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
+                                       $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS;
+                                       $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS;
                                }
                        } else {
                                $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
index 431f4ece9706885b01e7cd6d9f4afa13933c17e9..f7ed970515d6fcd96119e170879a43eeadfd9bc7 100644 (file)
@@ -28,13 +28,22 @@ class RestoreRun extends BaculumAPIServer {
 
        public function create($params) {
                $rfile = property_exists($params, 'rpath') ? $params->rpath : null;
-               $clientid = property_exists($params, 'clientid') ? intval($params->clientid) : null;
-               $fileset = property_exists($params, 'fileset') ? $params->fileset : null;
-               $priority = property_exists($params, 'priority') ? intval($params->priority) : null;
+
+               $fileset = null;
+               if (property_exists($params, 'fileset') && $this->getModule('misc')->isValidName($params->fileset)) {
+                       $fileset = $params->fileset;
+               }
+               $client = null;
+               if (property_exists($params, 'clientid')) {
+                       $clientid = intval($params->clientid);
+                       $client_row = $this->getModule('client')->getClientById($clientid);
+                       $client = is_object($client_row) ? $client_row->name : null;
+               } elseif (property_exists($params, 'client') && $this->getModule('misc')->isValidName($params->client)) {
+                       $client = $params->client;
+               }
+               $priority = property_exists($params, 'priority') ? intval($params->priority) : 10; // default priority is set to 10
                $where = property_exists($params, 'where') ? $params->where : null;
                $replace = property_exists($params, 'replace') ? $params->replace : null;
-
-               $client = $this->getModule('client')->getClientById($clientid);
                $misc = $this->getModule('misc');
 
                if(!is_null($fileset)) {
@@ -42,7 +51,16 @@ class RestoreRun extends BaculumAPIServer {
                                if(preg_match($misc::RPATH_PATTERN, $rfile) === 1) {
                                        if(!is_null($where)) {
                                                if(!is_null($replace)) {
-                                                       $restore = $this->getModule('bconsole')->bconsoleCommand($this->director, array('restore', 'file="?' . $rfile . '"', 'client="' . $client->name . '"', 'where="' . $where . '"', 'replace="' . $replace . '"', 'fileset="' . $fileset . '"', 'priority="' . $priority . '"', 'yes'), $this->user);
+                                                       $command = array('restore',
+                                                               'file="?' . $rfile . '"',
+                                                               'client="' . $client . '"',
+                                                               'where="' . $where . '"',
+                                                               'replace="' . $replace . '"',
+                                                               'fileset="' . $fileset . '"',
+                                                               'priority="' . $priority . '"',
+                                                               'yes'
+                                                       );
+                                                       $restore = $this->getModule('bconsole')->bconsoleCommand($this->director, $command, $this->user);
                                                        $this->removeTmpRestoreTable($rfile);
                                                        $this->output = $restore->output;
                                                        $this->error = (integer)$restore->exitcode;
@@ -59,12 +77,12 @@ class RestoreRun extends BaculumAPIServer {
                                        $this->error = JobError::ERROR_INVALID_RPATH;
                                }
                        } else {
-                               $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
-                               $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
+                               $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
+                               $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS;
                        }
                } else {
-                       $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
-                       $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
+                       $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS;
+                       $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS;
                }
        }
 
@@ -77,7 +95,18 @@ class RestoreRun extends BaculumAPIServer {
                        $connection->setActive(true);
                        $sql = "DROP TABLE $tableName";
                        $pdo = $connection->getPdoInstance();
-                       $pdo->exec($sql);
+                       try {
+                               $pdo->exec($sql);
+                       } catch(PDOException $e) {
+                               $emsg = 'Problem during delete temporary Bvfs table. ' . $e->getMessage();
+                               $this->getModule('logging')->log(
+                                       __FUNCTION__,
+                                       $emsg,
+                                       Logging::CATEGORY_APPLICATION,
+                                       __FILE__,
+                                       __LINE__
+                               );
+                       }
                        $pdo = null;
                }
        }
index e4f5cff5734c5abf5cd6ff0118c4f109cc711d57..8a308d5fb3decc868c16e4184750187529249ac0 100644 (file)
@@ -85,20 +85,20 @@ class PoolError extends GenericError {
 class JobError extends GenericError {
        const ERROR_JOB_DOES_NOT_EXISTS = 50;
        const ERROR_INVALID_JOBLEVEL = 51;
-       const ERROR_FILESETID_DOES_NOT_EXISTS = 52;
-       const ERROR_CLIENTID_DOES_NOT_EXISTS = 53;
-       const ERROR_STORAGEID_DOES_NOT_EXISTS = 54;
-       const ERROR_POOLID_DOES_NOT_EXISTS = 55;
+       const ERROR_FILESET_DOES_NOT_EXISTS = 52;
+       const ERROR_CLIENT_DOES_NOT_EXISTS = 53;
+       const ERROR_STORAGE_DOES_NOT_EXISTS = 54;
+       const ERROR_POOL_DOES_NOT_EXISTS = 55;
        const ERROR_INVALID_RPATH = 56;
        const ERROR_INVALID_WHERE_OPTION = 57;
        const ERROR_INVALID_REPLACE_OPTION = 58;
 
        const MSG_ERROR_JOB_DOES_NOT_EXISTS = 'Job with inputted jobid does not exist.';
        const MSG_ERROR_INVALID_JOBLEVEL = 'Inputted job level is invalid.';
-       const MSG_ERROR_FILESETID_DOES_NOT_EXISTS = 'FileSet resource with inputted filesetid does not exist.';
-       const MSG_ERROR_CLIENTID_DOES_NOT_EXISTS = 'Client with inputted clientid does not exist.';
-       const MSG_ERROR_STORAGEID_DOES_NOT_EXISTS = 'Storage with inputted storageid does not exist.';
-       const MSG_ERROR_POOLID_DOES_NOT_EXISTS = 'Pool with inputted poolid does not exist.';
+       const MSG_ERROR_FILESET_DOES_NOT_EXISTS = 'FileSet resource does not exist.';
+       const MSG_ERROR_CLIENT_DOES_NOT_EXISTS = 'Client does not exist.';
+       const MSG_ERROR_STORAGE_DOES_NOT_EXISTS = 'Storage does not exist.';
+       const MSG_ERROR_POOL_DOES_NOT_EXISTS = 'Pool does not exist.';
        const MSG_ERROR_INVALID_RPATH = 'Inputted rpath for restore is invalid. Proper format is b2[0-9]+.';
        const MSG_ERROR_INVALID_WHERE_OPTION = 'Inputted "where" option is invalid.';
        const MSG_ERROR_INVALID_REPLACE_OPTION = 'Inputted "replace" option is invalid.';