35 |
35 |
36 from cubicweb import AuthenticationError, ExecutionError, ConfigurationError, SourceException |
36 from cubicweb import AuthenticationError, ExecutionError, ConfigurationError, SourceException |
37 from cubicweb.toolsutils import Command, CommandHandler, underline_title |
37 from cubicweb.toolsutils import Command, CommandHandler, underline_title |
38 from cubicweb.cwctl import CWCTL, check_options_consistency, ConfigureInstanceCommand |
38 from cubicweb.cwctl import CWCTL, check_options_consistency, ConfigureInstanceCommand |
39 from cubicweb.server import SOURCE_TYPES |
39 from cubicweb.server import SOURCE_TYPES |
|
40 from cubicweb.server import checkintegrity |
40 from cubicweb.server.serverconfig import ( |
41 from cubicweb.server.serverconfig import ( |
41 USER_OPTIONS, ServerConfiguration, SourceConfiguration, |
42 USER_OPTIONS, ServerConfiguration, SourceConfiguration, |
42 ask_source_config, generate_source_config) |
43 ask_source_config, generate_source_config) |
43 |
44 |
44 |
45 |
900 arguments = '<instance>' |
901 arguments = '<instance>' |
901 min_args = max_args = 1 |
902 min_args = max_args = 1 |
902 options = ( |
903 options = ( |
903 ('checks', |
904 ('checks', |
904 {'short': 'c', 'type': 'csv', 'metavar': '<check list>', |
905 {'short': 'c', 'type': 'csv', 'metavar': '<check list>', |
905 'default': ('entities', 'relations', |
906 'default': sorted(checkintegrity._CHECKERS), |
906 'mandatory_relations', 'mandatory_attributes', |
907 'help': 'Comma separated list of check to run. By default run all checks.'} |
907 'metadata', 'schema', 'text_index'), |
|
908 'help': 'Comma separated list of check to run. By default run all \ |
|
909 checks, i.e. entities, relations, mandatory_relations, mandatory_attributes, \ |
|
910 metadata, text_index and schema.'} |
|
911 ), |
908 ), |
912 |
909 |
913 ('autofix', |
910 ('autofix', |
914 {'short': 'a', 'type': 'yn', 'metavar': '<yes or no>', |
911 {'short': 'a', 'type': 'yn', 'metavar': '<yes or no>', |
915 'default': False, |
912 'default': False, |
928 'help': 'don\'t check instance is up to date.'} |
925 'help': 'don\'t check instance is up to date.'} |
929 ), |
926 ), |
930 ) |
927 ) |
931 |
928 |
932 def run(self, args): |
929 def run(self, args): |
933 from cubicweb.server.checkintegrity import check |
|
934 appid = args[0] |
930 appid = args[0] |
935 config = ServerConfiguration.config_for(appid) |
931 config = ServerConfiguration.config_for(appid) |
936 config.repairing = self.config.force |
932 config.repairing = self.config.force |
937 repo, _cnx = repo_cnx(config) |
933 repo, _cnx = repo_cnx(config) |
938 with repo.internal_cnx() as cnx: |
934 with repo.internal_cnx() as cnx: |
939 check(repo, cnx, |
935 checkintegrity.check(repo, cnx, |
940 self.config.checks, |
936 self.config.checks, |
941 self.config.reindex, |
937 self.config.reindex, |
942 self.config.autofix) |
938 self.config.autofix) |
943 |
939 |
944 |
940 |
951 arguments = '<instance>' |
947 arguments = '<instance>' |
952 name = 'db-check-index' |
948 name = 'db-check-index' |
953 min_args = 1 |
949 min_args = 1 |
954 |
950 |
955 def run(self, args): |
951 def run(self, args): |
956 from cubicweb.server.checkintegrity import check_indexes |
|
957 config = ServerConfiguration.config_for(args[0]) |
952 config = ServerConfiguration.config_for(args[0]) |
958 repo, cnx = repo_cnx(config) |
953 repo, cnx = repo_cnx(config) |
959 with cnx: |
954 with cnx: |
960 status = check_indexes(cnx) |
955 status = checkintegrity.check_indexes(cnx) |
961 sys.exit(status) |
956 sys.exit(status) |
962 |
957 |
963 |
958 |
964 class RebuildFTICommand(Command): |
959 class RebuildFTICommand(Command): |
965 """Rebuild the full-text index of the system database of an instance. |
960 """Rebuild the full-text index of the system database of an instance. |