Fix source clean command on CKAN > 2.5, as related don't exist any more
This commit is contained in:
parent
86edc4209b
commit
6354ad5656
|
@ -109,16 +109,19 @@ def harvest_source_clear(context, data_dict):
|
||||||
|
|
||||||
model = context['model']
|
model = context['model']
|
||||||
|
|
||||||
sql = '''select id from related where id in (
|
# CKAN-2.6 or above: related don't exist any more
|
||||||
select related_id from related_dataset where dataset_id in (
|
if toolkit.check_ckan_version(max_version='2.5.99'):
|
||||||
select package_id from harvest_object
|
|
||||||
where harvest_source_id = '{harvest_source_id}'));'''.format(
|
sql = '''select id from related where id in (
|
||||||
harvest_source_id=harvest_source_id)
|
select related_id from related_dataset where dataset_id in (
|
||||||
result = model.Session.execute(sql)
|
select package_id from harvest_object
|
||||||
ids = []
|
where harvest_source_id = '{harvest_source_id}'));'''.format(
|
||||||
for row in result:
|
harvest_source_id=harvest_source_id)
|
||||||
ids.append(row[0])
|
result = model.Session.execute(sql)
|
||||||
related_ids = "('" + "','".join(ids) + "')"
|
ids = []
|
||||||
|
for row in result:
|
||||||
|
ids.append(row[0])
|
||||||
|
related_ids = "('" + "','".join(ids) + "')"
|
||||||
|
|
||||||
sql = '''begin;
|
sql = '''begin;
|
||||||
update package set state = 'to_delete' where id in (
|
update package set state = 'to_delete' where id in (
|
||||||
|
@ -194,15 +197,27 @@ def harvest_source_clear(context, data_dict):
|
||||||
select id from package where state = 'to_delete');
|
select id from package where state = 'to_delete');
|
||||||
delete from member where table_id in (
|
delete from member where table_id in (
|
||||||
select id from package where state = 'to_delete');
|
select id from package where state = 'to_delete');
|
||||||
delete from related_dataset where dataset_id in (
|
'''.format(
|
||||||
select id from package where state = 'to_delete');
|
harvest_source_id=harvest_source_id)
|
||||||
delete from related where id in {related_ids};
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
if toolkit.check_ckan_version(max_version='2.5.99'):
|
||||||
|
sql += '''
|
||||||
|
delete from related_dataset where dataset_id in (
|
||||||
|
select id from package where state = 'to_delete');
|
||||||
|
delete from related where id in {related_ids};
|
||||||
|
delete from package where id in (
|
||||||
|
select id from package where state = 'to_delete');
|
||||||
|
'''.format(related_ids=related_ids)
|
||||||
|
else:
|
||||||
|
# CKAN-2.6 or above: related don't exist any more
|
||||||
|
sql += '''
|
||||||
|
delete from package where id in (
|
||||||
|
select id from package where state = 'to_delete');
|
||||||
|
'''
|
||||||
|
|
||||||
|
sql += '''
|
||||||
|
commit;
|
||||||
|
'''
|
||||||
model.Session.execute(sql)
|
model.Session.execute(sql)
|
||||||
|
|
||||||
# Refresh the index for this source to update the status object
|
# Refresh the index for this source to update the status object
|
||||||
|
|
Loading…
Reference in New Issue