From 54aa68ec5883ce419917b59c93a3445df43201c3 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Wed, 15 Sep 2021 22:07:28 +0200 Subject: [PATCH] Added import/export compatibility for version 1.7 --- server/server.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/server/server.js b/server/server.js index b8d0c90f8..b284d868b 100644 --- a/server/server.js +++ b/server/server.js @@ -948,6 +948,8 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); await R.exec("DELETE FROM monitor_notification"); await R.exec("DELETE FROM monitor_tls_info"); await R.exec("DELETE FROM notification"); + await R.exec("DELETE FROM monitor_tag"); + await R.exec("DELETE FROM tag"); await R.exec("DELETE FROM monitor"); } @@ -972,11 +974,18 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); for (let i = 0; i < monitorListData.length; i++) { if ((importHandle == "skip" && monitorNameListString.includes(monitorListData[i].name) == false) || importHandle == "keep" || importHandle == "overwrite") { + if (backupData.version.includes("1.7")) { + var retryInterval = monitorListData[i].retryInterval; + } else { + var retryInterval = 0; + } + let monitor = { name: monitorListData[i].name, type: monitorListData[i].type, url: monitorListData[i].url, interval: monitorListData[i].interval, + retryInterval: retryInterval, hostname: monitorListData[i].hostname, maxretries: monitorListData[i].maxretries, port: monitorListData[i].port, @@ -1002,6 +1011,34 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); bean.user_id = socket.userID await R.store(bean) + if (backupData.version.includes("1.7")) { + if (monitorListData[i].tags.length >= 1) { + for (let o = 0; o < monitorListData[i].tags.length; o++) { + + let tag = await R.findOne("tag", " name = ?", [ + monitorListData[i].tags[o].name, + ]) + + if (! tag) { + let beanTag = R.dispense("tag") + beanTag.name = monitorListData[i].tags[o].name + beanTag.color = monitorListData[i].tags[o].color + await R.store(beanTag) + + var tagId = beanTag.id + } else { + var tagId = tag.id + } + + await R.exec("INSERT INTO monitor_tag (tag_id, monitor_id, value) VALUES (?, ?, ?)", [ + tagId, + bean.id, + monitorListData[i].tags[o].value, + ]) + } + } + } + await updateMonitorNotification(bean.id, notificationIDList) if (monitorListData[i].active == 1) {