From 476918c1b1ca7fa814a247592934eae0c6f0d90b Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Sat, 12 Dec 2015 20:30:10 +0100 Subject: [PATCH] baculum: Remove temporary Bvfs table when restore starts --- gui/baculum/protected/Class/Miscellaneous.php | 2 ++ .../protected/Pages/API/RestoreRun.php | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gui/baculum/protected/Class/Miscellaneous.php b/gui/baculum/protected/Class/Miscellaneous.php index 9b1725d6bd..bb8a7170f6 100644 --- a/gui/baculum/protected/Class/Miscellaneous.php +++ b/gui/baculum/protected/Class/Miscellaneous.php @@ -20,6 +20,8 @@ class Miscellaneous extends TModule { const LICENCE_FILE = 'LICENSE'; + const RPATH_PATTERN = '/^b2\d+$/'; + private $jobTypes = array( 'B' => 'Backup', 'M' => 'Migrated', diff --git a/gui/baculum/protected/Pages/API/RestoreRun.php b/gui/baculum/protected/Pages/API/RestoreRun.php index 44d243a2e2..4599987210 100644 --- a/gui/baculum/protected/Pages/API/RestoreRun.php +++ b/gui/baculum/protected/Pages/API/RestoreRun.php @@ -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 +?> -- 2.39.5