Fix Watchlist Email Notification Intervals

Last modified by Ecaterina Moraru (Valica) on 2021/03/18 11:28

cogHelps migrating to the new interval format of watchlist storage introduced in XWiki 2.0
TypeSnippet
Category
Developed by

Arnaud Bourrée

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

The email notifications interval format changed with XWiki 2.0, if you are using the watchlist and upgrading from 1.x to 2.x you can use this script to migrate intervals in user profiles.
{{groovy}}
for(du in xwiki.search("select doc from XWikiDocument doc, BaseObject obj where obj.name = doc.fullName and obj.className = 'XWiki.WatchListClass' and doc.fullName <> 'XWiki.Admin' order by doc.fullName")) {
  u = xwiki.getDocument(du.fullName)
  wl = u.getObject('XWiki.WatchListClass')
  print u
  print " "
  if ("1".equals(wl.interval)) {
     wl.interval = "Scheduler.WatchListHourlyNotifier"
     u.save("Correct WatchList Email notification interval")
   }
  if ("2".equals(wl.interval)) {
     wl.interval = "Scheduler.WatchListDailyNotifier"
     u.save("Correct WatchList Email notification interval")
   }
  if ("3".equals(wl.interval)) {
     wl.interval = "Scheduler.WatchListWeeklyNotifier"
     u.save("Correct WatchList Email notification interval")
   }
  print wl.interval
  print "\n"
}
{{/groovy}}

The same as above, but usefully in a multi wiki setup. This Snippet adds the possibillity for the admin user to fix the watch list notification interval in any subwiki.

{{groovy}}

String form = "<form>Wiki: <input type='text' name='wiki' value='${request.wiki? request.wiki: xcontext.getDatabase()}' /> <input type='submit'/> <br /> Update: <input type='checkbox' name='doUpgrade' /></form>"
print "{{html}}$form{{/html}}"

print "\n"
def origDatabase = xcontext.getDatabase()
try{
if(request.wiki) {
 xcontext.setDatabase(request.wiki)
}

print "----"

for(du in xwiki.search("select doc from XWikiDocument doc, BaseObject obj where obj.name = doc.fullName and obj.className = 'XWiki.WatchListClass' and doc.fullName <> 'XWiki.Admin' order by doc.fullName")) {
   u = xwiki.getDocument(du.fullName)
   wl = u.getObject('XWiki.WatchListClass')
   print u
   print " "
  if(request.doUpgrade) {
   if ("1".equals(wl.interval)) {
      wl.interval = "Scheduler.WatchListHourlyNotifier"
      u.save("Correct WatchList Email notification interval")
   }
   if ("2".equals(wl.interval)) {
      wl.interval = "Scheduler.WatchListDailyNotifier"
      u.save("Correct WatchList Email notification interval")
   }
   if ("3".equals(wl.interval)) {
      wl.interval = "Scheduler.WatchListWeeklyNotifier"
      u.save("Correct WatchList Email notification interval")
   }
  }
   print " interval " +  wl.interval
   print "\n"
}
}
finally {
xcontext.setDatabase(origDatabase)
}

{{/groovy}}
Tags: watchlist
     

Get Connected