mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-20 03:16:12 +00:00
firmware: use model to save data #4881
This commit is contained in:
parent
e18d337419
commit
13b70a69c7
@ -1137,67 +1137,44 @@ class FirmwareController extends ApiControllerBase
|
||||
{
|
||||
$response = ['status' => 'failure'];
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$selectedMirror = filter_var($this->request->getPost("mirror", null, ""), FILTER_SANITIZE_URL);
|
||||
$selectedFlavour = filter_var($this->request->getPost("flavour", null, ""), FILTER_SANITIZE_URL);
|
||||
$selectedType = filter_var($this->request->getPost("type", null, ""), FILTER_SANITIZE_URL);
|
||||
$selSubscription = filter_var($this->request->getPost("subscription", null, ""), FILTER_SANITIZE_URL);
|
||||
|
||||
$ret = $this->validateFirmwareOptions($selectedMirror, $selectedFlavour, $selectedType, $selSubscription);
|
||||
if (count($ret)) {
|
||||
$response['status_msgs'] = $ret;
|
||||
} else {
|
||||
$config = Config::getInstance()->object();
|
||||
$response['status'] = 'ok';
|
||||
|
||||
// config data without model, prepare xml structure and write data
|
||||
if (!isset($config->system->firmware)) {
|
||||
$config->system->addChild('firmware');
|
||||
}
|
||||
|
||||
if (!isset($config->system->firmware->mirror)) {
|
||||
$config->system->firmware->addChild('mirror');
|
||||
}
|
||||
if (empty($selSubscription)) {
|
||||
$config->system->firmware->mirror = $selectedMirror;
|
||||
} else {
|
||||
// prepend subscription
|
||||
$config->system->firmware->mirror = $selectedMirror . '/' . $selSubscription;
|
||||
}
|
||||
if (empty($config->system->firmware->mirror)) {
|
||||
unset($config->system->firmware->mirror);
|
||||
}
|
||||
|
||||
if (!isset($config->system->firmware->flavour)) {
|
||||
$config->system->firmware->addChild('flavour');
|
||||
}
|
||||
$config->system->firmware->flavour = $selectedFlavour;
|
||||
if (empty($config->system->firmware->flavour)) {
|
||||
unset($config->system->firmware->flavour);
|
||||
}
|
||||
|
||||
if (!isset($config->system->firmware->type)) {
|
||||
$config->system->firmware->addChild('type');
|
||||
}
|
||||
$config->system->firmware->type = $selectedType;
|
||||
if (empty($config->system->firmware->type)) {
|
||||
unset($config->system->firmware->type);
|
||||
}
|
||||
|
||||
if (!@count($config->system->firmware->children())) {
|
||||
unset($config->system->firmware);
|
||||
}
|
||||
|
||||
Config::getInstance()->save();
|
||||
|
||||
$this->sessionClose(); // long running action, close session
|
||||
|
||||
$backend = new Backend();
|
||||
$backend->configdRun('firmware flush');
|
||||
$backend->configdRun("firmware configure");
|
||||
}
|
||||
if (!$this->request->isPost()) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$mdl = $this->getModel();
|
||||
|
||||
$selectedMirror = filter_var($this->request->getPost('mirror', null, ''), FILTER_SANITIZE_URL);
|
||||
$selectedFlavour = filter_var($this->request->getPost('flavour', null, ''), FILTER_SANITIZE_URL);
|
||||
$selectedType = filter_var($this->request->getPost('type', null, ''), FILTER_SANITIZE_URL);
|
||||
$selSubscription = filter_var($this->request->getPost('subscription', null, ''), FILTER_SANITIZE_URL);
|
||||
|
||||
$ret = $this->validateFirmwareOptions($selectedMirror, $selectedFlavour, $selectedType, $selSubscription);
|
||||
if (count($ret)) {
|
||||
$response['status_msg'] = $ret;
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response['status'] = 'ok';
|
||||
|
||||
if (!empty($selSubscription)) {
|
||||
/* prepend subscription */
|
||||
$selectedMirror .= '/' . $selSubscription;
|
||||
}
|
||||
|
||||
$mdl->mirror = $selectedMirror;
|
||||
$mdl->flavour = $selectedFlavour;
|
||||
$mdl->type = $selectedType;
|
||||
/* discards plugins on purpose for the time being */
|
||||
|
||||
$mdl->serializeToConfig();
|
||||
Config::getInstance()->save();
|
||||
|
||||
$this->sessionClose(); // long running action, close session
|
||||
|
||||
$backend = new Backend();
|
||||
$backend->configdRun('firmware flush');
|
||||
$backend->configdRun('firmware configure');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@ -757,8 +757,8 @@
|
||||
packagesInfo(true);
|
||||
} else {
|
||||
let validation_msgs = '<ul>';
|
||||
for (i = 0; i < data['status_msgs'].length; i++) {
|
||||
validation_msgs += '<li>' + $("<textarea/>").html(data['status_msgs'][i]).text() + '</li>';
|
||||
for (i = 0; i < data['status_msg'].length; i++) {
|
||||
validation_msgs += '<li>' + $("<textarea/>").html(data['status_msg'][i]).text() + '</li>';
|
||||
}
|
||||
validation_msgs += '</ul>';
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user