added synchronisation of object deletions (#1229)

This commit is contained in:
Frédéric Péters 2012-05-04 13:36:54 +02:00
parent 2684410452
commit 818be34579
1 changed files with 37 additions and 1 deletions

View File

@ -328,7 +328,8 @@ class SyncFromPcfDbView(BrowserView):
log.info('sync: start [%r] [%r]' % (timestamp, objects))
report = []
for object in ('polgroups', 'sessions', 'deputies', 'ministries', 'persons', 'commissions',
'documents', 'dossiers', 'questions', 'reunions', 'deptables', 'thesaurus'):
'documents', 'dossiers', 'questions', 'reunions', 'deptables', 'thesaurus',
'deleted'):
if not 'all' in objects:
if not object in objects:
continue
@ -1542,3 +1543,38 @@ class SyncFromPcfDbView(BrowserView):
cursor.close()
return 'OK'
def sync_deleted(self, timestamp=None):
if timestamp is not None:
return 'PASS'
cursor = self.db_connection.cursor()
cursor.execute('''SELECT t_document.id FROM t_document''')
folder_object_ids = set(self.documents_folder.objectIds())
database_object_ids = set([str(x[0]) for x in cursor.fetchall()])
log.debug('removing documents: %r', folder_object_ids-database_object_ids)
self.documents_folder.manage_delObjects(list(folder_object_ids-database_object_ids))
cursor.execute('''SELECT t_histo.id FROM t_histo
WHERE t_histo.type NOT IN ('QA', 'QE', 'QO', 'INTERP')''')
folder_object_ids = set(self.dossiers_folder.objectIds())
database_object_ids = set([str(x[0]) for x in cursor.fetchall()])
log.debug('removing dossiers: %r', folder_object_ids-database_object_ids)
self.dossiers_folder.manage_delObjects(list(folder_object_ids-database_object_ids))
cursor.execute('''SELECT t_histo.id FROM t_histo
WHERE t_histo.type IN ('QA', 'QE', 'QO', 'INTERP')''')
folder_object_ids = set(self.questions_folder.objectIds())
database_object_ids = set([str(x[0]) for x in cursor.fetchall()])
log.debug('removing questions: %r', folder_object_ids-database_object_ids)
self.questions_folder.manage_delObjects(list(folder_object_ids-database_object_ids))
cursor.execute('''SELECT id FROM t_reunion''')
folder_object_ids = set(self.parlevents_folder.objectIds())
database_object_ids = set([str(x[0]) for x in cursor.fetchall()])
log.debug('removing reunions: %r', folder_object_ids-database_object_ids)
self.parlevents_folder.manage_delObjects(list(folder_object_ids-database_object_ids))
cursor.close()
return 'DONE'