From 03d4dcf02948bbeb1a3fd1c2d56aa466a7b442d9 Mon Sep 17 00:00:00 2001 From: souliane Date: Mon, 24 Mar 2014 16:21:14 +0100 Subject: [PATCH] plugin account: bug fix profile deletion from the database + unsubscribe the contacts --- src/core/xmpp.py | 2 +- src/memory/sqlite.py | 12 ++++++++++-- src/plugins/plugin_misc_account.py | 9 +++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/core/xmpp.py b/src/core/xmpp.py index 59106dcc..f6fce20d 100644 --- a/src/core/xmpp.py +++ b/src/core/xmpp.py @@ -84,7 +84,7 @@ class SatXMPPClient(client.XMPPClient): self.conn_deferred.callback(None) def initializationFailed(self, reason): - print "initializationFailed: %s" % reason + error(_("ERROR: XMPP connection failed for profile '%(profile)s': %(reason)s" % {'profile': self.profile, 'reason': reason})) self.host_app.bridge.connectionError("AUTH_ERROR", self.profile) try: client.XMPPClient.initializationFailed(self, reason) diff --git a/src/memory/sqlite.py b/src/memory/sqlite.py index f321538a..25d86152 100644 --- a/src/memory/sqlite.py +++ b/src/memory/sqlite.py @@ -85,6 +85,9 @@ class SqliteStorage(object): self.dbpool = adbapi.ConnectionPool("sqlite3", db_filename, check_same_thread=False) # init_defer is the initialisation deferred, initialisation is ok when all its callbacks have been done + # XXX: foreign_keys activation doesn't seem to work, probably because of the multi-threading + # All the requests that need to use this feature should be run with runInteraction instead, + # so you can set the PRAGMA as it is done in self.deleteProfile init_defer = self.dbpool.runOperation("PRAGMA foreign_keys = ON").addErrback(lambda x: error(_("Can't activate foreign keys"))) def getNewBaseSql(): @@ -162,8 +165,13 @@ class SqliteStorage(object): error(_("Can't delete profile [%s]") % name) return failure - del self.profiles[name] - d = self.dbpool.runQuery("DELETE FROM profiles WHERE name = ?", (name, )) + def delete(txn): + del self.profiles[name] + txn.execute("PRAGMA foreign_keys = ON") + txn.execute("DELETE FROM profiles WHERE name = ?", (name,)) + return None + + d = self.dbpool.runInteraction(delete) d.addCallback(lambda ignore: info(_("Profile [%s] deleted") % name)) d.addErrback(deletionError) return d diff --git a/src/plugins/plugin_misc_account.py b/src/plugins/plugin_misc_account.py index 9c2ef452..1475e2dd 100755 --- a/src/plugins/plugin_misc_account.py +++ b/src/plugins/plugin_misc_account.py @@ -105,6 +105,7 @@ class ProsodyRegisterProtocol(protocol.ProcessProtocol): d = defer.Deferred() prosody_reg = ProsodyRegisterProtocol(password, d) prosody_exe = join(plugin._prosody_path, plugin.getConfig('prosodyctl')) + # TODO delete account which are not on the same host reactor.spawnProcess(prosody_reg, prosody_exe, [prosody_exe, command, "%s@%s" % (profile, plugin.getConfig('new_account_domain'))], path=plugin._prosody_path) return d @@ -318,6 +319,14 @@ SàT team""" % {'login': login, 'password': password, 'jid': "%s@%s" % (login, s @param profile """ def userDeleted(result): + client = self.host.profiles[profile] + + for jid_ in client.roster._jids: # empty roster + client.presence.unsubscribe(jid_) + + for jid_ in self.host.memory.getWaitingSub(profile): # delete waiting subscriptions + self.host.memory.delWaitingSub(jid_) + self.host.disconnect(profile) self.host.memory.asyncDeleteProfile(profile, force=True) return defer.succeed({})