server/checkintegrity.py
changeset 9797 4e640ab62f51
parent 9578 68049d53426c
child 10365 21461f80f348
equal deleted inserted replaced
9796:2d1e488f6f71 9797:4e640ab62f51
     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
   393     """check integrity of instance's repository,
   393     """check integrity of instance's repository,
   394     using given user and password to locally connect to the repository
   394     using given user and password to locally connect to the repository
   395     (no running cubicweb server needed)
   395     (no running cubicweb server needed)
   396     """
   396     """
   397     # yo, launch checks
   397     # yo, launch checks
   398     srvcnx = cnx._cnx
       
   399     if checks:
   398     if checks:
   400         eids_cache = {}
   399         eids_cache = {}
   401         with srvcnx.security_enabled(read=False, write=False): # ensure no read security
   400         with cnx.security_enabled(read=False, write=False): # ensure no read security
   402             for check in checks:
   401             for check in checks:
   403                 check_func = globals()['check_%s' % check]
   402                 check_func = globals()['check_%s' % check]
   404                 with srvcnx.ensure_cnx_set:
   403                 with cnx.ensure_cnx_set:
   405                     check_func(repo.schema, srvcnx, eids_cache, fix=fix)
   404                     check_func(repo.schema, cnx, eids_cache, fix=fix)
   406         if fix:
   405         if fix:
   407             srvcnx.commit()
   406             cnx.commit()
   408         else:
   407         else:
   409             print
   408             print
   410         if not fix:
   409         if not fix:
   411             print 'WARNING: Diagnostic run, nothing has been corrected'
   410             print 'WARNING: Diagnostic run, nothing has been corrected'
   412     if reindex:
   411     if reindex:
   413         srvcnx.rollback()
   412         cnx.rollback()
   414         with srvcnx.ensure_cnx_set:
   413         with cnx.ensure_cnx_set:
   415             reindex_entities(repo.schema, srvcnx, withpb=withpb)
   414             reindex_entities(repo.schema, cnx, withpb=withpb)
   416         srvcnx.commit()
   415         cnx.commit()