add server update status field

This commit is contained in:
Yu Sun
2022-08-18 22:16:02 +08:00
parent cbad19a3f6
commit 12e00952fb
3 changed files with 40 additions and 3 deletions

View File

@@ -41,6 +41,14 @@ class ECommand {
curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$return = curl_exec($ch); $return = curl_exec($ch);
curl_close($ch); curl_close($ch);
if ($return) {
pg_update(
$this -> dbconn,
"hf_mes_scada_edgeserver_controller_server",
['updated' => false],
['id' => $this -> post -> server_id]
);
}
} }
pg_insert( pg_insert(

View File

@@ -108,13 +108,41 @@ class EConfigure {
); );
} }
function update_device () { function update_device() {
return pg_update( pg_query($this -> dbconn, "BEGIN");
$res[] = pg_update(
$this -> dbconn, $this -> dbconn,
'hf_mes_scada_edgeserver_controller_device', 'hf_mes_scada_edgeserver_controller_device',
(array) $this -> post, (array) $this -> post,
['id' => $this -> post -> id] ['id' => $this -> post -> id]
); );
$res[] = $id_res = pg_query(
$this -> dbconn, sprintf(
"SELECT server_id
FROM hf_mes_scada_edgeserver_controller_device
WHERE id = '%s'
LIMIT 1",
$this -> post -> id
)
);
$server_id = pg_fetch_row($id_res)[0];
$res[] = pg_update(
$this -> dbconn,
"hf_mes_scada_edgeserver_controller_server",
['updated' => true],
['id' => $server_id]
);
if (in_array(false, $res)) {
pg_query($this -> dbconn, "ROLLBACK");
return false;
} else {
pg_query($this -> dbconn, "COMMIT");
return true;
}
} }
function get_device() { function get_device() {

View File

@@ -29,7 +29,8 @@ function init_db($server_name, $port, $user, $password) {
port int2 NOT NULL, port int2 NOT NULL,
address text NOT NULL, address text NOT NULL,
create_date timestamp NOT NULL DEFAULT NOW(), create_date timestamp NOT NULL DEFAULT NOW(),
note text note text,
updated bool NOT NULL DEFAULT false
)"); )");
pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_edgeserver_controller_device ( pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_edgeserver_controller_device (
id serial2 primary key, id serial2 primary key,