--- a/cubicweb/hooks/syncsources.py Wed Oct 05 15:30:10 2016 +0200
+++ b/cubicweb/hooks/syncsources.py Thu Oct 06 12:11:23 2016 +0200
@@ -135,68 +135,3 @@
except IndexError:
# XXX no source linked to the host config yet
pass
-
-
-# source mapping synchronization ###############################################
-#
-# Expect cw_for_source/cw_schema are immutable relations (i.e. can't change from
-# a source or schema to another).
-
-class SourceMappingImmutableHook(SourceHook):
- """check cw_for_source and cw_schema are immutable relations
-
- XXX empty delete perms would be enough?
- """
- __regid__ = 'cw.sources.mapping.immutable'
- __select__ = SourceHook.__select__ & hook.match_rtype('cw_for_source', 'cw_schema')
- events = ('before_add_relation',)
- def __call__(self):
- if not self._cw.added_in_transaction(self.eidfrom):
- msg = _("You can't change this relation")
- raise validation_error(self.eidfrom, {self.rtype: msg})
-
-
-class SourceMappingChangedOp(hook.DataOperationMixIn, hook.Operation):
- def check_or_update(self, checkonly):
- cnx = self.cnx
- # take care, can't call get_data() twice
- try:
- data = self.__data
- except AttributeError:
- data = self.__data = self.get_data()
- for schemacfg, source in data:
- if source is None:
- source = schemacfg.cwsource.repo_source
- if cnx.added_in_transaction(schemacfg.eid):
- if not cnx.deleted_in_transaction(schemacfg.eid):
- source.add_schema_config(schemacfg, checkonly=checkonly)
- elif cnx.deleted_in_transaction(schemacfg.eid):
- source.del_schema_config(schemacfg, checkonly=checkonly)
- else:
- source.update_schema_config(schemacfg, checkonly=checkonly)
-
- def precommit_event(self):
- self.check_or_update(True)
-
- def postcommit_event(self):
- self.check_or_update(False)
-
-
-class SourceMappingChangedHook(SourceHook):
- __regid__ = 'cw.sources.schemaconfig'
- __select__ = SourceHook.__select__ & is_instance('CWSourceSchemaConfig')
- events = ('after_add_entity', 'after_update_entity')
- def __call__(self):
- if self.event == 'after_add_entity' or (
- self.event == 'after_update_entity' and 'options' in self.entity.cw_edited):
- SourceMappingChangedOp.get_instance(self._cw).add_data(
- (self.entity, None) )
-
-class SourceMappingDeleteHook(SourceHook):
- __regid__ = 'cw.sources.delschemaconfig'
- __select__ = SourceHook.__select__ & hook.match_rtype('cw_for_source')
- events = ('before_delete_relation',)
- def __call__(self):
- SourceMappingChangedOp.get_instance(self._cw).add_data(
- (self._cw.entity_from_eid(self.eidfrom),
- self._cw.entity_from_eid(self.eidto).repo_source) )