]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Remove temporary Bvfs table when restore starts
authorMarcin Haba <marcin.haba@bacula.pl>
Sat, 12 Dec 2015 19:30:10 +0000 (20:30 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 12 Dec 2015 19:30:10 +0000 (20:30 +0100)
gui/baculum/protected/Class/Miscellaneous.php
gui/baculum/protected/Pages/API/RestoreRun.php

index 9b1725d6bd17b04b9c37083286f84fef4f06553b..bb8a7170f67e94ecd3c1dde26e2114bbab4a6330 100644 (file)
@@ -20,6 +20,8 @@ class Miscellaneous extends TModule {
 
        const LICENCE_FILE = 'LICENSE';
 
+       const RPATH_PATTERN = '/^b2\d+$/';
+
        private $jobTypes = array(
                'B' => 'Backup',
                'M' => 'Migrated',
index 44d243a2e246dec0c5eee17b39efb2ac65093712..4599987210a69fa180f580023ec33e173b4cab41 100644 (file)
@@ -33,13 +33,15 @@ class RestoreRun extends BaculumAPI {
                $replace = property_exists($params, 'replace') ? $params->replace : null;
 
                $client = $this->getModule('client')->getClientById($clientid);
+               $misc = $this->getModule('misc');
 
                if(!is_null($fileset)) {
                        if(!is_null($client)) {
-                               if(preg_match('/^b2[\d]+$/', $rfile) === 1) {
+                               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);
+                                                       $this->removeTmpRestoreTable($rfile);
                                                        $this->output = $restore->output;
                                                        $this->error = (integer)$restore->exitcode;
                                                } else {
@@ -63,6 +65,19 @@ class RestoreRun extends BaculumAPI {
                        $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
                }
        }
+
+       private function removeTmpRestoreTable($tableName) {
+               $misc = $this->getModule('misc');
+               if (preg_match($misc::RPATH_PATTERN, $tableName) === 1) {
+                       $db = new ActiveRecord();
+                       $connection = $db->getDbConnection();
+                       $connection->setActive(true);
+                       $sql = "DROP TABLE $tableName";
+                       $pdo = $connection->getPdoInstance();
+                       $pdo->exec($sql);
+                       $pdo = null;
+               }
+       }
 }
 
-?>
\ No newline at end of file
+?>