Commit 16dd8aca authored by Franco Fichtner's avatar Franco Fichtner

firmware: move reboot kerfuffle down into API call

While there, clean up messages for clarity and grammatical correctness.
parent a46014d1
...@@ -45,31 +45,40 @@ class FirmwareController extends ApiControllerBase ...@@ -45,31 +45,40 @@ class FirmwareController extends ApiControllerBase
{ {
$this->sessionClose(); // long running action, close session $this->sessionClose(); // long running action, close session
$backend = new Backend(); $backend = new Backend();
$response = json_decode(trim($backend->configdRun("firmware pkgstatus")), true); $response = json_decode(trim($backend->configdRun('firmware pkgstatus')), true);
if ($response != null) { if ($response != null) {
if (array_key_exists("connection", $response) && $response["connection"]=="error") { if (array_key_exists('connection', $response) && $response['connection'] == 'error') {
$response["status"] = "error"; $response['status_msg'] = 'Connection error.';
$response["status_msg"] = "Connection Error"; $response['status'] = 'error';
} elseif (array_key_exists("repository", $response) && $response["repository"]=="error") { } elseif (array_key_exists('repository', $response) && $response['repository'] == 'error') {
$response["status"] = "error"; $response['status_msg'] = 'Repository problem.';
$response["status_msg"] = "Repository Problem"; $response['status'] = 'error';
} elseif (array_key_exists("updates", $response) && $response['updates'] == 0) { } elseif (array_key_exists('updates', $response) && $response['updates'] == 0) {
$response["status"] = "none"; $response['status_msg'] = 'There are no updates available.';
$response["status_msg"] = "No updates found"; $response['status'] = 'none';
} elseif (array_key_exists(0, $response["upgrade_packages"]) && } elseif (array_key_exists(0, $response['upgrade_packages']) &&
$response["upgrade_packages"][0]["name"] == "pkg") { $response['upgrade_packages'][0]['name'] == 'pkg') {
$response["status"] = "ok"; $response['status_upgrade_action'] = 'pkg';
$response["status_upgrade_action"] = "pkg"; $response['status'] = 'ok';
$response["status_msg"] = "There is a mandatory update for the package manager. ". $response['status_msg'] =
"Please install and check for updates again."; 'There is a mandatory update for the package manager available. ' .
} elseif (array_key_exists("updates", $response)) { 'Please install and fetch updates again.';
$response["status"] = "ok"; } elseif (array_key_exists('updates', $response)) {
$response["status_upgrade_action"] = "all"; $response['status_upgrade_action'] = 'all';
$response["status_msg"] = sprintf("A total of %s update(s) are available.", $response["updates"]); $response['status'] = 'ok';
if ($response['updates'] == 1) {
/* keep this dynamic for template translation even though %s is always '1' */
$response['status_msg'] = sprintf('There is %s update available.', $response['updates']);
} else {
$response['status_msg'] = sprintf('There are %s updates available.', $response['updates']);
}
if ($response['upgrade_needs_reboot'] == 1) {
$response['status_msg'] += ' ' . 'This update requires a reboot.';
}
} }
} else { } else {
$response = array("status" => "unknown","status_msg" => "Current status is unknown"); $response = array('status' => 'unknown', 'status_msg' => 'Current status is unknown.');
} }
return $response; return $response;
......
...@@ -40,12 +40,8 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -40,12 +40,8 @@ POSSIBILITY OF SUCH DAMAGE.
// request status // request status
ajaxGet('/api/core/firmware/status',{},function(data,status){ ajaxGet('/api/core/firmware/status',{},function(data,status){
status_msg = data['status_msg'];
if (data['upgrade_needs_reboot'] == "1") {
status_msg = status_msg + " This update requires a reboot.";
}
$("#checkupdate_progress").removeClass("fa fa-spinner fa-pulse"); $("#checkupdate_progress").removeClass("fa fa-spinner fa-pulse");
$('#updatestatus').html(status_msg); $('#updatestatus').html(data['status_msg']);
if (data['status'] == "ok") { if (data['status'] == "ok") {
$.upgrade_action = data['status_upgrade_action']; $.upgrade_action = data['status_upgrade_action'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment