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:
parent
14e51ec587
commit
7257258ca4
|
@ -167,6 +167,20 @@ class HarvesterBase(SingletonPlugin):
|
||||||
log.info('Package with GUID %s not updated, skipping...' % harvest_object.guid)
|
log.info('Package with GUID %s not updated, skipping...' % harvest_object.guid)
|
||||||
return
|
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:
|
except NotFound:
|
||||||
# Package needs to be created
|
# Package needs to be created
|
||||||
|
|
||||||
|
@ -186,21 +200,8 @@ class HarvesterBase(SingletonPlugin):
|
||||||
|
|
||||||
new_package = get_action('package_create_rest')(context, package_dict)
|
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()
|
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
|
return True
|
||||||
|
|
||||||
except ValidationError,e:
|
except ValidationError,e:
|
||||||
|
|
Loading…
Reference in New Issue