Merge branch 'clear-source-delete-related' of https://github.com/waldvogel/ckanext-harvest into waldvogel-clear-source-delete-related

This commit is contained in:
amercader 2014-09-29 13:49:19 +01:00
commit 098b54f1e5
1 changed files with 11 additions and 3 deletions

View File

@ -104,6 +104,14 @@ def harvest_source_clear(context,data_dict):
# Clear all datasets from this source from the index # Clear all datasets from this source from the index
harvest_source_index_clear(context, data_dict) harvest_source_index_clear(context, data_dict)
model = context['model']
sql = "select id from related where id in (select related_id from related_dataset where dataset_id in (select package_id from harvest_object where harvest_source_id = '{harvest_source_id}'));".format(harvest_source_id=harvest_source_id)
result = model.Session.execute(sql)
ids = []
for row in result:
ids.append(row[0])
related_ids = "('" + "','".join(ids) + "')"
sql = '''begin; update package set state = 'to_delete' where id in (select package_id from harvest_object where harvest_source_id = '{harvest_source_id}'); sql = '''begin; update package set state = 'to_delete' where id in (select package_id from harvest_object where harvest_source_id = '{harvest_source_id}');
delete from harvest_object_error where harvest_object_id in (select id from harvest_object where harvest_source_id = '{harvest_source_id}'); delete from harvest_object_error where harvest_object_id in (select id from harvest_object where harvest_source_id = '{harvest_source_id}');
@ -124,9 +132,9 @@ def harvest_source_clear(context,data_dict):
delete from package_extra where package_id in (select id from package where state = 'to_delete'); delete from package_extra where package_id in (select id from package where state = 'to_delete');
delete from member where table_id in (select id from package where state = 'to_delete'); delete from member where table_id in (select id from package where state = 'to_delete');
delete from resource_group where package_id in (select id from package where state = 'to_delete'); delete from resource_group where package_id in (select id from package where state = 'to_delete');
delete from package where id in (select id from package where state = 'to_delete'); commit;'''.format(harvest_source_id=harvest_source_id) delete from related_dataset where dataset_id in (select id from package where state = 'to_delete');
delete from related where id in {related_ids};
model = context['model'] delete from package where id in (select id from package where state = 'to_delete'); commit;'''.format(harvest_source_id=harvest_source_id, related_ids=related_ids)
model.Session.execute(sql) model.Session.execute(sql)