Skip to content

Commit

Permalink
Improved install script
Browse files Browse the repository at this point in the history
  • Loading branch information
berwinter committed Sep 30, 2015
1 parent 22e9313 commit e5caa14
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 42 deletions.
31 changes: 27 additions & 4 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
if (!$conn->connect_error) {
$check["mysql"] = true;
}
$conn->set_charset("utf8");

if ($conn->select_db($database)) {
$check["database"] = true;
Expand All @@ -44,6 +45,10 @@
break;
case "install":
$message = createDatabase($conn, $database);
$check["database"] = true;
break;
case "demo":
$message = loadDemo($conn, $database);
break;
case "update":
$message = updateDatabase($conn, $database);
Expand All @@ -61,7 +66,6 @@
$conn->close();
}


if (!needDatabaseUpdate($conn, $database)) {
$check["update"] = true;
}
Expand All @@ -76,6 +80,18 @@ function finishSetup() {
exit();
}

function loadDemo($conn, $database) {
$sql = file_get_contents("sql/example-data/t_names_of_charts.sql");
$sql .= file_get_contents("sql/example-data/t_menu.sql");
$sql .= file_get_contents("sql/example-data/t_names.sql");
$sql .= file_get_contents("sql/example-data/t_schema.sql");
$result = $conn->multi_query($sql);
if (!$result) {
throw new Exception("Konnte Demo Daten nicht laden: " . $conn->error);
}
return "Demo Daten erfolgreich geladen.";
}

