Skip to content

Commit

Permalink
Merge pull request #1050 from bareos/dev/fbergkemper/master/s5024
Browse files Browse the repository at this point in the history
webui:  remove an unnecessary .bvfs_get_jobids and buildSubtree() call
  • Loading branch information
pstorz committed Feb 4, 2022
2 parents d79d2da + dbc1c61 commit 746e7a1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 79 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -22,6 +22,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- systemtests: wait for mariadb shutdown [PR #1048]

### Changed
- webui: remove an unnecessary .bvfs_get_jobids and buildSubtree() call [PR #1050]

### Deprecated

Expand Down
133 changes: 58 additions & 75 deletions webui/module/Restore/src/Restore/Controller/RestoreController.php
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2021 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2022 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -93,44 +93,12 @@ public function indexAction()
$errors = null;
$result = null;

if($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)) {
$this->restore_params['jobid'] = null;
}
else {
$this->restore_params['jobid'] = $latestbackup[0]['jobid'];
}
}
catch(Exception $e) {
echo $e->getMessage();
}
}

if(isset($this->restore_params['mergejobs']) && $this->restore_params['mergejobs'] == 1) {
$jobids = $this->restore_params['jobid'];
}
else {
try {
$jobids = $this->getRestoreModel()->getJobIds($this->bsock, $this->restore_params['jobid'], $this->restore_params['mergefilesets']);
$this->restore_params['jobids'] = $jobids;
}
catch(Exception $e) {
echo $e->getMessage();
}
}

if($this->restore_params['client'] != null) {
try {
$backups = $this->getClientModel()->getClientBackups($this->bsock, $this->restore_params['client'], "any", "desc", null);
$this->updateBvfsCache();
}
catch(Exception $e) {
echo $e->getMessage();
}
}
else {
$this->handleJobId();
$this->handleJobMerge();
$backups = $this->getClientBackups();
$this->updateBvfsCache();
} else {
$backups = null;
}

Expand Down Expand Up @@ -158,7 +126,7 @@ public function indexAction()
$clients,
$filesets,
$restorejobresources,
$jobids,
$this->restore_params['jobids'],
$backups
);

Expand Down Expand Up @@ -297,39 +265,12 @@ public function versionsAction()
$errors = null;
$result = null;

if ($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)) {
$this->restore_params['jobid'] = null;
} else {
$this->restore_params['jobid'] = $latestbackup[0]['jobid'];
}
} catch (Exception $e) {
echo $e->getMessage();
}
}

if (isset($this->restore_params['mergejobs']) && $this->restore_params['mergejobs'] == 1) {
$jobids = $this->restore_params['jobid'];
if($this->restore_params['client'] != null) {
$this->handleJobId();
$this->handleJobMerge();
$backups = $this->getClientBackups();
$this->updateBvfsCache();
} else {
try {
$jobids = $this->getRestoreModel()->getJobIds($this->bsock, $this->restore_params['jobid'], $this->restore_params['mergefilesets']);
$this->restore_params['jobids'] = $jobids;
} catch (Exception $e) {
echo $e->getMessage();
}
}

if ($this->restore_params['client'] != null) {
try {
$backups = $this->getClientModel()->getClientBackups($this->bsock, $this->restore_params['client'], "any", "desc", null);
$this->updateBvfsCache();
} catch (Exception $e) {
echo $e->getMessage();
}
}
else {
$backups = null;
}

Expand All @@ -356,7 +297,7 @@ public function versionsAction()
$clients,
$filesets,
$restorejobresources,
$jobids,
$this->restore_params['jobids'],
$backups
);

Expand Down Expand Up @@ -456,6 +397,44 @@ public function versionsAction()

}

private function handleJobId()
{
if($this->restore_params['jobid'] == null) {
try {
$latestbackup = $this->getClientModel()->getClientBackups($this->bsock, $this->restore_params['client'], "any", "desc", 1);
if (empty($latestbackup)) {
$this->restore_params['jobid'] = null;
} else {
$this->restore_params['jobid'] = $latestbackup[0]['jobid'];
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
}

private function handleJobMerge()
{
if(isset($this->restore_params['mergejobs']) && $this->restore_params['mergejobs'] == 1) {
$this->restore_params['jobids'] = $this->restore_params['jobid'];
} else {
try {
$this->restore_params['jobids'] = $this->getRestoreModel()->getJobIds($this->bsock, $this->restore_params['jobid'], $this->restore_params['mergefilesets']);
} catch (Exception $e) {
echo $e->getMessage();
}
}
}

private function getClientBackups()
{
try {
return $this->getClientModel()->getClientBackups($this->bsock, $this->restore_params['client'], "any", "desc", null);
} catch (Exception $e) {
echo $e->getMessage();
}
}

/**
* Delivers a subtree as Json for JStree
*/
Expand All @@ -481,9 +460,13 @@ public function filebrowserAction()
$this->setRestoreParams();
$this->layout('layout/json');

return new ViewModel(array(
'items' => $this->buildSubtree()
));
if($this->restore_params['client'] != null) {
$items = $this->buildSubtree();
} else {
$items = "{}";
}

return new ViewModel(array('items' => $items));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions webui/module/Restore/view/restore/restore/index.phtml
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2021 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2022 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -382,7 +382,7 @@ $this->headTitle($title);
displayBvfsCacheUpdateInfo();
},
'data' :{
'url' : '<?php echo $this->basePath() . "/restore/filebrowser?jobid=" . $this->restore_params['jobid'] . "&mergefilesets=" . $this->restore_params['mergefilesets'] . "&mergejobs=" . $this->restore_params['mergejobs'] . "&limit=" . $this->restore_params['limit']; ?>',
'url' : '<?php echo $this->basePath() . "/restore/filebrowser?jobid=" . $this->restore_params['jobid'] . "&client=" . $this->restore_params['client'] . "&mergefilesets=" . $this->restore_params['mergefilesets'] . "&mergejobs=" . $this->restore_params['mergejobs'] . "&limit=" . $this->restore_params['limit']; ?>',
'dataType' : 'json',
'data' : function (node) {
return { 'id' : node.id };
Expand Down
4 changes: 2 additions & 2 deletions webui/module/Restore/view/restore/restore/versions.phtml
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2021 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2022 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -523,7 +523,7 @@ $('#filebrowser').jstree({
},
'multiple': false,
'data': {
'url': '<?php echo $this->basePath() . "/restore/filebrowser?jobid=" . $this->restore_params['jobid'] . "&mergefilesets=" . $this->restore_params['mergefilesets'] . "&mergejobs=" . $this->restore_params['mergejobs'] . "&limit=" . $this->restore_params['limit']; ?>',
'url': '<?php echo $this->basePath() . "/restore/filebrowser?jobid=" . $this->restore_params['jobid'] . "&client=" . $this->restore_params['client'] . "&mergefilesets=" . $this->restore_params['mergefilesets'] . "&mergejobs=" . $this->restore_params['mergejobs'] . "&limit=" . $this->restore_params['limit']; ?>',
'dataType': 'json',
'data': function (node) {
return {
Expand Down

0 comments on commit 746e7a1

Please sign in to comment.