changeset 2385:53fbdf5899ff

Use the event handling framework to (re)generate xapian indexes.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sat, 14 Jul 2007 18:42:12 +0200
parents 2b31b87db417
children aad0a118e609
files MoinMoin/PageEditor.py MoinMoin/events/__init__.py MoinMoin/events/jabbernotify.py
diffstat 3 files changed, 27 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Sat Jul 14 18:41:44 2007 +0200
+++ b/MoinMoin/PageEditor.py	Sat Jul 14 18:42:12 2007 +0200
@@ -30,7 +30,7 @@
 from MoinMoin.logfile import editlog, eventlog
 from MoinMoin.util import filesys, timefuncs, web
 from MoinMoin.mail import sendmail
-from MoinMoin.events import PageDeletedEvent, PageRenamedEvent, send_event
+from MoinMoin.events import PageDeletedEvent, PageRenamedEvent, PageCopiedEvent, send_event
 import MoinMoin.events.notification as notification
 
 # used for merging
@@ -536,7 +536,7 @@
             if request.user.may.write(newpagename):
                 # Save page text with a comment about the old name and log entry
                 savetext = u"## page was copied from %s\n%s" % (self.page_name, savetext)
-                newpage.saveText(savetext, 0, comment=comment, index=0, extra=self.page_name, action='SAVE', notify=False)
+                newpage.saveText(savetext, 0, comment=comment, extra=self.page_name, action='SAVE', notify=False)
             else:
                 # if user is  not able to write to the page itselfs we set a log entry only
                 from MoinMoin import packages
@@ -544,11 +544,9 @@
                 packages.edit_logfile_append(self, newpagename, newpath, rev, 'SAVENEW', logname='edit-log',
                                        comment=comment, author=u"CopyPage action")
 
-            if request.cfg.xapian_search:
-                from MoinMoin.search.Xapian import Index
-                index = Index(request)
-                if index.exists():
-                    index.update_page(newpagename)
+            event = PageCopiedEvent(request, newpage, self, comment)
+            send_event(event)
+
             return True, None
         except OSError, err:
             # Try to understand what happened. Maybe its better to check
@@ -605,7 +603,7 @@
             self.error = None
             # Save page text with a comment about the old name
             savetext = u"## page was renamed from %s\n%s" % (self.page_name, savetext)
-            newpage.saveText(savetext, 0, comment=comment, index=0, extra=self.page_name, action='SAVE/RENAME', notify=False)
+            newpage.saveText(savetext, 0, comment=comment, extra=self.page_name, action='SAVE/RENAME', notify=False)
             # delete pagelinks
             arena = newpage
             key = 'pagelinks'
@@ -619,14 +617,7 @@
                 cache = caching.CacheEntry(request, arena, key, scope='item')
                 cache.remove()
 
-            if request.cfg.xapian_search:
-                from MoinMoin.search.Xapian import Index
-                index = Index(request)
-                if index.exists():
-                    index.remove_item(self.page_name, now=0)
-                    index.update_page(newpagename)
-
-            event = PageRenamedEvent(request, newpage, comment)
+            event = PageRenamedEvent(request, newpage, self, comment)
             send_event(event)
 
             return True, None
@@ -658,11 +649,14 @@
             event = PageDeletedEvent(request, self, comment)
             send_event(event)
 
-            msg = self.saveText(u"deleted\n", 0, comment=comment or u'', index=1, deleted=True, notify=False)
+            msg = self.saveText(u"deleted\n", 0, comment=comment or u'', deleted=True, notify=False)
             msg = msg.replace(
                 _("Thank you for your changes. Your attention to detail is appreciated."),
                 _('Page "%s" was successfully deleted!') % (self.page_name, ))
 
+            event = PageDeletedEvent(request, self, comment)
+            send_event(event)
+
         except self.SaveError, message:
             # XXX do not only catch base class SaveError here, but
             # also the derived classes, so we can give better err msgs
@@ -1066,15 +1060,6 @@
                             info = _("Notifications sent to:")
                             msg = msg + "<p>%s %s</p>" % (info, ",".join(recipients))
 
-            if kw.get('index', 1) and request.cfg.xapian_search:
-                from MoinMoin.search.Xapian import Index
-                index = Index(request)
-                if index.exists():
-                    if deleted:
-                        index.remove_item(self.page_name)
-                    else:
-                        index.update_page(self.page_name)
-
             # Update page trail with the page we just saved.
             # This is needed for NewPage macro with backto because it does not
             # send the page we just saved.
--- a/MoinMoin/events/__init__.py	Sat Jul 14 18:41:44 2007 +0200
+++ b/MoinMoin/events/__init__.py	Sat Jul 14 18:42:12 2007 +0200
@@ -67,11 +67,22 @@
 
     def __init__(self, request, page, comment):
         PageEvent.__init__(self, request)
-        self.request = request
         self.page = page
         self.comment = comment
 
 
+class PageCopiedEvent(PageEvent):
+
+    description = u"""Page has been copied"""
+    req_superuser = False
+
+    def __init__(self, request, page, old_page, comment):
+        PageEvent.__init__(self, request)
+        self.page = page
+        self.old_page = old_page
+        self.comment = comment
+
+
 class FileAttachedEvent(PageEvent):
 
     description = u"""A new attachment has been added"""
@@ -178,6 +189,9 @@
     # Try to handle the event with each available handler (for now)
     for handle in cfg.event_handlers:
         retval = handle(event)
+
+        assert retval is None or isinstance(retval, EventResult)
+
         if retval:
             msg.append(retval)
 
--- a/MoinMoin/events/jabbernotify.py	Sat Jul 14 18:41:44 2007 +0200
+++ b/MoinMoin/events/jabbernotify.py	Sat Jul 14 18:42:12 2007 +0200
@@ -121,7 +121,7 @@
 
     subscribers = page.getSubscribers(request, return_users=1)
     notification.filter_subscriber_list(event, subscribers, True)
-    return page_change("page_renamed", request, page, subscribers, oldname=old.page_name)
+    return page_change("page_renamed", request, page, subscribers, oldname=old_name)
 
 
 def handle_user_created(event):