From e18d3374191a631ffad4b4d1ab781b01c8fbb7fa Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 8 Mar 2023 12:50:22 +0100 Subject: [PATCH] firmware: use model to get config data #4881 --- .../OPNsense/Core/Api/FirmwareController.php | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php index e637cf883..201da837b 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php @@ -1,7 +1,7 @@ + * Copyright (c) 2015-2023 Franco Fichtner * Copyright (c) 2015-2018 Deciso B.V. * All rights reserved. * @@ -32,6 +32,7 @@ namespace OPNsense\Core\Api; use OPNsense\Base\ApiControllerBase; use OPNsense\Core\Backend; use OPNsense\Core\Config; +use OPNsense\Core\Firmware; /** * Class FirmwareController @@ -39,6 +40,34 @@ use OPNsense\Core\Config; */ class FirmwareController extends ApiControllerBase { + /** + * @var null|BaseModel model object to work on + */ + private $modelHandle = null; + + /** + * Get (or create) model object + * @return null|BaseModel + */ + private function getModel() + { + if ($this->modelHandle == null) { + $this->modelHandle = new Firmware(); + } + return $this->modelHandle; + } + + /** + * Query model items + * @return array plain model settings (non repeating items) + * @throws \ReflectionException when not bound to model + */ + protected function getModelNodes() + { + return $this->getModel()->getNodes(); + return $result; + } + /** * return bytes in human-readable form * @param integer $bytes bytes to convert @@ -1097,26 +1126,7 @@ class FirmwareController extends ApiControllerBase */ public function getFirmwareConfigAction() { - $config = Config::getInstance()->object(); - $result = array(); - - $result['flavour'] = ''; - $result['mirror'] = ''; - $result['type'] = ''; - - if (!empty($config->system->firmware->flavour)) { - $result['flavour'] = (string)$config->system->firmware->flavour; - } - - if (!empty($config->system->firmware->type)) { - $result['type'] = (string)$config->system->firmware->type; - } - - if (!empty($config->system->firmware->mirror)) { - $result['mirror'] = (string)$config->system->firmware->mirror; - } - - return $result; + return $this->getModelNodes(); } /**