214 rschema = values = entity = None # make pylint happy |
214 rschema = values = entity = None # make pylint happy |
215 |
215 |
216 def precommit_event(self): |
216 def precommit_event(self): |
217 session = self.session |
217 session = self.session |
218 rschema = self.rschema |
218 rschema = self.rschema |
219 if rschema.is_final() or not 'inlined' in self.values: |
219 if rschema.final or not 'inlined' in self.values: |
220 return # nothing to do |
220 return # nothing to do |
221 inlined = self.values['inlined'] |
221 inlined = self.values['inlined'] |
222 entity = self.entity |
222 entity = self.entity |
223 # check in-lining is necessary / possible |
223 # check in-lining is necessary / possible |
224 if not entity.inlined_changed(inlined): |
224 if not entity.inlined_changed(inlined): |
452 sysource = self.session.pool.source('system') |
452 sysource = self.session.pool.source('system') |
453 if self.values['indexed']: |
453 if self.values['indexed']: |
454 sysource.create_index(self.session, table, column) |
454 sysource.create_index(self.session, table, column) |
455 else: |
455 else: |
456 sysource.drop_index(self.session, table, column) |
456 sysource.drop_index(self.session, table, column) |
457 if 'cardinality' in self.values and self.rschema.is_final(): |
457 if 'cardinality' in self.values and self.rschema.final: |
458 adbh = self.session.pool.source('system').dbhelper |
458 adbh = self.session.pool.source('system').dbhelper |
459 if not adbh.alter_column_support: |
459 if not adbh.alter_column_support: |
460 # not supported (and NOT NULL not set by yams in that case, so |
460 # not supported (and NOT NULL not set by yams in that case, so |
461 # no worry) |
461 # no worry) |
462 return |
462 return |
814 def __call__(self): |
814 def __call__(self): |
815 # workflow cleanup |
815 # workflow cleanup |
816 self._cw.execute('DELETE Workflow X WHERE NOT X workflow_of Y') |
816 self._cw.execute('DELETE Workflow X WHERE NOT X workflow_of Y') |
817 |
817 |
818 |
818 |
|
819 <<<<<<< /home/syt/src/fcubicweb/cubicweb/hooks/syncschema.py |
819 class AfterAddCWETypeHook(DelCWETypeHook): |
820 class AfterAddCWETypeHook(DelCWETypeHook): |
|
821 ======= |
|
822 def after_del_relation_type(session, rdefeid, rtype, rteid): |
|
823 |
|
824 |
|
825 # addition hooks ############################################################### |
|
826 |
|
827 def before_add_eetype(session, entity): |
|
828 """before adding a CWEType entity: |
|
829 * check that we are not using an existing entity type, |
|
830 """ |
|
831 name = entity['name'] |
|
832 schema = session.schema |
|
833 if name in schema and schema[name].eid is not None: |
|
834 raise RepositoryError('an entity type %s already exists' % name) |
|
835 |
|
836 def after_add_eetype(session, entity): |
|
837 >>>>>>> /tmp/schemahooks.py~other.2drHhu |
820 """after adding a CWEType entity: |
838 """after adding a CWEType entity: |
821 * create the necessary table |
839 * create the necessary table |
822 * set creation_date and modification_date by creating the necessary |
840 * set creation_date and modification_date by creating the necessary |
823 CWAttribute entities |
841 CWAttribute entities |
824 * add owned_by relation by creating the necessary CWRelation entity |
842 * add owned_by relation by creating the necessary CWRelation entity |
972 events = ('after_delete_relation',) |
990 events = ('after_delete_relation',) |
973 |
991 |
974 def __call__(self): |
992 def __call__(self): |
975 session = self._cw |
993 session = self._cw |
976 subjschema, rschema, objschema = session.vreg.schema.schema_by_eid(self.eidfrom) |
994 subjschema, rschema, objschema = session.vreg.schema.schema_by_eid(self.eidfrom) |
|
995 subjschema, rschema, objschema = session.schema.schema_by_eid(rdefeid) |
977 pendings = session.transaction_data.get('pendingeids', ()) |
996 pendings = session.transaction_data.get('pendingeids', ()) |
978 pendingrdefs = session.transaction_data.setdefault('pendingrdefs', set()) |
997 pendingrdefs = session.transaction_data.setdefault('pendingrdefs', set()) |
979 # first delete existing relation if necessary |
998 # first delete existing relation if necessary |
980 if rschema.is_final(): |
999 if rschema.final: |
981 rdeftype = 'CWAttribute' |
1000 rdeftype = 'CWAttribute' |
982 pendingrdefs.add((subjschema, rschema)) |
1001 pendingrdefs.add((subjschema, rschema)) |
983 else: |
1002 else: |
984 rdeftype = 'CWRelation' |
1003 rdeftype = 'CWRelation' |
985 pendingrdefs.add((subjschema, rschema, objschema)) |
1004 pendingrdefs.add((subjschema, rschema, objschema)) |
986 if not (subjschema.eid in pendings or objschema.eid in pendings): |
1005 if not (subjschema.eid in pendings or objschema.eid in pendings): |
987 session.execute('DELETE X %s Y WHERE X is %s, Y is %s' |
1006 session.execute('DELETE X %s Y WHERE X is %s, Y is %s' |
988 % (rschema, subjschema, objschema)) |
1007 % (rschema, subjschema, objschema)) |
989 execute = session.unsafe_execute |
1008 execute = session.unsafe_execute |
990 rteid = self.eidto |
|
991 rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R,' |
1009 rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R,' |
992 'R eid %%(x)s' % rdeftype, {'x': rteid}) |
1010 'R eid %%(x)s' % rdeftype, {'x': rteid}) |
993 lastrel = rset[0][0] == 0 |
1011 lastrel = rset[0][0] == 0 |
994 # we have to update physical schema systematically for final and inlined |
1012 # we have to update physical schema systematically for final and inlined |
995 # relations, but only if it's the last instance for this relation type |
1013 # relations, but only if it's the last instance for this relation type |
996 # for other relations |
1014 # for other relations |
997 |
1015 |
998 if (rschema.is_final() or rschema.inlined): |
1016 if (rschema.final or rschema.inlined): |
999 rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R, ' |
1017 rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R, ' |
1000 'R eid %%(x)s, X from_entity E, E name %%(name)s' |
1018 'R eid %%(x)s, X from_entity E, E name %%(name)s' |
1001 % rdeftype, {'x': rteid, 'name': str(subjschema)}) |
1019 % rdeftype, {'x': rteid, 'name': str(subjschema)}) |
1002 if rset[0][0] == 0 and not subjschema.eid in pendings: |
1020 if rset[0][0] == 0 and not subjschema.eid in pendings: |
1003 ptypes = session.transaction_data.setdefault('pendingrtypes', set()) |
1021 ptypes = session.transaction_data.setdefault('pendingrtypes', set()) |