From b4f012cd13699b8347f89b881b7000876021e896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 12 Aug 2014 13:36:25 +0200 Subject: [PATCH] makes sure to unpublish inactive commissions (#5254) --- tabellio/pcfdb/sync.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tabellio/pcfdb/sync.py b/tabellio/pcfdb/sync.py index 53a2102..1c4d488 100644 --- a/tabellio/pcfdb/sync.py +++ b/tabellio/pcfdb/sync.py @@ -691,6 +691,7 @@ class SyncFromPcfDbView(BrowserView): WHERE t_com.st = 'S_ACTIVE' %s''' % where_ts) count = 0 + existing_commissions = {} while True: row = cursor.fetchone() if row is None: @@ -705,6 +706,7 @@ class SyncFromPcfDbView(BrowserView): commission_folder = getattr(self.commissions_folder, cat_id) com_code = self.plone_utils.normalizeString(code) + existing_commissions[com_code] = category if title[0] == title[0].lower(): title = title[0].upper() + title[1:] if not hasattr(commission_folder, com_code): @@ -828,6 +830,35 @@ class SyncFromPcfDbView(BrowserView): # many things happened, commit transaction.commit() + + # second pass, to make sure inactive commissions are unpublished. + cursor.execute('''SELECT t_com.id, t_com.st, t_com.nom, code, compets, t_comcat.nom + FROM t_com JOIN t_comcat + ON (t_com.comcat = t_comcat.id) + WHERE t_com.st = 'S_INACTIVE' + %s''' % where_ts) + while True: + row = cursor.fetchone() + if row is None: + break + com_id, state, title, code, compets, category = row + + cat_id = self.plone_utils.normalizeString(category) + if not hasattr(self.commissions_folder, cat_id): + self.commissions_folder.invokeFactory('Folder', + cat_id, title=category) + commission_folder = getattr(self.commissions_folder, cat_id) + + com_code = self.plone_utils.normalizeString(code) + if existing_commissions.get(com_code) == category: + # a new one exists in the same place, continue happily + continue + + if hasattr(commission_folder, com_code): + log.debug('sync: unpublising commission: %r' % com_code) + object = getattr(commission_folder, com_code) + self.unpublish(object) + cursor.close() return count