Skip to content
Permalink
Browse files

Merge pull request #456 from bareos/dev/fbergkemper/master/s3905

pre-fill restore form element "replace" according to selected restore job in the webui
  • Loading branch information
fbergkemper committed Mar 26, 2020
2 parents 9aef75f + b794e54 commit 56e12f9c902936a38637a51dc23404d684e3bacc
Showing with 107 additions and 25 deletions.
  1. +5 −0 core/src/dird/ua_dotcmds.cc
  2. +23 −0 core/src/lib/util.cc
  3. +1 −0 core/src/lib/util.h
  4. +78 −25 webui/module/Restore/src/Restore/Form/RestoreForm.php
@@ -1480,6 +1480,11 @@ bool DotDefaultsCmd(UaContext* ua, const char* cmd)
ua->send->SendBuffer();
ua->send->ObjectKeyValue(
"where", "%s=", (job->RestoreWhere ? job->RestoreWhere : ""), "%s\n");
if(job->JobType == JT_RESTORE) {
ua->send->SendBuffer();
ua->send->ObjectKeyValue(
"replace", "%s=", job_replace_to_str(job->replace), "%s\n");
}
ua->send->SendBuffer();
ua->send->ObjectKeyValue("level", "%s=", JobLevelToString(job->JobLevel),
"%s\n");
@@ -584,6 +584,29 @@ const char* job_type_to_str(int type)
return str;
}

const char* job_replace_to_str(int replace)
{
const char* str = NULL;
switch(replace) {
case REPLACE_ALWAYS:
str = _("always");
break;
case REPLACE_IFNEWER:
str = _("ifnewer");
break;
case REPLACE_IFOLDER:
str = _("ifolder");
break;
case REPLACE_NEVER:
str = _("never");
break;
default:
str = _("Unknown Replace");
break;
}
return str;
}

/*
* Convert ActionOnPurge to string (Truncate, Erase, Destroy)
*/
@@ -53,6 +53,7 @@ int RunProgram(char* prog, int wait, POOLMEM*& results);
int RunProgramFullOutput(char* prog, int wait, POOLMEM*& results);
char* action_on_purge_to_string(int aop, PoolMem& ret);
const char* job_type_to_str(int type);
const char* job_replace_to_str(int relace);
const char* job_status_to_str(int stat);
const char* job_level_to_str(int level);
const char* volume_status_to_str(const char* status);
@@ -344,29 +344,8 @@ public function __construct($restore_params=null, $clients=null, $filesets=null,
}

// Replace
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(
if(isset($this->restore_params['restorejob'])) {
$this->add(array(
'name' => 'replace',
'type' => 'select',
'options' => array(
@@ -381,12 +360,56 @@ public function __construct($restore_params=null, $clients=null, $filesets=null,
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'id' => 'replace',
'value' => 'never',
'disabled' => true
'value' => $this->determineReplaceDirective($this->restore_params['restorejob'])
)
)
);
}
else {
if(isset($restore_params['client']) && count($this->getRestoreJobList()) > 0) {
$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' => @array_pop($this->getRestoreJobReplaceDirectives()),
)
)
);
}
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' => 'always',
'disabled' => true
)
)
);
}
}

// Where
if(isset($this->restore_params['restorejob'])) {
@@ -631,6 +654,20 @@ private function getRestoreJobWhereDirectives()
return $selectData;
}

/**
*
*/
private function getRestoreJobReplaceDirectives()
{
$selectData = array();
if(!empty($this->restorejobresources)) {
foreach($this->restorejobresources as $restorejob) {
$selectData[$restorejob['replace']] = $restorejob['replace'];
}
}
return $selectData;
}

/**
*
*/
@@ -647,4 +684,20 @@ private function determineWhereDirective($restorejob=null)
return $where;
}

/**
*
*/
private function determineReplaceDirective($restorejob=null)
{
$replace = null;
if(isset($restorejob)) {
foreach($this->restorejobresources as $restorejobresource) {
if($restorejobresource['job'] == $restorejob) {
$replace = $restorejobresource['replace'];
}
}
}
return $replace;
}

}

0 comments on commit 56e12f9

Please sign in to comment.
You can’t perform that action at this time.