diff --git a/docs/admin/backup.rst b/docs/admin/backup.rst index 2ba0186bf..b8799a3a4 100644 --- a/docs/admin/backup.rst +++ b/docs/admin/backup.rst @@ -52,6 +52,4 @@ To load the backup file into your empty wiki, run:: moin load --file backup.moin -Then build an index of the loaded data:: - - moin index-build +The index is removed and automatically recreated by the load command. diff --git a/docs/admin/index.rst b/docs/admin/index.rst index 54dd8932e..d5401a010 100644 --- a/docs/admin/index.rst +++ b/docs/admin/index.rst @@ -114,6 +114,7 @@ If your wiki has data and is shut down If index needs a rebuild for some reason, e.g. index lost, index damaged, incompatible upgrade, etc., use:: + moin index-destroy moin index-create moin index-build # can take a while... diff --git a/src/moin/cli/_tests/test_serialization.py b/src/moin/cli/_tests/test_serialization.py index 7f1de5863..a58511278 100644 --- a/src/moin/cli/_tests/test_serialization.py +++ b/src/moin/cli/_tests/test_serialization.py @@ -1,4 +1,5 @@ # Copyright: 2023 MoinMoin project +# Copyright: 2024 MoinMoin:UlrichB # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. """ @@ -28,8 +29,7 @@ def load(restore_dir, backup_name, artifact_dir, args=None): try: for command in (['moin', 'create-instance'], ['moin', 'index-create'], - ['moin', 'load', '-f', getBackupPath(backup_name)] + (args if args else []), - ['moin', 'index-build']): + ['moin', 'load', '-f', getBackupPath(backup_name)] + (args if args else []),): p = run(command) assert_p_succcess(p) finally: diff --git a/src/moin/cli/_util.py b/src/moin/cli/_util.py index 805b3159e..d4d6bd133 100644 --- a/src/moin/cli/_util.py +++ b/src/moin/cli/_util.py @@ -1,4 +1,5 @@ # Copyright: 2023 MoinMoin project +# Copyright: 2024 MoinMoin:UlrichB # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. """ @@ -32,3 +33,19 @@ def get_backends(backends: Optional[str], all_backends: bool) -> Set[Backend]: else: logging.warning('no backends specified') return set() + + +def drop_and_recreate_index(indexer): + """Drop index and recreate, rebuild and optimize + :param indexer: IndexingMiddleware object + """ + indexer.close() + indexer.destroy() + logging.debug("Create index") + indexer.create() + logging.debug("Rebuild index") + indexer.rebuild() + logging.debug("Optimize index") + indexer.optimize_index() + indexer.open() + logging.info("Rebuild index finished") diff --git a/src/moin/cli/maint/serialization.py b/src/moin/cli/maint/serialization.py index 1f024ba92..be3931348 100644 --- a/src/moin/cli/maint/serialization.py +++ b/src/moin/cli/maint/serialization.py @@ -1,5 +1,6 @@ # Copyright: 2011 MoinMoin:ThomasWaldmann # Copyright: 2023 MoinMoin project +# Copyright: 2024 MoinMoin:UlrichB # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. """ @@ -14,7 +15,7 @@ from moin.storage.middleware.serialization import serialize, deserialize from moin.app import create_app -from moin.cli._util import get_backends +from moin.cli._util import get_backends, drop_and_recreate_index from moin import log logging = log.getLogger(__name__) @@ -82,4 +83,6 @@ def Deserialize(file=None, new_ns=None, old_ns=None, kill_ns=None): logging.info("Load backup started") with open_file(file, "rb") as f: deserialize(f, app.storage.backend, new_ns=new_ns, old_ns=old_ns, kill_ns=kill_ns) - logging.info("Load Backup finished. You need to run index-build now.") + logging.info("Rebuilding the index ...") + drop_and_recreate_index(app.storage) + logging.info("Load Backup finished.") diff --git a/src/moin/cli/migration/moin19/import19.py b/src/moin/cli/migration/moin19/import19.py index c0347df27..22df1f11d 100644 --- a/src/moin/cli/migration/moin19/import19.py +++ b/src/moin/cli/migration/moin19/import19.py @@ -29,6 +29,7 @@ from .macros import PageList # noqa from moin.app import create_app +from moin.cli._util import drop_and_recreate_index from moin.constants.keys import * # noqa from moin.constants.contenttypes import CONTENTTYPE_USER, CHARSET19, CONTENTTYPE_MARKUP_OUT from moin.constants.itemtypes import ITEMTYPE_DEFAULT @@ -241,15 +242,7 @@ def ImportMoin19(data_dir=None, markup_out=None, namespace=None): backend.store(meta, out) logging.info("PHASE4: Rebuilding the index ...") - indexer.close() - indexer.destroy() - logging.debug("Create index") - indexer.create() - logging.debug("Rebuild index") - indexer.rebuild() - logging.debug("Optimize index") - indexer.optimize_index() - indexer.open() + drop_and_recreate_index(app.storage) logging.info("Finished conversion!") if hasattr(conv_out, 'unknown_macro_list'): diff --git a/src/moin/converters/_util.py b/src/moin/converters/_util.py index 5808a5fdb..e05a01487 100644 --- a/src/moin/converters/_util.py +++ b/src/moin/converters/_util.py @@ -1,4 +1,5 @@ # Copyright: 2011 MoinMoin:ThomasWaldmann +# Copyright: 2024 MoinMoin:UlrichB # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. """ @@ -120,7 +121,7 @@ def add_lineno(self, elem): """ Add a custom attribute (data-lineno=nn) that will be used by Javascript to scroll edit textarea. """ - if flaskg and flaskg.add_lineno_attr: + if flaskg and getattr(flaskg, 'add_lineno_attr', False): if self.last_lineno != self.iter_content.lineno: # avoid adding same lineno to parent and multiple children or grand-children elem.attrib[html.data_lineno] = self.iter_content.lineno diff --git a/src/moin/converters/docbook_in.py b/src/moin/converters/docbook_in.py index a157ab180..05c3286c9 100644 --- a/src/moin/converters/docbook_in.py +++ b/src/moin/converters/docbook_in.py @@ -1,4 +1,5 @@ # Copyright: 2010 MoinMoin:ValentinJaniaut +# Copyright: 2024 MoinMoin:UlrichB # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. """ @@ -57,7 +58,7 @@ class XMLParser(ET.XMLParser): """ def _start_list(self, tag, attrib_in): elem = super(XMLParser, self)._start_list(tag, attrib_in) - if flaskg and flaskg.add_lineno_attr: + if flaskg and getattr(flaskg, 'add_lineno_attr', False): elem.attrib[html.data_lineno] = self._parser.CurrentLineNumber return elem diff --git a/src/moin/converters/markdown_in.py b/src/moin/converters/markdown_in.py index ddb79ecbf..9474e9546 100644 --- a/src/moin/converters/markdown_in.py +++ b/src/moin/converters/markdown_in.py @@ -1,5 +1,6 @@ # Copyright: 2008-2010 MoinMoin:BastianBlank # Copyright: 2012 MoinMoin:AndreasKloeckner +# Copyright: 2024 MoinMoin:UlrichB # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. """ @@ -599,7 +600,7 @@ def __call__(self, data, contenttype=None, arguments=None): # }}} end Markdown 3.0.0 core.py convert method - add_lineno = bool(flaskg and flaskg.add_lineno_attr) + add_lineno = bool(flaskg and getattr(flaskg, 'add_lineno_attr', False)) # run markdown post processors and convert from ElementTree to an EmeraldTree object converted = self.do_children(root, add_lineno=add_lineno) diff --git a/src/moin/converters/rst_in.py b/src/moin/converters/rst_in.py index 1ab84d6a7..271084c3d 100644 --- a/src/moin/converters/rst_in.py +++ b/src/moin/converters/rst_in.py @@ -2,6 +2,7 @@ # Copyright: 2004 Matthew Gilbert # Copyright: 2004 Alexander Schremmer # Copyright: 2010 MoinMoin:DmitryAndreev +# Copyright: 2024 MoinMoin:UlrichB # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. """ @@ -92,7 +93,7 @@ def unknown_departure(self, node): pass def open_moin_page_node(self, mointree_element): - if flaskg and flaskg.add_lineno_attr: + if flaskg and getattr(flaskg, 'add_lineno_attr', False): # add data-lineno attribute for auto-scrolling edit textarea if self.last_lineno < self.current_lineno: mointree_element.attrib[html.data_lineno] = self.current_lineno