summaryrefslogtreecommitdiffstats
path: root/tabellio/pcfdb/sync.py
diff options
context:
space:
mode:
Diffstat (limited to 'tabellio/pcfdb/sync.py')
-rw-r--r--tabellio/pcfdb/sync.py31
1 files changed, 31 insertions, 0 deletions
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