Factoids: Fix @lock and @unlock.

This commit is contained in:
Valentin Lorentz 2013-05-04 01:01:11 +02:00
parent c133d973aa
commit b9a46cef21
2 changed files with 14 additions and 8 deletions

View File

@ -583,10 +583,10 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
"""
db = self.getDb(channel)
cursor = db.cursor()
cursor.execute("UPDATE factoids, keys, relations "
"SET factoids.locked=1 WHERE key LIKE ? AND "
"factoids.id=relations.fact_id AND "
"keys.id=relations.key_id", (key,))
cursor.execute("UPDATE factoids "
"SET locked=1 WHERE factoids.id IN "
"(SELECT fact_id FROM relations WHERE key_id IN "
"(SELECT id FROM keys WHERE key LIKE ?));", (key,))
db.commit()
irc.replySuccess()
lock = wrap(lock, ['channel', 'text'])
@ -601,10 +601,10 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
"""
db = self.getDb(channel)
cursor = db.cursor()
cursor.execute("""UPDATE factoids, keys, relations
SET factoids.locked=1 WHERE key LIKE ? AND
factoids.id=relations.fact_id AND
keys.id=relations.key_id""", (key,))
cursor.execute("UPDATE factoids "
"SET locked=0 WHERE factoids.id IN "
"(SELECT fact_id FROM relations WHERE key_id IN "
"(SELECT id FROM keys WHERE key LIKE ?));", (key,))
db.commit()
irc.replySuccess()
unlock = wrap(unlock, ['channel', 'text'])

View File

@ -208,4 +208,10 @@ class FactoidsTestCase(ChannelPluginTestCase):
self.assertNotError('learn foo as "\\"bar\\""')
self.assertRegexp('whatis foo', r'"bar"')
def testLock(self):
self.assertNotError('learn foo as bar')
self.assertNotError('lock foo')
self.assertNotError('unlock foo')
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: