]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Pages/API/RestoreRun.php
baculum: Assign Baculum copyright to Kern Sibbald
[bacula/bacula] / gui / baculum / protected / Pages / API / RestoreRun.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2016 Kern Sibbald
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The original author of Bacula is Kern Sibbald, with contributions
10  * from many others, a complete list can be found in the file AUTHORS.
11  *
12  * You may use this file and others of this release according to the
13  * license defined in the LICENSE file, which includes the Affero General
14  * Public License, v3.0 ("AGPLv3") and some additional permissions and
15  * terms pursuant to its AGPLv3 Section 7.
16  *
17  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22  
23 class RestoreRun extends BaculumAPI {
24
25         public function get() {}
26
27         public function create($params) {
28                 $rfile = property_exists($params, 'rpath') ? $params->rpath : null;
29                 $clientid = property_exists($params, 'clientid') ? intval($params->clientid) : null;
30                 $fileset = property_exists($params, 'fileset') ? $params->fileset : null;
31                 $priority = property_exists($params, 'priority') ? intval($params->priority) : null;
32                 $where = property_exists($params, 'where') ? $params->where : null;
33                 $replace = property_exists($params, 'replace') ? $params->replace : null;
34
35                 $client = $this->getModule('client')->getClientById($clientid);
36                 $misc = $this->getModule('misc');
37
38                 if(!is_null($fileset)) {
39                         if(!is_null($client)) {
40                                 if(preg_match($misc::RPATH_PATTERN, $rfile) === 1) {
41                                         if(!is_null($where)) {
42                                                 if(!is_null($replace)) {
43                                                         $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);
44                                                         $this->removeTmpRestoreTable($rfile);
45                                                         $this->output = $restore->output;
46                                                         $this->error = (integer)$restore->exitcode;
47                                                 } else {
48                                                         $this->output = JobError::MSG_ERROR_INVALID_REPLACE_OPTION;
49                                                         $this->error = JobError::ERROR_INVALID_REPLACE_OPTION;
50                                                 }
51                                         } else {
52                                                 $this->output = JobError::MSG_ERROR_INVALID_WHERE_OPTION;
53                                                 $this->error = JobError::ERROR_INVALID_WHERE_OPTION;
54                                         }
55                                 } else {
56                                         $this->output = JobError::MSG_ERROR_INVALID_RPATH;
57                                         $this->error = JobError::ERROR_INVALID_RPATH;
58                                 }
59                         } else {
60                                 $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
61                                 $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
62                         }
63                 } else {
64                         $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
65                         $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
66                 }
67         }
68
69         private function removeTmpRestoreTable($tableName) {
70                 $misc = $this->getModule('misc');
71                 if (preg_match($misc::RPATH_PATTERN, $tableName) === 1) {
72                         $db = new ActiveRecord();
73                         $connection = $db->getDbConnection();
74                         $connection->setActive(true);
75                         $sql = "DROP TABLE $tableName";
76                         $pdo = $connection->getPdoInstance();
77                         $pdo->exec($sql);
78                         $pdo = null;
79                 }
80         }
81 }
82
83 ?>