From e92f5b3d34ffabb4037ea4b35e6a4e781675a007 Mon Sep 17 00:00:00 2001 From: csikosjanos Date: Tue, 23 May 2006 14:15:28 +0000 Subject: [PATCH] Restore part of #1608 --- .../modules/htmlUI/var/html/ui_browser.php | 6 +- .../modules/htmlUI/var/html/ui_handler.php | 16 +++- .../lang/default_DEFAULT/templates.xml | 4 + .../var/templates/backup/fileBrowser.tpl | 14 ++- .../htmlUI/var/templates/backup/restore.tpl | 10 ++- .../src/modules/htmlUI/var/ui_conf.php | 1 + .../modules/htmlUI/var/ui_exchange.class.php | 86 ++++++++++++++++--- .../src/modules/storageServer/bin/restore.php | 40 +++++++++ .../src/modules/storageServer/var/Restore.php | 2 +- 9 files changed, 156 insertions(+), 23 deletions(-) create mode 100755 livesupport/src/modules/storageServer/bin/restore.php diff --git a/livesupport/src/modules/htmlUI/var/html/ui_browser.php b/livesupport/src/modules/htmlUI/var/html/ui_browser.php index a0bec836c..d7c2c7306 100644 --- a/livesupport/src/modules/htmlUI/var/html/ui_browser.php +++ b/livesupport/src/modules/htmlUI/var/html/ui_browser.php @@ -160,15 +160,17 @@ if (is_array($_REQUEST['popup'])){ $Smarty->display('popup/help.tpl'); break; - case "BACKUP.setLocation": + case 'BACKUP.setLocation': if ($_REQUEST['cd']) { $uiBrowser->EXCHANGE->setFolder($_REQUEST['cd']); } + $Smarty->assign('isRestore',$_REQUEST['isRestore']); $Smarty->display('backup/fileBrowser.tpl'); break; case 'BACKUP.setFile': - $uiBrowser->EXCHANGE->setFile($_REQUEST['file']); + $Smarty->assign('isFile',$uiBrowser->EXCHANGE->setFile($_REQUEST['file'])); + $Smarty->assign('isRestore',$_REQUEST['isRestore']); $Smarty->display('backup/fileBrowser.tpl'); break; diff --git a/livesupport/src/modules/htmlUI/var/html/ui_handler.php b/livesupport/src/modules/htmlUI/var/html/ui_handler.php index ca16f5ac5..b217cd3e3 100644 --- a/livesupport/src/modules/htmlUI/var/html/ui_handler.php +++ b/livesupport/src/modules/htmlUI/var/html/ui_handler.php @@ -371,7 +371,7 @@ switch($_REQUEST['act']){ $uiHandler->SCHEDULER->setReload(); break; - case "BACKUP.createBackupOpen": + case 'BACKUP.createBackupOpen': $uiHandler->EXCHANGE->createBackupOpen(); $uiHandler->redirUrl = UI_BROWSER.'?act=BACKUP'; break; @@ -381,12 +381,22 @@ switch($_REQUEST['act']){ $uiHandler->redirUrl = UI_BROWSER.'?act=BACKUP'; break; - case "BACKUP.createBackupClose": + case 'BACKUP.createBackupClose': $uiHandler->EXCHANGE->createBackupClose(); $uiHandler->redirUrl = UI_BROWSER.'?act=BACKUP'; break; - case "SESSION.CLEAR": + case 'RESTORE.setBackupFileToRestore': + $uiHandler->EXCHANGE->backupRestoreOpen($_REQUEST['target']); + $uiHandler->redirUrl = UI_BROWSER.'?act=RESTORE'; + break; + + case 'RESTORE.backupRestoreClose': + $uiHandler->EXCHANGE->backupRestoreClose(); + $uiHandler->redirUrl = UI_BROWSER.'?act=RESTORE'; + break; + + case 'SESSION.CLEAR': $_SESSION = array(); die(); break; diff --git a/livesupport/src/modules/htmlUI/var/localizer/lang/default_DEFAULT/templates.xml b/livesupport/src/modules/htmlUI/var/localizer/lang/default_DEFAULT/templates.xml index a6091b68e..48c32d6be 100644 --- a/livesupport/src/modules/htmlUI/var/localizer/lang/default_DEFAULT/templates.xml +++ b/livesupport/src/modules/htmlUI/var/localizer/lang/default_DEFAULT/templates.xml @@ -845,4 +845,8 @@ Are you sure to cancel transfer(s)? Are you sure to cancel transfer(s)? + + Choose a backup file + AChoose a backup file + \ No newline at end of file diff --git a/livesupport/src/modules/htmlUI/var/templates/backup/fileBrowser.tpl b/livesupport/src/modules/htmlUI/var/templates/backup/fileBrowser.tpl index 9162241f8..645577457 100644 --- a/livesupport/src/modules/htmlUI/var/templates/backup/fileBrowser.tpl +++ b/livesupport/src/modules/htmlUI/var/templates/backup/fileBrowser.tpl @@ -17,10 +17,18 @@ if (window.scrollbars.visible == false) {

