import re
from wradmin.lib.mediawiki import wikipage_to_wrsleddingcache, unicode_e
+from weberror import collector # Prevent a bug of weberror # See https://bitbucket.org/bbangert/weberror/issue/3/nameerror-global-name-fallback_encoding-is-not
+collector.FALLBACK_ENCODING = 'utf-8' # --"--
+
log = logging.getLogger(__name__)
class RodelbahnController(BaseController):
from sqlalchemy.sql import select
c = model.meta.Session.connection()
- # 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 wrsleddingcache
- c.execute(wrsleddingcache.delete())
-
- # Refill wrsleddingcache table
- error_msg = ''
- for sl in sledding_pages:
- try:
- sl = wikipage_to_wrsleddingcache(sl.page_id, sl.page_title, sl.old_text)
- sl.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
- model.meta.Session.add(sl)
- except formencode.Invalid, e: error_msg = u"Fehler bei Rodelbahn '%s': " % sl.page_title + unicode_e(e)
- model.meta.Session.commit()
+ # 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 wrsleddingcache
+ if i == 1: c.execute(wrsleddingcache.delete())
+
+ # Refill wrsleddingcache table
+ error_msg = u''
+ for sl in sledding_pages:
+ try:
+ sl = wikipage_to_wrsleddingcache(sl.page_id, sl.page_title, sl.old_text)
+ sl.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(sl)
+ except (RuntimeError, formencode.Invalid) as e: error_msg = u"Fehler bei Rodelbahn '%s': " % sl.page_title + unicode_e(e)
+ if i == 1: model.meta.Session.commit()
# Redirect to result page
if error_msg == '': session['flash'] = u'Die Rodelbahnliste wurde erfolgreich aktualisiert.'