function createDatabase($conn, $database) {
$database = $conn->real_escape_string($database);
$result = $conn->query("CREATE DATABASE IF NOT EXISTS `$database`;");
Expand Down Expand Up @@ -157,8 +173,8 @@ function resetPassword($conn) {
<link rel="stylesheet" type="text/css" href="css/format.css">
<link rel="stylesheet" type="text/css" href="css/smoothness/jquery-ui-1.9.2.custom.min.css">
<style>
#logo { margin-top:-285px; }
#menu { height: 400px; color: #555;}
#logo { margin-top:-300px; }
#menu { height: 440px; color: #555;}
#output {margin-top: 10px; color: #C22;}
#success {margin-top: 10px;}
#form { width: 100%; table-layout: fixed; border-collapse:collapse;}
Expand Down Expand Up @@ -195,6 +211,7 @@ function resetPassword($conn) {
</g>
</svg>
<div id="menu">
<p><strong>Achtung!</strong> Die Verwendung dieses Skripts kann im Fehlerfall zu Datenverlust führen. Wichtige Daten sollten zuvor gesichert werden. Nach Abschluss der Installation sollte dieses Skript unbedingt gelöscht werden, um den Datenlogger vor unberechtigem Zugriff zu schützen.</p>
<h3>Status</h3>
<ul id="status">
<?php
Expand Down Expand Up @@ -243,12 +260,18 @@ function resetPassword($conn) {
<td class="buttons" colspan="2">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" type="submit" name="action" value="reset">Passwort zurücksetzen</button>
<?php
if(!$check["database"]) {
if(!$check["mysql"]) {
echo '<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" type="submit" name="action" value="test">Verbindung testen</button>';
}
else if(!$check["database"]) {
echo '<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" type="submit" name="action" value="install">Datenbank anlegen</button>';
}
else if(!$check["update"]) {
echo '<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" type="submit" name="action" value="update">Datenbank updaten</button>';
}
else {
echo '<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" type="submit" name="action" value="demo">Lade Demo Daten</button>';
}
?>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" type="submit" name="action" value="finish">Installation abschließen</button>
</td>
Expand Down
5 changes: 4 additions & 1 deletion lib/backend/cmi-parser.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class CmiDataset
const RAD = 0x0002;
const HOURS = 0x000f;
const COUNT = 0x0011;
const LONG_SIGN = 0x80000000;
const SHORT_SIGN = 0x8000;


public function __construct($string) {
Expand All @@ -58,7 +60,8 @@ public function getFormat() {
public function getValue($value) {
switch ($this->data["type"]) {
case self::PT1000:
case self::TEMP:
case self::TEMP:
return (($value^SELF::SHORT_SIGN)-SELF::SHORT_SIGN)/10;
case self::KWH:
return $value/10;
case self::VOL:
Expand Down
22 changes: 8 additions & 14 deletions sql/example-data/t_menu.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/*
-- Query: SELECT * FROM uvr1611.t_menu
LIMIT 0, 1000
-- Date: 2013-03-31 17:20
*/
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`) VALUES (2,'Speicher','#.# °C','line',3,NULL);
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`) VALUES (3,'Heizkreise','#.# °C','line',4,NULL);
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`) VALUES (4,'Sonstige','#.# °C','line',5,NULL);
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`) VALUES (5,'Solar','#.# °C','line',6,NULL);
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`) VALUES (6,'Leistung','#.## kW','power',7,NULL);
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`) VALUES (7,'Erträge','#.# kWh','energy',8,NULL);
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`) VALUES (8,'Schema',NULL,'schema',1,'schema.svg');
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`) VALUES (9,'Kollektoren',NULL,'schema',2,'kollektoren.svg');
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`,`view`) VALUES (2,'Speicher','#.# °C','line',3,NULL,'yes');
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`,`view`) VALUES (3,'Heizkreise','#.# °C','line',4,NULL,'yes');
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`,`view`) VALUES (4,'Sonstige','#.# °C','line',5,NULL,'yes');
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`,`view`) VALUES (5,'Solar','#.# °C','line',6,NULL,'yes');
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`,`view`) VALUES (6,'Leistung','#.## kW','power',7,NULL,'yes');
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`,`view`) VALUES (7,'Erträge','#.# kWh','energy',8,NULL,'yes');
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`,`view`) VALUES (8,'Schema',NULL,'schema',1,'schema.svg','yes');
INSERT INTO `t_menu` (`id`,`name`,`unit`,`type`,`order`,`schema`,`view`) VALUES (9,'Kollektoren',NULL,'schema',2,'kollektoren.svg','yes');
6 changes: 0 additions & 6 deletions sql/example-data/t_names.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
-- Query: SELECT * FROM uvr1611.t_names
LIMIT 0, 1000
-- Date: 2013-03-31 17:19
*/
INSERT INTO `t_names` (`id`,`frame`,`type`,`name`) VALUES (1,'frame1','analog1','Speicher 1 Oben');
INSERT INTO `t_names` (`id`,`frame`,`type`,`name`) VALUES (4,'frame1','analog2','Speicher 1 Unten');
INSERT INTO `t_names` (`id`,`frame`,`type`,`name`) VALUES (5,'frame1','analog3','Speicher 2 Oben');
Expand Down
6 changes: 0 additions & 6 deletions sql/example-data/t_names_of_charts.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
-- Query: SELECT * FROM uvr1611.t_names_of_charts
LIMIT 0, 1000
-- Date: 2013-03-31 17:19
*/
INSERT INTO `t_names_of_charts` (`chart_id`,`type`,`frame`,`order`) VALUES (2,'analog1','frame1',1);
INSERT INTO `t_names_of_charts` (`chart_id`,`type`,`frame`,`order`) VALUES (2,'analog2','frame1',2);
INSERT INTO `t_names_of_charts` (`chart_id`,`type`,`frame`,`order`) VALUES (2,'analog3','frame1',3);
Expand Down
6 changes: 0 additions & 6 deletions sql/example-data/t_schema.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
-- Query: SELECT * FROM uvr1611.t_schema
LIMIT 0, 1000
-- Date: 2013-03-31 17:20
*/
INSERT INTO `t_schema` (`id`,`path`,`frame`,`type`,`format`) VALUES (1,'#speicher1_oben > tspan','frame1','analog1','#.# °C');
INSERT INTO `t_schema` (`id`,`path`,`frame`,`type`,`format`) VALUES (2,'#speicher1_unten > tspan','frame1','analog2','#.# °C');
INSERT INTO `t_schema` (`id`,`path`,`frame`,`type`,`format`) VALUES (3,'#speicher2_oben > tspan','frame1','analog3','#.# °C');
Expand Down
7 changes: 2 additions & 5 deletions sql/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,18 @@ CREATE VIEW `v_energies` AS select cast(`v_minmaxdate`.`date` as date) AS `date`
*/
DROP PROCEDURE IF EXISTS `p_energies`;
DROP PROCEDURE IF EXISTS `p_minmax`;
DELIMITER //
CREATE PROCEDURE `p_energies`()
BEGIN
REPLACE INTO t_energies (date, energy1, energy2, frame) SELECT * FROM v_energies;
END //
END ;

CREATE PROCEDURE `p_minmax`()
BEGIN
REPLACE INTO t_min (date, analog1, analog2, analog3, analog4, analog5, analog6, analog7, analog8,
analog9, analog10, analog11, analog12, analog13, analog14, analog15, analog16, speed1, speed2, speed3, speed4, power1, power2, frame) SELECT * FROM v_min;
REPLACE INTO t_max (date, analog1, analog2, analog3, analog4, analog5, analog6, analog7, analog8,
analog9, analog10, analog11, analog12, analog13, analog14, analog15, analog16, speed1, speed2, speed3, speed4, power1, power2, frame) SELECT * FROM v_max;
END //
DELIMITER ;

END ;

/*
Insert default data
Expand Down

0 comments on commit e5caa14

Please sign in to comment.