Commit 410493eb authored by Ad Schellevis's avatar Ad Schellevis

(traffic shaper) toggle api to support direct enable/disable

parent 7baccb7c
...@@ -165,9 +165,10 @@ class SettingsController extends ApiControllerBase ...@@ -165,9 +165,10 @@ class SettingsController extends ApiControllerBase
/** /**
* toggle pipe by uuid (enable/disable) * toggle pipe by uuid (enable/disable)
* @param $uuid item unique id * @param $uuid item unique id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array status * @return array status
*/ */
public function togglePipeAction($uuid) public function togglePipeAction($uuid, $enabled = null)
{ {
$result = array("result" => "failed"); $result = array("result" => "failed");
...@@ -176,13 +177,14 @@ class SettingsController extends ApiControllerBase ...@@ -176,13 +177,14 @@ class SettingsController extends ApiControllerBase
if ($uuid != null) { if ($uuid != null) {
$node = $mdlShaper->getNodeByReference('pipes.pipe.' . $uuid); $node = $mdlShaper->getNodeByReference('pipes.pipe.' . $uuid);
if ($node != null) { if ($node != null) {
if ($node->enabled->__toString() == "1") { if ($enabled == "0" || $enabled == "1") {
$result['result'] = "Disabled"; $node->enabled = (string)$enabled;
} elseif ($node->enabled->__toString() == "1") {
$node->enabled = "0"; $node->enabled = "0";
} else { } else {
$result['result'] = "Enabled";
$node->enabled = "1"; $node->enabled = "1";
} }
$result['result'] = $node->enabled;
// if item has toggled, serialize to config and save // if item has toggled, serialize to config and save
$mdlShaper->serializeToConfig($disable_validation = true); $mdlShaper->serializeToConfig($disable_validation = true);
Config::getInstance()->save(); Config::getInstance()->save();
...@@ -346,9 +348,10 @@ class SettingsController extends ApiControllerBase ...@@ -346,9 +348,10 @@ class SettingsController extends ApiControllerBase
/** /**
* toggle queue by uuid (enable/disable) * toggle queue by uuid (enable/disable)
* @param $uuid item unique id * @param $uuid item unique id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array status * @return array status
*/ */
public function toggleQueueAction($uuid) public function toggleQueueAction($uuid, $enabled = null)
{ {
$result = array("result" => "failed"); $result = array("result" => "failed");
...@@ -357,13 +360,14 @@ class SettingsController extends ApiControllerBase ...@@ -357,13 +360,14 @@ class SettingsController extends ApiControllerBase
if ($uuid != null) { if ($uuid != null) {
$node = $mdlShaper->getNodeByReference('queues.queue.'.$uuid); $node = $mdlShaper->getNodeByReference('queues.queue.'.$uuid);
if ($node != null) { if ($node != null) {
if ($node->enabled->__toString() == "1") { if ($enabled == "0" || $enabled == "1") {
$result['result'] = "Disabled"; $node->enabled = (string)$enabled;
} elseif ($node->enabled->__toString() == "1") {
$node->enabled = "0"; $node->enabled = "0";
} else { } else {
$result['result'] = "Enabled";
$node->enabled = "1"; $node->enabled = "1";
} }
$result['result'] = $node->enabled;
// if item has toggled, serialize to config and save // if item has toggled, serialize to config and save
$mdlShaper->serializeToConfig($disable_validation = true); $mdlShaper->serializeToConfig($disable_validation = true);
Config::getInstance()->save(); Config::getInstance()->save();
......
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