-
- # As MySQL does not support transactions we make a dry run first and only continue if there is no fatal error
- for i in range(2):
- # Query all sledding routes
- q = select([page, categorylinks, revision, text], (page.c.page_latest==revision.c.rev_id) & (text.c.old_id==revision.c.rev_text_id) & (categorylinks.c.cl_from==page.c.page_id) & (categorylinks.c.cl_to==u'Rodelbahn'))
- sledding_pages = c.execute(q)
- # Original SQL:
- # sql = u"select page_id, rev_id, old_id, page_title, old_text, 'In_Arbeit' in (select cl_to from categorylinks where cl_from=page_id) as under_construction from page, revision, text, categorylinks where page_latest=rev_id and old_id=rev_text_id and cl_from=page_id and cl_to='Rodelbahn' order by page_title"
-
- # Delete all existing entries in wrsledruncache
- if i == 1: c.execute(wrsledruncache.delete())
-
- # Refill wrsledruncache table
- error_msg = u''
- for sl in sledding_pages:
- try:
- start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(sl.old_text, model.WrSledrunCache())
- sledrun.page_id = sl.page_id
- sledrun.page_title = sl.page_title
- sledrun.under_construction = c.execute(select([categorylinks], (categorylinks.c.cl_from==sl.page_id) & (categorylinks.c.cl_to == u'In_Arbeit')).alias('x').count()).fetchone()[0] > 0 # It would be better to do this in the query above
- if i == 1: model.meta.Session.add(sledrun)
- except (RuntimeError, formencode.Invalid) as e: error_msg = u"Fehler bei Rodelbahn '%s': " % sl.page_title + unicode(e)
- if i == 1: model.meta.Session.commit()
-
- # Redirect to result page
- if error_msg == '': session['flash'] = u'Die Rodelbahnliste wurde erfolgreich aktualisiert.'
- else: session['flash'] = error_msg
+ try:
+ wrpylib.wrmwcache.update_wrsledruncache(c)
+ session['flash'] = u'Die Rodelbahnliste wurde erfolgreich aktualisiert.'
+ except wrpylib.wrmwcache.UpdateCacheError as e:
+ if len(e.args) == 3: session['flash'] = u"Fehler bei Rodelbahn '{0}': {1}".format(e.args[1], e.args[2])
+ else: session['flash'] = unicode(e)