How to delete a message from the archive
from
slinkp
on Mar 30, 2009 06:16 PM
(Dumping this here in case anybody needs it in the future)
I got a request from an openplans.org to delete some accidentally-posted messages from a Listen archive. Listen doesn't seem to have such a feature; here's what I stumbled ignorantly through that seems to mostly work.... Merely deleting the offending messages from the ZMI causes massive breakage :-\
$ zopectl debug
Password:
Starting debugger (the name "app" is bound to the top-level Zope object)
...
>>> msg_paths >>> listenlist >>> from zope.app import zapi
>>> from Products.listen.interfaces import ISearchableArchive
>>> search >>> parent_path >>> for p in msg_paths:
... search.uncatalog_object(p)
... parent.manage_delObjects([p.split('/')[-1]])
>>> search
# Now reindex the neighboring messages... hacky I know, but nothing else I tried worked without errors:
>>> for brain in search.searchResults(path=parent_path):
... search.catalog_object(brain.getObject(), brain.getPath())
>>> import transaction
>>> transaction.get().note('I deleted some messages through the console')
>>> transaction.commit()
After that, all views I tried worked OK, except that the parent message thinks it has the old number of replies.