diff --git a/ckanext/xloader/plugin.py b/ckanext/xloader/plugin.py index 1b8417b9..392b1cf5 100644 --- a/ckanext/xloader/plugin.py +++ b/ckanext/xloader/plugin.py @@ -5,6 +5,9 @@ from ckan import plugins from ckan.plugins import toolkit +from ckan.model.domain_object import DomainObjectOperation +from ckan.model.resource import Resource + from . import action, auth, helpers as xloader_helpers, utils from ckanext.xloader.utils import XLoaderFormats @@ -23,7 +26,7 @@ def config_declarations(cls): class xloaderPlugin(plugins.SingletonPlugin): plugins.implements(plugins.IConfigurer) plugins.implements(plugins.IConfigurable) - plugins.implements(plugins.IResourceUrlChange) + plugins.implements(plugins.IDomainObjectModification) plugins.implements(plugins.IActions) plugins.implements(plugins.IAuthFunctions) plugins.implements(plugins.ITemplateHelpers) @@ -64,16 +67,27 @@ def configure(self, config_): ) ) - # IResourceUrlChange + # IDomainObjectModification - def notify(self, resource): + def notify(self, entity, operation): + # type: (ckan.model.Package|ckan.model.Resource, DomainObjectOperation) -> None + """ + Runs before_commit to database for Packages and Resources. + We only want to check for changed Resources for this. + We want to check if values have changed, namely the url. + See: ckan/model/modification.py.DomainObjectModificationExtension + """ + if operation != DomainObjectOperation.changed \ + or not isinstance(entity, Resource) \ + or not getattr(entity, 'url_changed', False): + return context = { "ignore_auth": True, } resource_dict = toolkit.get_action("resource_show")( context, { - "id": resource.id, + "id": entity.id, }, ) self._submit_to_xloader(resource_dict)