##File browser##

-
+ ##Filename:##
+ {if ($isRestore && $isFile) || !$isRestore} + {/if}
@@ -28,7 +36,7 @@ if (window.scrollbars.visible == false) { {foreach from=$currdir.subdirs item=entry key=name} - {$name|truncate:50:"...":true} + {$name|truncate:50:"...":true} {$entry.u|truncate:10:'...':true} {$entry.g|truncate:10:'...':true} {if $entry.r}r{/if} @@ -40,7 +48,7 @@ if (window.scrollbars.visible == false) { {foreach from=$currdir.files item=entry key=name} - {$name|truncate:50:"...":true} + {$name|truncate:50:"...":true} {$entry.u|truncate:10:'...':true} {$entry.g|truncate:10:'...':true} {if $entry.r}r{/if} diff --git a/livesupport/src/modules/htmlUI/var/templates/backup/restore.tpl b/livesupport/src/modules/htmlUI/var/templates/backup/restore.tpl index 8d3d2099c..423a0c164 100644 --- a/livesupport/src/modules/htmlUI/var/templates/backup/restore.tpl +++ b/livesupport/src/modules/htmlUI/var/templates/backup/restore.tpl @@ -3,21 +3,23 @@

##Restore backup##

- {assign var=token' value=$EXCHANGE->getBackupToken()} + {assign var='token' value=$EXCHANGE->getRestoreToken()} {if $token === false} - + {else} - {assign var='status' value=$EXCHANGE->createBackupCheck()} + {assign var='status' value=$EXCHANGE->backupRestoreCheck()} Backup status: {$status.status} {if $status.status === 'success'} -

+

{/if} {/if} + +
diff --git a/livesupport/src/modules/htmlUI/var/ui_conf.php b/livesupport/src/modules/htmlUI/var/ui_conf.php index 302843c49..f35b092cc 100644 --- a/livesupport/src/modules/htmlUI/var/ui_conf.php +++ b/livesupport/src/modules/htmlUI/var/ui_conf.php @@ -110,6 +110,7 @@ define('UI_PL_ELEM_FADEOUT', 'fadeOut'); ## Export/Import define('UI_BACKUPTOKEN_KEY', 'backupToken'); +define('UI_RESTORETOKEN_KEY', 'restoreToken'); ## LS stuff require_once '../../../storageServer/var/conf.php'; diff --git a/livesupport/src/modules/htmlUI/var/ui_exchange.class.php b/livesupport/src/modules/htmlUI/var/ui_exchange.class.php index 73b015372..f22f2ab72 100644 --- a/livesupport/src/modules/htmlUI/var/ui_exchange.class.php +++ b/livesupport/src/modules/htmlUI/var/ui_exchange.class.php @@ -11,7 +11,7 @@ class uiExchange } } - // GB wrapper emthods + // GB wrapper methods function getBackupToken() { @@ -47,7 +47,7 @@ class uiExchange $token = $this->getBackupToken(); if ($token === false) { - return flase; + return false; } $res = $this->Base->gb->createBackupCheck($token); @@ -76,8 +76,8 @@ class uiExchange function createBackupClose() { - $token = $token = $this->getBackupToken(); - + $token = $this->getBackupToken(); + if ($token === false) { $this->Base->_retMsg('Token not available'); return false; @@ -144,8 +144,80 @@ class uiExchange return false; } + // Restore methods + function getRestoreToken() + { + $token = $this->Base->gb->loadPref($this->Base->sessid, UI_RESTORETOKEN_KEY); + if (PEAR::isError($token)) { + return false; + } + return $token; + } + function restore($filename) { + $filename='/tmp/backup_20060508.tar'; + } + function backupRestoreOpen($backupFile) + { + $token = $this->Base->gb->backupRestoreOpen($this->Base->sessid,$backupFile); + + if (PEAR::isError($token)) { + $this->Base->_retMsg('Error initializing backup restore: $1', $token->getMessage()); + return false; + } + + #$this->backupRestoreCheck(); //? + + $this->Base->gb->savePref($this->Base->sessid, UI_RESTORETOKEN_KEY, $token['token']); + + return true; + } + + function backupRestoreCheck() + { + $token = $this->getRestoreToken(); + + if ($token === false) { + return false; + } + + $res = $this->Base->gb->backupRestoreCheck($token); + + if (PEAR::isError($res)) { + $this->Base->_retMsg('Unable to check backup restore status: $1', $res->getMessage()); + return false; + } + + return $res; + } + + function backupRestoreClose() + { + $token = $this->getRestoreToken(); + + if ($token === false) { + $this->Base->_retMsg('Backup restore token is not available'); + return false; + } + + $status = $this->Base->gb->backupRestoreClose($token); + + if (PEAR::isError($status)) { + $this->Base->_retMsg('Error closing restore backup: $1', $status->getMessage()); + return false; + } + + if ($status === true) { + $this->Base->gb->delPref($this->Base->sessid, UI_RESTORETOKEN_KEY); + } + + return $status; + } + + function setBackupFileToRestore($filename) { + } + // file browser methods function setFolder($subfolder) @@ -248,11 +320,5 @@ class uiExchange ); } - - // restore methods - function restore($filename) { - $filename='/tmp/backup_20060508.tar'; - $this->Base->gb->doRestore($this->Base->sessid,$filename); - } } ?> \ No newline at end of file diff --git a/livesupport/src/modules/storageServer/bin/restore.php b/livesupport/src/modules/storageServer/bin/restore.php new file mode 100755 index 000000000..06137749e --- /dev/null +++ b/livesupport/src/modules/storageServer/bin/restore.php @@ -0,0 +1,40 @@ +#!/usr/bin/php + +getMessage()); + } + $dbc->setFetchMode(DB_FETCHMODE_ASSOC); + + $gb =& new GreenBox($dbc, $config); + $rs = new Restore($gb); + + if ($rs->loglevel=='debug') { + $rs->addLogItem('argv:'.print_r($argv,true)); + } + +# sleep(2); + + $backupfile = $argv[1]; + $token = $argv[3]; + $sessid = $argv[4]; + $rs->startRestore($backupfile,$token,$sessid); + +?> \ No newline at end of file diff --git a/livesupport/src/modules/storageServer/var/Restore.php b/livesupport/src/modules/storageServer/var/Restore.php index c40033651..efd78347f 100644 --- a/livesupport/src/modules/storageServer/var/Restore.php +++ b/livesupport/src/modules/storageServer/var/Restore.php @@ -294,7 +294,7 @@ class Restore { if(!is_dir($dirname."/".$file)) unlink ($dirname."/".$file); else - Backup::rRmDir($dirname."/".$file); + Restore::rRmDir($dirname."/".$file); } } closedir($dir_handle);