From 1454d8d40fe71fee247f423d36951ae8f42d961d Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sat, 30 May 2020 10:08:05 +0200 Subject: [PATCH] get defaults from configparser --- install/lib/class.FroxlorInstall.php | 11 ++++++ lib/Froxlor/Config/ConfigParser.php | 50 ++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index 0e4bb52b..0ca253ce 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -505,6 +505,17 @@ class FroxlorInstall $this->_updateSetting($upd_stmt, 'error', 'system', 'errorlog_level'); } + $distros = glob(\Froxlor\FileDir::makeCorrectDir(\Froxlor\Froxlor::getInstallDir() . '/lib/configfiles/') . '*.xml'); + foreach ($distros as $_distribution) { + if($this->_data['distribution'] == str_replace(".xml", "", strtolower(basename($_distribution)))) { + $dist = new \Froxlor\Config\ConfigParser($_distribution); + $defaults = $dist->getDefaults(); + foreach ($defaults->property as $property) { + $this->_updateSetting($upd_stmt, $property->value, $property->settinggroup, $property->varname); + } + } + } + if (file_exists(dirname(__DIR__).'/../lib/configfiles/'.$this->_data['distribution'].'.xml')) { $xml = simplexml_load_file(dirname(__DIR__).'/../lib/configfiles/'.$this->_data['distribution'].'.xml'); foreach($xml->distribution->defaults->property as $property) { diff --git a/lib/Froxlor/Config/ConfigParser.php b/lib/Froxlor/Config/ConfigParser.php index ca995d7c..c881bcdd 100644 --- a/lib/Froxlor/Config/ConfigParser.php +++ b/lib/Froxlor/Config/ConfigParser.php @@ -39,6 +39,13 @@ class ConfigParser */ private $services = array(); + /** + * Holding the available defaults in the XML + * + * @var array + */ + private $defaults = array(); + /** * Store the parsed SimpleXMLElement for usage * @@ -147,7 +154,7 @@ class ConfigParser * * @return bool */ - private function parse() + private function parseServices() { // We only want to parse the stuff one time if ($this->isparsed == true) { @@ -174,6 +181,29 @@ class ConfigParser return true; } + /** + * Parse the XML and populate $this->services + * + * @return bool + */ + private function parseDefaults() + { + // We only want to parse the stuff one time + if ($this->isparsed == true) { + return true; + } + + // Get all defaults + $defaults = $this->xml->xpath('//defaults'); + foreach ($defaults as $default) { + $this->defaults = $default; + } + + // Switch flag to indicate we parsed our data + $this->isparsed = true; + return true; + } + /** * Return all services defined by the XML * @@ -184,9 +214,25 @@ class ConfigParser public function getServices() { // Let's parse this shit(!) - $this->parse(); + $this->parseServices(); // Return our carefully searched for services return $this->services; } + + /** + * Return all defaults defined by the XML + * + * The array will hold ConfigDefaults - Objects for further handling + * + * @return array + */ + public function getDefaults() + { + // Let's parse this shit(!) + $this->parseDefaults(); + + // Return our carefully searched for defaults + return $this->defaults; + } }