Skip to content

Commit

Permalink
ResourceGroup optional, because it is removed in recent versions of C…
Browse files Browse the repository at this point in the history
…KAN.
  • Loading branch information
David Read committed Nov 10, 2015
1 parent 4364f54 commit 4797f2f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
19 changes: 9 additions & 10 deletions ckanext/archiver/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,15 @@ def create(cls, resource_id):
c.resource_id = resource_id

# Find the package_id for the resource.
q = """
SELECT P.id from package P
INNER JOIN resource_group RG ON RG.package_id = P.id
INNER JOIN resource R ON R.resource_group_id = RG.id
WHERE R.id = '%s';
"""
row = model.Session.execute(q % c.resource_id).first()
if not row or not row[0]:
raise Exception("Missing dataset")
c.package_id = row[0]
dataset = model.Session.query(model.Package)
if hasattr(model, 'ResourceGroup'):
# earlier CKANs had ResourceGroup
dataset = dataset.join(model.ResourceGroup)
dataset = dataset \
.join(model.Resource) \
.filter_by(id=resource_id) \
.one()
c.package_id = dataset.id
return c

@property
Expand Down
6 changes: 5 additions & 1 deletion ckanext/archiver/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def update_config(self, config):

def create_archiver_resource_task(resource, queue):
from pylons import config
package = resource.resource_group.package
if hasattr(model, 'ResourceGroup'):
# earlier CKANs had ResourceGroup
package = resource.resource_group.package
else:
package = resource.package
task_id = '%s/%s/%s' % (package.name, resource.id[:4], make_uuid()[:4])
ckan_ini_filepath = os.path.abspath(config['__file__'])
celery.send_task('archiver.update_resource', args=[ckan_ini_filepath, resource.id, queue],
Expand Down

0 comments on commit 4797f2f

Please sign in to comment.