Skip to content

Commit

Permalink
Merge branch '91-reindex-list-fields-in-config'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jun 27, 2014
2 parents 7459358 + 58a873a commit 4f7563f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
60 changes: 37 additions & 23 deletions ckanext/harvest/logic/action/update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import hashlib
import json

import logging
import datetime
Expand Down Expand Up @@ -133,13 +134,7 @@ def harvest_source_clear(context,data_dict):
model.Session.execute(sql)

# Refresh the index for this source to update the status object
context.update({'validate': False, 'ignore_auth': True})
package_dict = logic.get_action('package_show')(context,
{'id': harvest_source_id})

if package_dict:
package_index = PackageSearchIndex()
package_index.index_package(package_dict)
get_action('harvest_source_reindex')(context, {'id': harvest_source_id})

return {'id': harvest_source_id}

Expand Down Expand Up @@ -326,14 +321,8 @@ def harvest_jobs_run(context,data_dict):
job_obj.save()
# Reindex the harvest source dataset so it has the latest
# status
if 'extras_as_string'in context:
del context['extras_as_string']
context.update({'validate': False, 'ignore_auth': True})
package_dict = logic.get_action('package_show')(context,
{'id': job_obj.source.id})

if package_dict:
package_index.index_package(package_dict)
get_action('harvest_source_reindex')(reindex_context,
{'id': job_obj.source.id})

# resubmit old redis tasks
resubmit_jobs()
Expand Down Expand Up @@ -361,6 +350,8 @@ def harvest_jobs_run(context,data_dict):
publisher.close()
return sent_jobs


@logic.side_effect_free
def harvest_sources_reindex(context, data_dict):
'''
Reindexes all harvest source datasets with the latest status
Expand All @@ -376,14 +367,37 @@ def harvest_sources_reindex(context, data_dict):
.all()

package_index = PackageSearchIndex()

reindex_context = {'defer_commit': True}
for package in packages:
if 'extras_as_string'in context:
del context['extras_as_string']
context.update({'ignore_auth': True})
package_dict = logic.get_action('harvest_source_show')(context,
{'id': package.id})
log.debug('Updating search index for harvest source {0}'.format(package.id))
package_index.index_package(package_dict, defer_commit=True)
get_action('harvest_source_reindex')(reindex_context, {'id': package.id})

package_index.commit()
log.info('Updated search index for {0} harvest sources'.format(len(packages)))

return True

@logic.side_effect_free
def harvest_source_reindex(context, data_dict):
'''Reindex a single harvest source'''

harvest_source_id = logic.get_or_bust(data_dict, 'id')
defer_commit = context.get('defer_commit', False)

if 'extras_as_string'in context:
del context['extras_as_string']
context.update({'ignore_auth': True})
package_dict = logic.get_action('harvest_source_show')(context,
{'id': harvest_source_id})
log.debug('Updating search index for harvest source {0}'.format(harvest_source_id))

# Remove configuration values
new_dict = {}
if package_dict.get('config'):
config = json.loads(package_dict['config'])
for key, value in package_dict.iteritems():
if key not in config:
new_dict[key] = value
package_index = PackageSearchIndex()
package_index.index_package(new_dict, defer_commit=defer_commit)

return True
8 changes: 8 additions & 0 deletions ckanext/harvest/logic/auth/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,11 @@ def harvest_sources_reindex(context, data_dict):
return {'success': False, 'msg': pt._('Only sysadmins can reindex all harvest sources')}
else:
return {'success': True}

def harvest_source_reindex(context, data_dict):
'''
Authorization check for reindexing a harvest source
It forwards to harvest_source_update
'''
return harvest_source_update(context, data_dict)

0 comments on commit 4f7563f

Please sign in to comment.