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.
This commit is contained in:
joetsoi 2013-03-07 20:27:27 +00:00
parent 14e51ec587
commit 7257258ca4
1 changed files with 14 additions and 13 deletions

View File

@ -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: