diff --git a/plugins/Sidebar/SidebarPlugin.py b/plugins/Sidebar/SidebarPlugin.py index 4c0d9a29..45287d49 100644 --- a/plugins/Sidebar/SidebarPlugin.py +++ b/plugins/Sidebar/SidebarPlugin.py @@ -786,6 +786,9 @@ class UiWebsocketPlugin(object): if "ADMIN" not in permissions: return self.response(to, "You don't have permission to run this command") - self.site.storage.rebuildDb() + result = self.site.storage.rebuildDb() + + if not result: + return self.response(to, {"error": "Failed to rebuild database"}) return self.response(to, "ok") diff --git a/plugins/Sidebar/media/all.js b/plugins/Sidebar/media/all.js index c6f398de..55823738 100644 --- a/plugins/Sidebar/media/all.js +++ b/plugins/Sidebar/media/all.js @@ -814,8 +814,15 @@ window.initScrollable = function () { this.tag.find("#button-dbrebuild").off("click touchend").on("click touchend", (function(_this) { return function() { _this.wrapper.notifications.add("done-dbrebuild", "info", "Database rebuilding...."); - _this.wrapper.ws.cmd("dbRebuild", [], function() { + _this.wrapper.ws.cmd("dbRebuild", [], function(response) { + + if (response !== "ok") { + _this.wrapper.notifications.add("done-dbrebuild", "error", response.error, 5000); + return _this.updateHtmlTag(); + } + _this.wrapper.notifications.add("done-dbrebuild", "done", "Database rebuilt!", 5000); + return _this.updateHtmlTag(); }); return false; @@ -1477,4 +1484,4 @@ function morphdom(fromNode, toNode, options) { module.exports = morphdom; },{}]},{},[1])(1) -}); \ No newline at end of file +}); diff --git a/src/Db/Db.py b/src/Db/Db.py index e2baf35f..4202e1c1 100644 --- a/src/Db/Db.py +++ b/src/Db/Db.py @@ -264,6 +264,7 @@ class Db(object): changed_tables.append(table_name) except Exception as err: self.log.error("Error creating table %s: %s" % (table_name, Debug.formatException(err))) + return False self.log.debug("Db check done in %.3fs, changed tables: %s" % (time.time() - s, changed_tables)) if changed_tables: diff --git a/src/Site/SiteStorage.py b/src/Site/SiteStorage.py index 084765b5..e4ae237c 100644 --- a/src/Site/SiteStorage.py +++ b/src/Site/SiteStorage.py @@ -138,7 +138,11 @@ class SiteStorage(object): self.event_db_busy = gevent.event.AsyncResult() self.log.info("Creating tables...") - self.db.checkTables() + changed_tables = self.db.checkTables() + if not changed_tables: + # It failed + # "Error creating table..." + return False cur = self.db.getCursor() cur.logging = False s = time.time()