diff --git a/src/ini.php b/src/ini.php index 87774e1..3313ec0 100644 --- a/src/ini.php +++ b/src/ini.php @@ -1,4 +1,22 @@ htmlMessage = $html; + } + + public function getHTMLMessage() { + return $this->htmlMessage; + } +} + +class MSQ_ConfigException extends MSQ_ParseException { } + /* * @brief INI parsing * @@ -6,7 +24,7 @@ class INI { /** - * @brief Given a signature string, finds and parses the respective INI file. + * @brief Given a signature string, calculates the respective INI file. * * Returns an array of the config file contents. * @param $signature The signature string which will be modified into a firmware/version array. @@ -60,7 +78,7 @@ public static function getConfig(&$signature) break; default: - $msDir = "unknown"; + throw new MSQ_ConfigException("Unknown/Invalid MSQ signature: $msVersion/$fwVersion"); } //Setup firmware version for matching. @@ -76,9 +94,7 @@ public static function getConfig(&$signature) debug("INI File: $iniFile"); - $msqMap = INI::parse($iniFile, TRUE); - - return $msqMap; + return $iniFile; } /** @@ -87,10 +103,9 @@ public static function getConfig(&$signature) * Based on code from: goulven.ch@gmail.com (php.net comments) http://php.net/manual/en/function.parse-ini-file.php#78815 * * @param $file The path to the INI file that will be loaded and parsed. - * @param $something Unused * @returns A huge array of arrays, starting with sections. */ - public static function parse($file, $something) + public static function parse($file) { try { @@ -107,9 +122,8 @@ public static function parse($file, $something) if ($ini == FALSE || count($ini) == 0) { - echo "
Error opening file: $file
"; error("Error or empty file: $file"); - return null; + throw new MSQ_ConfigException("Could not open MSQ config file: $file"); } else if (DEBUG) debug("Opened: $file"); diff --git a/src/msq.php b/src/msq.php index 961e970..3b2b97d 100644 --- a/src/msq.php +++ b/src/msq.php @@ -69,21 +69,20 @@ public function parseMSQ($xml, &$engine, &$metadata) $msqHeader .= "
Tuning SW: " . $msq->bibliography['author'] . "
"; $msqHeader .= "
Date: " . $msq->bibliography['writeDate'] . "
"; $msqHeader .= ''; + $html['msqHeader'] = $msqHeader; $sig = $msq->versionInfo['signature']; $sigString = $sig; - $msqMap = INI::getConfig($sig); - - if ($msqMap == null) - { + try { + $iniFile = INI::getConfig($sig); + $msqMap = INI::parse($iniFile); + } catch (MSQ_ConfigException $e) { + error('Error parsing config file: ' . $e->getMessage()); $issueTitle = urlencode("INI Request: $sigString"); - $msqHeader .= '
Unable to load the corresponding configuration file for that MSQ. Please file a bug!
'; - $html['msqHeader'] = $msqHeader; - return $html; //TODO Signal caller to skip engine/metadata updates + $htmlMessage = $msqHeader . '
Unable to load the corresponding configuration file for that MSQ. Please file a bug!
'; + throw new MSQ_ParseException("Could not load configuration file for MSQ: " . $e->getMessage(), $htmlMessage, 100, $e); } - $html['msqHeader'] = $msqHeader; - //Calling function will update $metadata['fileFormat'] = $msq->versionInfo['fileFormat']; $metadata['signature'] = $sig[1]; diff --git a/src/msqur.php b/src/msqur.php index edb8ad7..818c721 100644 --- a/src/msqur.php +++ b/src/msqur.php @@ -155,20 +155,24 @@ public function view($id) $metadata = array(); $xml = $this->db->getXML($id); if ($xml !== null) { - $groupedHtml = $msq->parseMSQ($xml, $engine, $metadata); - $this->db->updateMetadata($id, $metadata); - $this->db->updateEngine($id, $engine); - - $html = ""; - foreach($groupedHtml as $group => $v) - { - //TODO Group name as fieldset legend or sth - $html .= "
"; - $html .= $v; - $html .= '
'; + try { + $groupedHtml = $msq->parseMSQ($xml, $engine, $metadata); + $this->db->updateMetadata($id, $metadata); + $this->db->updateEngine($id, $engine); + + $html = ""; + foreach($groupedHtml as $group => $v) + { + //TODO Group name as fieldset legend or sth + $html .= "
"; + $html .= $v; + $html .= '
'; + } + + $this->db->updateCache($id, $html); + } catch (MSQ_ParseException $e) { + $html = $e->getHTMLMessage(); } - - $this->db->updateCache($id, $html); } } }