makes sure to unpublish inactive commissions (#5254)
This commit is contained in:
parent
8bbed058ea
commit
b4f012cd13
|
@ -691,6 +691,7 @@ class SyncFromPcfDbView(BrowserView):
|
||||||
WHERE t_com.st = 'S_ACTIVE'
|
WHERE t_com.st = 'S_ACTIVE'
|
||||||
%s''' % where_ts)
|
%s''' % where_ts)
|
||||||
count = 0
|
count = 0
|
||||||
|
existing_commissions = {}
|
||||||
while True:
|
while True:
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
if row is None:
|
if row is None:
|
||||||
|
@ -705,6 +706,7 @@ class SyncFromPcfDbView(BrowserView):
|
||||||
commission_folder = getattr(self.commissions_folder, cat_id)
|
commission_folder = getattr(self.commissions_folder, cat_id)
|
||||||
|
|
||||||
com_code = self.plone_utils.normalizeString(code)
|
com_code = self.plone_utils.normalizeString(code)
|
||||||
|
existing_commissions[com_code] = category
|
||||||
if title[0] == title[0].lower():
|
if title[0] == title[0].lower():
|
||||||
title = title[0].upper() + title[1:]
|
title = title[0].upper() + title[1:]
|
||||||
if not hasattr(commission_folder, com_code):
|
if not hasattr(commission_folder, com_code):
|
||||||
|
@ -828,6 +830,35 @@ class SyncFromPcfDbView(BrowserView):
|
||||||
# many things happened, commit
|
# many things happened, commit
|
||||||
transaction.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()
|
cursor.close()
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
Reference in New Issue