summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2022-07-28 13:12:43 +0200
committerErich Eckner <git@eckner.net>2022-07-28 13:12:43 +0200
commit53dcd7604c077f2a46383f89843e967f0ee9f567 (patch)
treeb7d815da6f7839909db1d8b506dd906e504ea934
parent2b4d629419f4d9d82d736050e943793b5a778ea9 (diff)
downloadcolocation-53dcd7604c077f2a46383f89843e967f0ee9f567.tar.xz
add single lo key for power and ping
-rw-r--r--html/db.php12
-rw-r--r--html/maintenance.php3
2 files changed, 9 insertions, 6 deletions
diff --git a/html/db.php b/html/db.php
index fee5ef6..960cbd3 100644
--- a/html/db.php
+++ b/html/db.php
@@ -128,14 +128,18 @@ class MyDB extends SQLite3 {
$stm -> close();
return $result['value_id'];
}
- function add_key_for($machine, $state, $comment) {
+ function add_key_for($machine, $states, $comment) {
$key_id = $this -> add_key($comment);
- $value_id = $this -> get_value_id_of($machine, $state);
+ if (!is_array($states))
+ $states = array($states);
$stm = $this -> prepare(
'INSERT INTO permissions (key_id, value_id) VALUES (:key,:value)');
- $stm -> bindValue('value', $value_id);
$stm -> bindValue('key', $key_id);
- $stm -> execute();
+ foreach ($states as $state) {
+ $value_id = $this -> get_value_id_of($machine, $state);
+ $stm -> bindValue('value', $value_id);
+ $stm -> execute();
+ }
$stm -> close();
}
}
diff --git a/html/maintenance.php b/html/maintenance.php
index b45b731..9982751 100644
--- a/html/maintenance.php
+++ b/html/maintenance.php
@@ -83,8 +83,7 @@ if (array_key_exists('lights_out_machines', $_GET)) {
break;
}
}
- $db -> add_key_for($machine_id, $power_id, 'lights-out');
- $db -> add_key_for($machine_id, $ping_id, 'lights-out');
+ $db -> add_key_for($machine_id, array($power_id, $ping_id), 'lights-out');
}
echo 'done.' . "\n";
die();