Skip to content

Commit

Permalink
Merge pull request #456 from bareos/dev/fbergkemper/master/s3905
Browse files Browse the repository at this point in the history
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 56e12f9
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 25 deletions.
5 changes: 5 additions & 0 deletions core/src/dird/ua_dotcmds.cc
Expand Up @@ -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");
Expand Down
23 changes: 23 additions & 0 deletions core/src/lib/util.cc
Expand Up @@ -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)
*/
Expand Down
1 change: 1 addition & 0 deletions core/src/lib/util.h
Expand Up @@ -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);
Expand Down
103 changes: 78 additions & 25 deletions webui/module/Restore/src/Restore/Form/RestoreForm.php
Expand Up @@ -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(
Expand All @@ -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'])) {
Expand Down Expand Up @@ -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;
}

/**
*
*/
Expand All @@ -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.