hooks/syncschema.py
changeset 3777 3ef8cdb5fb1c
parent 3774 1eca47d59fd9
parent 3726 986839199f23
child 3890 d7a270f50f54
equal deleted inserted replaced
3739:817e96eeac5c 3777:3ef8cdb5fb1c
    13 __docformat__ = "restructuredtext en"
    13 __docformat__ = "restructuredtext en"
    14 
    14 
    15 from yams.schema import BASE_TYPES
    15 from yams.schema import BASE_TYPES
    16 from yams.buildobjs import EntityType, RelationType, RelationDefinition
    16 from yams.buildobjs import EntityType, RelationType, RelationDefinition
    17 from yams.schema2sql import eschema2sql, rschema2sql, type_from_constraints
    17 from yams.schema2sql import eschema2sql, rschema2sql, type_from_constraints
       
    18 
       
    19 from logilab.common.decorators import clear_cache
    18 
    20 
    19 from cubicweb import ValidationError, RepositoryError
    21 from cubicweb import ValidationError, RepositoryError
    20 from cubicweb.selectors import entity_implements
    22 from cubicweb.selectors import entity_implements
    21 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, CONSTRAINTS
    23 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, CONSTRAINTS
    22 from cubicweb.server import hook, schemaserial as ss
    24 from cubicweb.server import hook, schemaserial as ss
   142     """
   144     """
   143 
   145 
   144     def __init__(self, session):
   146     def __init__(self, session):
   145         hook.SingleLastOperation.__init__(self, session)
   147         hook.SingleLastOperation.__init__(self, session)
   146 
   148 
       
   149     def precommit_event(self):
       
   150         for eschema in self.repo.schema.entities():
       
   151             if not eschema.final:
       
   152                 clear_cache(eschema, 'ordered_relations')
       
   153 
   147     def commit_event(self):
   154     def commit_event(self):
   148         rebuildinfered = self.session.data.get('rebuild-infered', True)
   155         rebuildinfered = self.session.data.get('rebuild-infered', True)
   149         repo = self.session.repo
   156         repo = self.session.repo
   150         repo.set_schema(repo.schema, rebuildinfered=rebuildinfered)
   157         repo.set_schema(repo.schema, rebuildinfered=rebuildinfered)
       
   158 
       
   159     def rollback_event(self):
       
   160         self.precommit_event()
   151 
   161 
   152 
   162 
   153 class MemSchemaOperation(hook.Operation):
   163 class MemSchemaOperation(hook.Operation):
   154     """base class for schema operations"""
   164     """base class for schema operations"""
   155     def __init__(self, session, kobj=None, **kwargs):
   165     def __init__(self, session, kobj=None, **kwargs):