Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Restore: Adds form element limit for .bvfs_ls* commands
  • Loading branch information
fbergkemper committed May 23, 2017
1 parent 30c6a37 commit 8138008
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 45 deletions.
101 changes: 73 additions & 28 deletions module/Restore/src/Restore/Controller/RestoreController.php
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2016 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2017 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 @@ -34,14 +34,22 @@
class RestoreController extends AbstractActionController
{

/**
* Variables
*/
protected $restoreModel = null;
protected $jobModel = null;
protected $clientModel = null;
protected $filesetModel = null;
protected $restore_params = null;

protected $bsock = null;
protected $restore_params = null;

protected $acl_alert = false;

private $directories = null;
private $files = null;

private $required_commands = array(
"llist",
".filesets",
Expand All @@ -56,7 +64,7 @@ class RestoreController extends AbstractActionController
);

/**
*
* Index Action
*/
public function indexAction()
{
Expand All @@ -78,7 +86,7 @@ public function indexAction()

$this->bsock = $this->getServiceLocator()->get('director');

$this->getRestoreParams();
$this->setRestoreParams();
$errors = null;

if($this->restore_params['client'] == null) {
Expand Down Expand Up @@ -235,7 +243,7 @@ public function filebrowserAction()
return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director'])));
}

$this->getRestoreParams();
$this->setRestoreParams();
$this->layout('layout/json');

return new ViewModel(array(
Expand All @@ -244,74 +252,89 @@ public function filebrowserAction()
}

/**
* Builds a subtree as Json for JStree
* Get the directories
*/
private function buildSubtree()
private function getDirectories()
{
$this->directories = null;

$this->bsock = $this->getServiceLocator()->get('director');

$this->getRestoreParams();

// Get directories
try {
if($this->restore_params['type'] == "client") {
if(empty($this->restore_params['jobid'])) {
$this->restore_params['jobids'] = null;
$directories = 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;
$directories = $this->getRestoreModel()->getDirectories($this->bsock, $this->restore_params['jobids'],$this->restore_params['id']);
$this->directories = $this->getRestoreModel()->getDirectories($this->bsock, $this->restore_params['jobids'], $this->restore_params['id'], $this->restore_params['limit']);
}
}
else {
$directories = $this->getRestoreModel()->getDirectories($this->bsock, $this->restore_params['jobid'],$this->restore_params['id']);
$this->directories = $this->getRestoreModel()->getDirectories($this->bsock, $this->restore_params['jobid'], $this->restore_params['id'], $this->restore_params['limit']);
}
}
catch(Exception $e) {
echo $e->getMessage();
}

// Get files
}

/**
* Get the files
*/
private function getFiles()
{
$this->files = null;

try {
if($this->restore_params['type'] == "client") {
if(empty($this->restore_params['jobid'])) {
$this->restore_params['jobids'] = null;
$files = 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;
$files = $this->getRestoreModel()->getFiles($this->bsock, $this->restore_params['jobids'],$this->restore_params['id']);
$this->files = $this->getRestoreModel()->getFiles($this->bsock, $this->restore_params['jobids'], $this->restore_params['id'], $this->restore_params['limit']);
}
}
else {
$files = $this->getRestoreModel()->getFiles($this->bsock, $this->restore_params['jobid'],$this->restore_params['id']);
$this->files = $this->getRestoreModel()->getFiles($this->bsock, $this->restore_params['jobid'], $this->restore_params['id'], $this->restore_params['limit']);
}
}
catch(Exception $e) {
echo $e->getMessage();
}

$dnum = count($directories);
$fnum = count($files);
}

/**
* Builds a subtree as Json for JStree
*/
private function buildSubtree()
{

$this->bsock = $this->getServiceLocator()->get('director');
$this->setRestoreParams();
$this->getDirectories();
$this->getFiles();

$dnum = count($this->directories);
$fnum = count($this->files);
$tmp = $dnum;

// Build Json for JStree
$items = '[';

if($dnum > 0) {

foreach($directories as $dir) {
foreach($this->directories as $dir) {
if($dir['name'] == ".") {
--$dnum;
next($directories);
next($this->directories);
}
elseif($dir['name'] == "..") {
--$dnum;
next($directories);
next($this->directories);
}
else {
--$dnum;
Expand All @@ -337,7 +360,7 @@ private function buildSubtree()

if($fnum > 0) {

foreach($files as $file) {
foreach($this->files as $file) {
$items .= '{';
$items .= '"id":"' . $file["fileid"] . '"';
$items .= ',"text":"' . preg_replace('/[\x00-\x1F\x7F]/', '', addslashes($file["name"])) . '"';
Expand All @@ -361,9 +384,9 @@ private function buildSubtree()
}

/**
* Retrieve restore parameters
* Set the restore parameters
*/
private function getRestoreParams()
private function setRestoreParams()
{
if($this->params()->fromQuery('type')) {
$this->restore_params['type'] = $this->params()->fromQuery('type');
Expand Down Expand Up @@ -442,6 +465,13 @@ private function getRestoreParams()
$this->restore_params['id'] = null;
}

if($this->params()->fromQuery('limit')) {
$this->restore_params['limit'] = $this->params()->fromQuery('limit');
}
else {
$this->restore_params['limit'] = 2000;
}

if($this->params()->fromQuery('jobids')) {
$this->restore_params['jobids'] = $this->params()->fromQuery('jobids');
}
Expand Down Expand Up @@ -483,9 +513,12 @@ private function getRestoreParams()
else {
$this->restore_params['versions'] = null;
}

}

/**
* Get the restore model
* @return object
*/
public function getRestoreModel()
{
if(!$this->restoreModel) {
Expand All @@ -495,6 +528,10 @@ public function getRestoreModel()
return $this->restoreModel;
}

/**
* Get the job model
* @return object
*/
public function getJobModel()
{
if(!$this->jobModel) {
Expand All @@ -504,6 +541,10 @@ public function getJobModel()
return $this->jobModel;
}

/**
* Get the client model
* @return object
*/
public function getClientModel()
{
if(!$this->clientModel) {
Expand All @@ -513,6 +554,10 @@ public function getClientModel()
return $this->clientModel;
}

/**
* Get the fileset model
* @return object
*/
public function getFilesetModel()
{
if(!$this->filesetModel) {
Expand Down
108 changes: 108 additions & 0 deletions module/Restore/src/Restore/Form/RestoreForm.php
Expand Up @@ -430,6 +430,114 @@ public function __construct($restore_params=null, /*$jobs=null,*/ $clients=null,
)
);

// Path
if(isset($restore_params['path'])) {
$this->add(array(
'name' => 'path',
'type' => 'text',
'options' => array(
'label' => _('Path')
),
'attributes' => array(
'class' => 'form-control',
'id' => 'path',
'size' => '15',
'placeholder' => '/',
'value' => $restore_params['path']
)
)
);
}
else {
$this->add(array(
'name' => 'path',
'type' => 'text',
'options' => array(
'label' => _('Path')
),
'attributes' => array(
'class' => 'form-control',
'id' => 'path',
'size' => '15',
'placeholder' => '/',
'value' => ''
)
)
);
}

// Limit
if(isset($restore_params['limit'])) {
$this->add(array(
'name' => 'limit',
'type' => 'text',
'options' => array(
'label' => _('Limit')
),
'attributes' => array(
'class' => 'form-control',
'id' => 'limit',
'size' => '15',
'placeholder' => 2000,
'value' => $restore_params['limit']
)
)
);
}
else {
$this->add(array(
'name' => 'limit',
'type' => 'text',
'options' => array(
'label' => _('Limit')
),
'attributes' => array(
'class' => 'form-control',
'id' => 'limit',
'size' => '15',
'placeholder' => 2000,
'value' => 2000
)
)
);
}

// Offset
if(isset($restore_params['offset'])) {
$this->add(array(
'name' => 'offset',
'type' => 'text',
'options' => array(
'label' => _('Offset')
),
'attributes' => array(
'class' => 'form-control',
'id' => 'offset',
'size' => '15',
'placeholder' => 0,
'value' => $restore_params['offset']
)
)
);
}
else {
$this->add(array(
'name' => 'offset',
'type' => 'text',
'options' => array(
'label' => _('Offset')
),
'attributes' => array(
'class' => 'form-control',
'id' => 'offset',
'size' => '15',
'placeholder' => 0,
'value' => 0
)
)
);
}

// JobIds hidden
$this->add(array(
'name' => 'jobids_hidden',
Expand Down

0 comments on commit 8138008

Please sign in to comment.