server/checkintegrity.py
changeset 7398 26695dd703d8
parent 7040 9b1f9bc74f5d
child 7473 a164fdf3de5d
equal deleted inserted replaced
7397:6a9e66d788b3 7398:26695dd703d8
    99 def reindex_entities(schema, session, withpb=True, etypes=None):
    99 def reindex_entities(schema, session, withpb=True, etypes=None):
   100     """reindex all entities in the repository"""
   100     """reindex all entities in the repository"""
   101     # deactivate modification_date hook since we don't want them
   101     # deactivate modification_date hook since we don't want them
   102     # to be updated due to the reindexation
   102     # to be updated due to the reindexation
   103     repo = session.repo
   103     repo = session.repo
   104     cursor = session.pool['system']
   104     cursor = session.cnxset['system']
   105     dbhelper = session.repo.system_source.dbhelper
   105     dbhelper = session.repo.system_source.dbhelper
   106     if not dbhelper.has_fti_table(cursor):
   106     if not dbhelper.has_fti_table(cursor):
   107         print 'no text index table'
   107         print 'no text index table'
   108         dbhelper.init_fti(cursor)
   108         dbhelper.init_fti(cursor)
   109     repo.system_source.do_fti = True  # ensure full-text indexation is activated
   109     repo.system_source.do_fti = True  # ensure full-text indexation is activated
   354 def check(repo, cnx, checks, reindex, fix, withpb=True):
   354 def check(repo, cnx, checks, reindex, fix, withpb=True):
   355     """check integrity of instance's repository,
   355     """check integrity of instance's repository,
   356     using given user and password to locally connect to the repository
   356     using given user and password to locally connect to the repository
   357     (no running cubicweb server needed)
   357     (no running cubicweb server needed)
   358     """
   358     """
   359     session = repo._get_session(cnx.sessionid, setpool=True)
   359     session = repo._get_session(cnx.sessionid, setcnxset=True)
   360     # yo, launch checks
   360     # yo, launch checks
   361     if checks:
   361     if checks:
   362         eids_cache = {}
   362         eids_cache = {}
   363         with security_enabled(session, read=False): # ensure no read security
   363         with security_enabled(session, read=False): # ensure no read security
   364             for check in checks:
   364             for check in checks:
   370             print
   370             print
   371         if not fix:
   371         if not fix:
   372             print 'WARNING: Diagnostic run, nothing has been corrected'
   372             print 'WARNING: Diagnostic run, nothing has been corrected'
   373     if reindex:
   373     if reindex:
   374         cnx.rollback()
   374         cnx.rollback()
   375         session.set_pool()
   375         session.set_cnxset()
   376         reindex_entities(repo.schema, session, withpb=withpb)
   376         reindex_entities(repo.schema, session, withpb=withpb)
   377         cnx.commit()
   377         cnx.commit()