mirror of https://github.com/rusefi/msqur.git
Merge pull request #32 from nearwood/master
Improve parse errors #3, and avoid cache if it fails #31
This commit is contained in:
commit
931aedf32d
32
src/ini.php
32
src/ini.php
|
@ -1,4 +1,22 @@
|
|||
<?php
|
||||
|
||||
/* @brief Custom MSQ Parse Exceptions
|
||||
*/
|
||||
class MSQ_ParseException extends Exception {
|
||||
protected $htmlMessage;
|
||||
|
||||
public function __construct($message = null, $html = '', $code = 0, Exception $previous = null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->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 @@ class INI
|
|||
break;
|
||||
|
||||
default:
|
||||
$msDir = "unknown";
|
||||
throw new MSQ_ConfigException("Unknown/Invalid MSQ signature: $msVersion/$fwVersion");
|
||||
}
|
||||
|
||||
//Setup firmware version for matching.
|
||||
|
@ -76,9 +94,7 @@ class INI
|
|||
|
||||
debug("INI File: $iniFile");
|
||||
|
||||
$msqMap = INI::parse($iniFile, TRUE);
|
||||
|
||||
return $msqMap;
|
||||
return $iniFile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,10 +103,9 @@ class INI
|
|||
* 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 @@ class INI
|
|||
|
||||
if ($ini == FALSE || count($ini) == 0)
|
||||
{
|
||||
echo "<div class=\"error\">Error opening file: $file</div>";
|
||||
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");
|
||||
|
||||
|
|
17
src/msq.php
17
src/msq.php
|
@ -69,21 +69,20 @@ class MSQ
|
|||
$msqHeader .= "<div>Tuning SW: " . $msq->bibliography['author'] . "</div>";
|
||||
$msqHeader .= "<div>Date: " . $msq->bibliography['writeDate'] . "</div>";
|
||||
$msqHeader .= '</div>';
|
||||
$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 .= '<div class="error">Unable to load the corresponding configuration file for that MSQ. Please <a href="https://github.com/nearwood/msqur/issues/new?title=' . $issueTitle . '">file a bug!</a></div>';
|
||||
$html['msqHeader'] = $msqHeader;
|
||||
return $html; //TODO Signal caller to skip engine/metadata updates
|
||||
$htmlMessage = $msqHeader . '<div class="error">Unable to load the corresponding configuration file for that MSQ. Please <a href="https://github.com/nearwood/msqur/issues/new?title=' . $issueTitle . '">file a bug!</a></div>';
|
||||
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];
|
||||
|
|
|
@ -155,20 +155,24 @@ class Msqur
|
|||
$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 .= "<div class=\"group-$group\">";
|
||||
$html .= $v;
|
||||
$html .= '</div>';
|
||||
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 .= "<div class=\"group-$group\">";
|
||||
$html .= $v;
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
$this->db->updateCache($id, $html);
|
||||
} catch (MSQ_ParseException $e) {
|
||||
$html = $e->getHTMLMessage();
|
||||
}
|
||||
|
||||
$this->db->updateCache($id, $html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue