From 8c9bb1e5674e5542073e726b8c4d8a71f70a719c Mon Sep 17 00:00:00 2001 From: Frank Bergkemper Date: Wed, 21 Aug 2019 17:11:26 +0200 Subject: [PATCH] webui: Remove the functionality of preselecting a backup client in the restore module indexAction --- .../Restore/Controller/RestoreController.php | 100 +++++---- .../Restore/src/Restore/Form/RestoreForm.php | 192 ++++++++++++------ .../src/Restore/Model/RestoreModel.php | 31 ++- .../Restore/view/restore/restore/index.phtml | 10 +- 4 files changed, 225 insertions(+), 108 deletions(-) diff --git a/webui/module/Restore/src/Restore/Controller/RestoreController.php b/webui/module/Restore/src/Restore/Controller/RestoreController.php index 730bb156a66..c814264936f 100644 --- a/webui/module/Restore/src/Restore/Controller/RestoreController.php +++ b/webui/module/Restore/src/Restore/Controller/RestoreController.php @@ -52,6 +52,7 @@ class RestoreController extends AbstractActionController private $files = null; private $required_commands = array( + "list", "llist", ".filesets", ".jobs", @@ -61,7 +62,8 @@ class RestoreController extends AbstractActionController ".bvfs_lsdirs", ".bvfs_lsfiles", ".bvfs_restore", - ".bvfs_cleanup" + ".bvfs_cleanup", + ".bvfs_versions" ); /** @@ -90,7 +92,7 @@ public function indexAction() $this->setRestoreParams(); $errors = null; $result = null; - +/* if($this->restore_params['client'] == null) { try { $clients = $this->getClientModel()->getClients($this->bsock); @@ -101,8 +103,8 @@ public function indexAction() echo $e->getMessage(); } } - - if($this->restore_params['type'] == "client" && $this->restore_params['jobid'] == null) { +*/ + if($this->restore_params['type'] == "client" && $this->restore_params['jobid'] == null && $this->restore_params['client'] != null) { try { $latestbackup = $this->getClientModel()->getClientBackups($this->bsock, $this->restore_params['client'], "any", "desc", 1); if(empty($latestbackup)) { @@ -130,7 +132,7 @@ public function indexAction() } } - if($this->restore_params['type'] == "client") { + if($this->restore_params['type'] == "client" && $this->restore_params['client'] != null) { try { $backups = $this->getClientModel()->getClientBackups($this->bsock, $this->restore_params['client'], "any", "desc", null); } @@ -138,6 +140,9 @@ public function indexAction() echo $e->getMessage(); } } + else { + $backups = null; + } try { //$jobs = $this->getJobModel()->getJobs(); @@ -149,7 +154,7 @@ public function indexAction() echo $e->getMessage(); } - if(empty($backups)) { + if(isset($this->restore_params['client']) && empty($backups)) { $errors = 'No backups of client '.$this->restore_params['client'].' found.'; } @@ -401,7 +406,6 @@ public function versionsAction() } - /** * Delivers a subtree as Json for JStree */ @@ -429,24 +433,15 @@ private function getDirectories() $this->directories = null; try { - if($this->restore_params['type'] == "client") { - if(empty($this->restore_params['jobid'])) { - $this->restore_params['jobids'] = null; - } - else { - $jobids = $this->getRestoreModel()->getJobIds($this->bsock, $this->restore_params['jobid'],$this->restore_params['mergefilesets'],$this->restore_params['mergejobs']); - $this->restore_params['jobids'] = $jobids; - $this->directories = $this->getRestoreModel()->getDirectories($this->bsock, $this->restore_params['jobids'], $this->restore_params['id']); - } - } - else { - $this->directories = $this->getRestoreModel()->getDirectories($this->bsock, $this->restore_params['jobid'], $this->restore_params['id']); - } + $this->directories = $this->getRestoreModel()->getDirectories( + $this->bsock, + $this->restore_params['jobids'], + $this->restore_params['id'] + ); } catch(Exception $e) { echo $e->getMessage(); } - } /** @@ -457,24 +452,49 @@ private function getFiles() $this->files = null; try { - if($this->restore_params['type'] == "client") { - if(empty($this->restore_params['jobid'])) { - $this->restore_params['jobids'] = null; - } - else { - $jobids = $this->getRestoreModel()->getJobIds($this->bsock, $this->restore_params['jobid'],$this->restore_params['mergefilesets'],$this->restore_params['mergejobs']); - $this->restore_params['jobids'] = $jobids; - $this->files = $this->getRestoreModel()->getFiles($this->bsock, $this->restore_params['jobids'], $this->restore_params['id']); - } - } - else { - $this->files = $this->getRestoreModel()->getFiles($this->bsock, $this->restore_params['jobid'], $this->restore_params['id']); - } + $this->files = $this->getRestoreModel()->getFiles( + $this->bsock, + $this->restore_params['jobids'], + $this->restore_params['id'] + ); } catch(Exception $e) { echo $e->getMessage(); } + } + + /** + * Get depending JobIds considering the merge criteria + */ + private function getJobIds() + { + try { + $this->restore_params['jobids'] = $this->getRestoreModel()->getJobIds( + $this->bsock, + $this->restore_params['jobid'], + $this->restore_params['mergefilesets'], + $this->restore_params['mergejobs'] + ); + } + catch(Exception $e) { + echo $e->getMessage(); + } + } + /** + * Update Bvfs cache + */ + private function updateBvfsCache() + { + try { + $this->getRestoreModel()->updateBvfsCache( + $this->bsock, + $this->restore_params['jobids'] + ); + } + catch(Exception $e) { + echo $e->getMessage(); + } } /** @@ -482,9 +502,14 @@ private function getFiles() */ private function buildSubtree() { - $this->bsock = $this->getServiceLocator()->get('director'); $this->setRestoreParams(); + $this->getJobIds(); + + if($this->restore_params['id'] == null || $this->restore_params['id'] == "#") { + $this->updateBvfsCache(); + } + $this->getDirectories(); $this->getFiles(); @@ -496,7 +521,6 @@ private function buildSubtree() $items = '['; if($dnum > 0) { - foreach($this->directories as $dir) { if($dir['name'] == ".") { --$dnum; @@ -521,15 +545,12 @@ private function buildSubtree() } } } - if($fnum > 0) { $items .= ","; } - } if($fnum > 0) { - foreach($this->files as $file) { $items .= '{'; $items .= '"id":"' . $file["fileid"] . '"'; @@ -543,7 +564,6 @@ private function buildSubtree() $items .= ","; } } - } $items .= ']'; diff --git a/webui/module/Restore/src/Restore/Form/RestoreForm.php b/webui/module/Restore/src/Restore/Form/RestoreForm.php index df32dab6775..b05dd47d274 100644 --- a/webui/module/Restore/src/Restore/Form/RestoreForm.php +++ b/webui/module/Restore/src/Restore/Form/RestoreForm.php @@ -92,7 +92,7 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'type' => 'select', 'options' => array( 'label' => _('Backup jobs'), - //'empty_option' => _('Please choose a backup'), + 'empty_option' => _('Please choose a backup'), 'value_options' => $this->getBackupList() ), 'attributes' => array( @@ -109,13 +109,14 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'type' => 'select', 'options' => array( 'label' => _('Backups'), - //'empty_option' => _('Please choose a backup'), + 'empty_option' => _('Please choose a backup'), 'value_options' => $this->getBackupList() ), 'attributes' => array( 'class' => 'form-control selectpicker show-tick', 'data-live-search' => 'true', - 'id' => 'jobid' + 'id' => 'jobid', + 'disabled' => true ) )); } @@ -128,7 +129,7 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'type' => 'select', 'options' => array( 'label' => _('Client'), - //'empty_option' => _('Please choose a client'), + 'empty_option' => _('Please choose a client'), 'value_options' => $this->getClientList() ), 'attributes' => array( @@ -145,7 +146,7 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'type' => 'select', 'options' => array( 'label' => _('Client'), - //'empty_option' => _('Please choose a client'), + 'empty_option' => _('Please choose a client'), 'value_options' => $this->getClientList() ), 'attributes' => array( @@ -163,14 +164,14 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'type' => 'select', 'options' => array( 'label' => _('Client'), - //'empty_option' => _('Please choose a client'), + 'empty_option' => _('Please choose a client'), 'value_options' => $this->getClientList() ), 'attributes' => array( 'class' => 'form-control selectpicker show-tick', 'data-live-search' => 'true', 'id' => 'client', - 'value' => @array_pop($this->getClientList()) + 'value' => '' //@array_pop($this->getClientList()) ) )); } @@ -182,7 +183,7 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'type' => 'select', 'options' => array( 'label' => _('Restore to client'), - //'empty_option' => _('Please choose a client'), + 'empty_option' => _('Please choose a client'), 'value_options' => $this->getClientList() ), 'attributes' => array( @@ -199,7 +200,7 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'type' => 'select', 'options' => array( 'label' => _('Restore to client'), - //'empty_option' => _('Please choose a client'), + 'empty_option' => _('Please choose a client'), 'value_options' => $this->getClientList() ), 'attributes' => array( @@ -216,13 +217,14 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'type' => 'select', 'options' => array( 'label' => _('Restore to (another) client'), - //'empty_option' => _('Please choose a client'), + 'empty_option' => _('Please choose a client'), 'value_options' => $this->getClientList() ), 'attributes' => array( 'class' => 'form-control selectpicker show-tick', 'data-live-search' => 'true', - 'id' => 'restoreclient' + 'id' => 'restoreclient', + 'disabled' => true ) )); } @@ -277,13 +279,13 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, )); } else { - if(count($this->getRestoreJobList()) == 1) { + if(!empty($this->restore_params['client']) && count($this->getRestoreJobList()) == 1) { $this->add(array( 'name' => 'restorejob', 'type' => 'select', 'options' => array( 'label' => _('Restore job'), - //'empty_option' => _('Please choose a restore job'), + 'empty_option' => _('Please choose a restore job'), 'value_options' => $this->getRestoreJobList() ), 'attributes' => array( @@ -300,20 +302,21 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'type' => 'select', 'options' => array( 'label' => _('Restore job'), - //'empty_option' => _('Please choose a restore job'), + 'empty_option' => _('Please choose a restore job'), 'value_options' => $this->getRestoreJobList() ), 'attributes' => array( 'class' => 'form-control selectpicker show-tick', 'data-live-search' => 'true', - 'id' => 'restorejob' + 'id' => 'restorejob', + 'disabled' => true ) )); } } // Merge filesets - if(isset($restore_params['mergefilesets'])) { + if(isset($this->restore_params['client']) && isset($restore_params['mergefilesets'])) { $this->add(array( 'name' => 'mergefilesets', 'type' => 'select', @@ -346,14 +349,15 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'attributes' => array( 'class' => 'form-control selectpicker show-tick', 'id' => 'mergefilesets', - 'value' => '0' + 'value' => '0', + 'disabled' => true ) ) ); } // Merge jobs - if(isset($restore_params['mergejobs'])) { + if(isset($this->restore_params['client']) && isset($restore_params['mergejobs'])) { $this->add(array( 'name' => 'mergejobs', 'type' => 'select', @@ -386,50 +390,95 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, 'attributes' => array( 'class' => 'form-control selectpicker show-tick', 'id' => 'mergejobs', - 'value' => '0' + 'value' => '0', + 'disabled' => true ) ) ); } // Replace - $this->add(array( - 'name' => 'replace', - 'type' => 'select', - 'options' => array( - 'label' => _('Replace files on client'), - 'value_options' => array( - 'always' => _('always'), - 'never' => _('never'), - 'ifolder' => _('if file being restored is older than existing file'), - 'ifnewer' => _('if file being restored is newer than existing file') + if(isset($restore_params['client'])) { + $this->add(array( + 'name' => 'replace', + 'type' => 'select', + 'options' => array( + 'label' => _('Replace files on client'), + 'value_options' => array( + 'always' => _('always'), + 'never' => _('never'), + 'ifolder' => _('if file being restored is older than existing file'), + 'ifnewer' => _('if file being restored is newer than existing file') + ) + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'id' => 'replace', + 'value' => 'never' + ) + ) + ); + } + else { + $this->add(array( + 'name' => 'replace', + 'type' => 'select', + 'options' => array( + 'label' => _('Replace files on client'), + 'value_options' => array( + 'always' => _('always'), + 'never' => _('never'), + 'ifolder' => _('if file being restored is older than existing file'), + 'ifnewer' => _('if file being restored is newer than existing file') + ) + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'id' => 'replace', + 'value' => 'never', + 'disabled' => true ) - ), - 'attributes' => array( - 'class' => 'form-control selectpicker show-tick', - 'id' => 'replace', - 'value' => 'never' ) - ) - ); + ); + } // Where - $this->add(array( - 'name' => 'where', - 'type' => 'text', - 'options' => array( - 'label' => _('Restore location on client') - ), - 'attributes' => array( - 'class' => 'form-control selectpicker show-tick', - 'value' => '/tmp/bareos-restores/', - 'id' => 'where', - 'size' => '30', - 'placeholder' => _('e.g. / or /tmp/bareos-restores/') - ) - ) - ); - + if(isset($this->restore_params['client'])) { + $this->add(array( + 'name' => 'where', + 'type' => 'text', + 'options' => array( + 'label' => _('Restore location on client') + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'value' => '/tmp/bareos-restores/', + 'id' => 'where', + 'size' => '30', + 'placeholder' => _('e.g. / or /tmp/bareos-restores/') + ) + ) + ); + } + else { + $this->add(array( + 'name' => 'where', + 'type' => 'text', + 'options' => array( + 'label' => _('Restore location on client') + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'value' => '/tmp/bareos-restores/', + 'id' => 'where', + 'size' => '30', + 'placeholder' => _('e.g. / or /tmp/bareos-restores/'), + 'disabled' => true + ) + ) + ); + } +/* // Path if(isset($restore_params['path'])) { $this->add(array( @@ -537,7 +586,7 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, ) ); } - + */ // JobIds hidden $this->add(array( 'name' => 'jobids_hidden', @@ -587,14 +636,35 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null, ); // Submit button - $this->add(array( - 'name' => 'submit', - 'type' => 'submit', - 'attributes' => array( - 'value' => _('Restore'), - 'id' => 'submit' - ) - )); + if(isset($this->restore_params['client'])) { + $this->add(array( + 'name' => 'form-submit', + 'type' => 'button', + 'options' => array( + 'label' => _('Restore') + ), + 'attributes' => array( + //'value' => _('Restore'), + 'id' => 'btn-form-submit', + 'class' => 'btn btn-primary' + ) + )); + } + else { + $this->add(array( + 'name' => 'form-submit', + 'type' => 'button', + 'options' => array( + 'label' => _('Restore') + ), + 'attributes' => array( + //'value' => _('Restore'), + 'id' => 'btn-form-submit', + 'class' => 'btn btn-primary', + 'disabled' => true + ) + )); + } } diff --git a/webui/module/Restore/src/Restore/Model/RestoreModel.php b/webui/module/Restore/src/Restore/Model/RestoreModel.php index 2b0a2842948..ce1b3b663b3 100644 --- a/webui/module/Restore/src/Restore/Model/RestoreModel.php +++ b/webui/module/Restore/src/Restore/Model/RestoreModel.php @@ -46,19 +46,19 @@ public function getDirectories(&$bsock=null, $jobid=null, $pathid=null) { while (true) { - if($pathid == null || $pathid== "#") { + if($pathid == null || $pathid == "#") { $cmd_1 = '.bvfs_lsdirs jobid='.$jobid.' path= limit='.$limit.' offset='.$offset; } else { $cmd_1 = '.bvfs_lsdirs jobid='.$jobid.' pathid='.abs($pathid).' limit='.$limit.' offset='.$offset; } - $result = $bsock->send_command($cmd_1, 2, $jobid); + $result = $bsock->send_command($cmd_1, 2, null); $directories = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); if(empty($directories['result'])) { $cmd_2 = '.bvfs_lsdirs jobid='.$jobid.' path=@ limit='.$limit; - $result = $bsock->send_command($cmd_2, 2, $jobid); + $result = $bsock->send_command($cmd_2, 2, null); $directories = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); if(count($directories['result']['directories']) <= 2) { $retval = array_merge($retval, $directories['result']['directories']); @@ -122,7 +122,7 @@ public function getFiles(&$bsock=null, $jobid=null, $pathid=null) { $cmd_1 = '.bvfs_lsfiles jobid='.$jobid.' pathid='.abs($pathid).' limit='.$limit.' offset='.$offset; } - $result = $bsock->send_command($cmd_1, 2, $jobid); + $result = $bsock->send_command($cmd_1, 2, null); $files = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); if ( empty($files['result']) ) { @@ -131,7 +131,7 @@ public function getFiles(&$bsock=null, $jobid=null, $pathid=null) { if(empty($files['result']['files'])) { $cmd_2 = '.bvfs_lsfiles jobid='.$jobid.' path=@ limit='.$limit.' offset='.$offset; - $result = $bsock->send_command($cmd_2, 2, $jobid); + $result = $bsock->send_command($cmd_2, 2, null); $files = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); if(empty($files['result']['files'])) { return $retval; @@ -217,6 +217,27 @@ public function getJobIds(&$bsock=null, $jobid=null, $mergefilesets=0, $mergejob } } + /** + * Updates the bvfs cache + * + * @param $bsock + * @param $jobid + */ + public function updateBvfsCache(&$bsock=null, $jobid=null) + { + if(isset($bsock)) { + if($jobid != null) { + $cmd = '.bvfs_update jobid='.$jobid; + } else { + $cmd = '.bvfs_update'; + } + $result = $bsock->send_command($cmd, 2, null); + } + else { + throw new \Exception('Missing argument.'); + } + } + /** * Restore * diff --git a/webui/module/Restore/view/restore/restore/index.phtml b/webui/module/Restore/view/restore/restore/index.phtml index d639bce3387..edaa9fa6656 100644 --- a/webui/module/Restore/view/restore/restore/index.phtml +++ b/webui/module/Restore/view/restore/restore/index.phtml @@ -148,18 +148,23 @@ $this->headTitle($title); echo '

'.$this->formRow($form->get('restorejob')).'

'; echo '

'.$this->formRow($form->get('replace')).'

'; echo '

'.$this->formRow($form->get('where')).'

'; - echo '

'; + + echo '

'.$this->formRow($form->get('form-submit')).'

'; + //echo '

'; + // Hidden fields echo $this->formRow($form->get('checked_files')); echo $this->formRow($form->get('checked_directories')); echo $this->formRow($form->get('jobids_hidden')); } + /* elseif($this->restore_params['type'] == "job") { echo $this->formRow($form->get('jobid')->setAttribute('class', 'form-control')); echo $this->formRow($form->get('restoreclient')->setAttribute('class','form-control')); echo $this->formRow($form->get('restorejob')->setAttribute('class','form-control')); echo $this->formRow($form->get('where')->setAttribute('class','form-control')); } + */ ?> @@ -275,7 +280,8 @@ $this->headTitle($title); } function submitRestoreFormData() { - document.getElementById('restore').submit(); + //document.getElementById('restore').submit(); + document.restore.submit(); } function updateModalRestoreParamsTable(client, restoreclient, replace, where, selectedNumberOfDirectories, selectedNumberOfFiles) {