1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
194 for eschema in self.cnx.repo.schema.entities(): |
194 for eschema in self.cnx.repo.schema.entities(): |
195 if not eschema.final: |
195 if not eschema.final: |
196 clear_cache(eschema, 'ordered_relations') |
196 clear_cache(eschema, 'ordered_relations') |
197 |
197 |
198 def postcommit_event(self): |
198 def postcommit_event(self): |
199 rebuildinfered = self.cnx.get_shared_data('rebuild-infered', True) |
|
200 repo = self.cnx.repo |
199 repo = self.cnx.repo |
201 # commit event should not raise error, while set_schema has chances to |
200 # commit event should not raise error, while set_schema has chances to |
202 # do so because it triggers full vreg reloading |
201 # do so because it triggers full vreg reloading |
203 try: |
202 try: |
204 if rebuildinfered: |
203 repo.schema.rebuild_infered_relations() |
205 repo.schema.rebuild_infered_relations() |
|
206 # trigger vreg reload |
204 # trigger vreg reload |
207 repo.set_schema(repo.schema) |
205 repo.set_schema(repo.schema) |
208 # CWUser class might have changed, update current session users |
206 # CWUser class might have changed, update current session users |
209 cwuser_cls = self.cnx.vreg['etypes'].etype_class('CWUser') |
207 cwuser_cls = self.cnx.vreg['etypes'].etype_class('CWUser') |
210 for session in repo._sessions.itervalues(): |
208 for session in repo._sessions.itervalues(): |
648 def precommit_event(self): |
646 def precommit_event(self): |
649 cnx = self.cnx |
647 cnx = self.cnx |
650 rdef = self.rdef |
648 rdef = self.rdef |
651 # in-place modification of in-memory schema first |
649 # in-place modification of in-memory schema first |
652 _set_modifiable_constraints(rdef) |
650 _set_modifiable_constraints(rdef) |
653 rdef.constraints.remove(self.oldcstr) |
651 if self.oldcstr in rdef.constraints: |
|
652 rdef.constraints.remove(self.oldcstr) |
|
653 else: |
|
654 self.critical('constraint %s for rdef %s was missing or already removed', |
|
655 self.oldcstr, rdef) |
654 # then update database: alter the physical schema on size/unique |
656 # then update database: alter the physical schema on size/unique |
655 # constraint changes |
657 # constraint changes |
656 syssource = cnx.repo.system_source |
658 syssource = cnx.repo.system_source |
657 cstrtype = self.oldcstr.type() |
659 cstrtype = self.oldcstr.type() |
658 if cstrtype == 'SizeConstraint': |
660 if cstrtype == 'SizeConstraint': |
1134 try: |
1136 try: |
1135 # KeyError, e.g. composite chain deletion |
1137 # KeyError, e.g. composite chain deletion |
1136 rdef = schema.schema_by_eid(entity.reverse_constrained_by[0].eid) |
1138 rdef = schema.schema_by_eid(entity.reverse_constrained_by[0].eid) |
1137 # IndexError |
1139 # IndexError |
1138 cstr = rdef.constraint_by_type(entity.type) |
1140 cstr = rdef.constraint_by_type(entity.type) |
1139 except (IndexError, KeyError): |
1141 except (KeyError, IndexError): |
1140 self._cw.critical('constraint type no more accessible') |
1142 self._cw.critical('constraint type no more accessible') |
1141 else: |
1143 else: |
1142 CWConstraintDelOp(self._cw, rdef=rdef, oldcstr=cstr) |
1144 CWConstraintDelOp(self._cw, rdef=rdef, oldcstr=cstr) |
1143 |
1145 |
1144 # unique_together constraints |
1146 # unique_together constraints |