server/checkintegrity.py
branchtls-sprint
changeset 1802 d628defebc17
parent 1398 5fe84a5f7035
child 1977 606923dff11b
equal deleted inserted replaced
1801:672acc730ce5 1802:d628defebc17
    59                 _done.add(targeteschema)
    59                 _done.add(targeteschema)
    60                 for container in etype_fti_containers(targeteschema, _done):
    60                 for container in etype_fti_containers(targeteschema, _done):
    61                     yield container
    61                     yield container
    62     else:
    62     else:
    63         yield eschema
    63         yield eschema
    64     
    64 
    65 def reindex_entities(schema, session):
    65 def reindex_entities(schema, session):
    66     """reindex all entities in the repository"""
    66     """reindex all entities in the repository"""
    67     # deactivate modification_date hook since we don't want them
    67     # deactivate modification_date hook since we don't want them
    68     # to be updated due to the reindexation
    68     # to be updated due to the reindexation
    69     from cubicweb.server.hooks import (setmtime_before_update_entity,
    69     from cubicweb.server.hooks import (setmtime_before_update_entity,
   101             FTIndexEntityOp(session, entity=entity)
   101             FTIndexEntityOp(session, entity=entity)
   102         pb.update()
   102         pb.update()
   103     # restore Entity.check
   103     # restore Entity.check
   104     Entity.check = _check
   104     Entity.check = _check
   105 
   105 
   106     
   106 
   107 def check_schema(schema, session, eids, fix=1):
   107 def check_schema(schema, session, eids, fix=1):
   108     """check serialized schema"""
   108     """check serialized schema"""
   109     print 'Checking serialized schema'
   109     print 'Checking serialized schema'
   110     unique_constraints = ('SizeConstraint', 'FormatConstraint',
   110     unique_constraints = ('SizeConstraint', 'FormatConstraint',
   111                           'VocabularyConstraint', 'RQLConstraint',
   111                           'VocabularyConstraint', 'RQLConstraint',
   120         if cstrname in unique_constraints:
   120         if cstrname in unique_constraints:
   121             print "ERROR: got %s %r constraints on relation %s.%s" % (
   121             print "ERROR: got %s %r constraints on relation %s.%s" % (
   122                 count, cstrname, en, rn)
   122                 count, cstrname, en, rn)
   123 
   123 
   124 
   124 
   125     
   125 
   126 def check_text_index(schema, session, eids, fix=1):
   126 def check_text_index(schema, session, eids, fix=1):
   127     """check all entities registered in the text index"""
   127     """check all entities registered in the text index"""
   128     print 'Checking text index'
   128     print 'Checking text index'
   129     cursor = session.system_sql('SELECT uid FROM appears;')
   129     cursor = session.system_sql('SELECT uid FROM appears;')
   130     for row in cursor.fetchall():
   130     for row in cursor.fetchall():
   170                 if fix:
   170                 if fix:
   171                     session.system_sql('DELETE FROM %s WHERE %s=%s;' % (table, column, eid))
   171                     session.system_sql('DELETE FROM %s WHERE %s=%s;' % (table, column, eid))
   172                     print >> sys.stderr, ' [FIXED]'
   172                     print >> sys.stderr, ' [FIXED]'
   173                 else:
   173                 else:
   174                     print >> sys.stderr
   174                     print >> sys.stderr
   175                 
   175 
   176             
   176 
   177 def bad_related_msg(rtype, target, eid, fix):
   177 def bad_related_msg(rtype, target, eid, fix):
   178     msg = '  A relation %s with %s eid %s exists but no such entity in sources'
   178     msg = '  A relation %s with %s eid %s exists but no such entity in sources'
   179     print >> sys.stderr, msg % (rtype, target, eid),
   179     print >> sys.stderr, msg % (rtype, target, eid),
   180     if fix:
   180     if fix:
   181         print >> sys.stderr, ' [FIXED]'
   181         print >> sys.stderr, ' [FIXED]'
   182     else:
   182     else:
   183         print >> sys.stderr
   183         print >> sys.stderr
   184     
   184 
   185     
   185 
   186 def check_relations(schema, session, eids, fix=1):
   186 def check_relations(schema, session, eids, fix=1):
   187     """check all relations registered in the repo system table"""
   187     """check all relations registered in the repo system table"""
   188     print 'Checking relations'
   188     print 'Checking relations'
   189     for rschema in schema.relations():
   189     for rschema in schema.relations():
   190         if rschema.is_final():
   190         if rschema.is_final():