server/checkintegrity.py
branchstable
changeset 7677 134613d3b353
parent 7473 a164fdf3de5d
child 7682 07b592a62be3
equal deleted inserted replaced
7670:6397a9051f65 7677:134613d3b353
    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()