From 7257258ca4973df1e37d0564abbcf7cc87ad895e Mon Sep 17 00:00:00 2001 From: joetsoi Date: Thu, 7 Mar 2013 20:27:27 +0000 Subject: [PATCH] mark new harvest objects as current When a new harvest_object for a new package was being created, it was immediately being marked as false, as all objects were marked as false, including the new object just created and newly marked as current=true. Fix so that old HarvestObjects are only marked as current=False when updating an existing package. --- ckanext/harvest/harvesters/base.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/ckanext/harvest/harvesters/base.py b/ckanext/harvest/harvesters/base.py index 913442d..0960a38 100644 --- a/ckanext/harvest/harvesters/base.py +++ b/ckanext/harvest/harvesters/base.py @@ -167,6 +167,20 @@ class HarvesterBase(SingletonPlugin): log.info('Package with GUID %s not updated, skipping...' % harvest_object.guid) return + # Flag the other objects linking to this package as not current anymore + from ckanext.harvest.model import harvest_object_table + conn = Session.connection() + u = update(harvest_object_table) \ + .where(harvest_object_table.c.package_id==bindparam('b_package_id')) \ + .values(current=False) + conn.execute(u, b_package_id=new_package['id']) + + # Flag this as the current harvest object + + harvest_object.package_id = new_package['id'] + harvest_object.current = True + harvest_object.save() + except NotFound: # Package needs to be created @@ -186,21 +200,8 @@ class HarvesterBase(SingletonPlugin): new_package = get_action('package_create_rest')(context, package_dict) - # Flag the other objects linking to this package as not current anymore - from ckanext.harvest.model import harvest_object_table - conn = Session.connection() - u = update(harvest_object_table) \ - .where(harvest_object_table.c.package_id==bindparam('b_package_id')) \ - .values(current=False) - conn.execute(u, b_package_id=new_package['id']) Session.commit() - # Flag this as the current harvest object - - harvest_object.package_id = new_package['id'] - harvest_object.current = True - harvest_object.save() - return True except ValidationError,e: