From 50b6fd4093e74a7378e83c2ca976590662343370 Mon Sep 17 00:00:00 2001 From: nbenedek Date: Sun, 9 Apr 2023 13:47:23 +0200 Subject: [PATCH] mediawiki: Completely uninstall app Tests: 1. Install Mediawiki, set the admin password and edit the main page 2. Reinstall app: password and wiki content are set back to default 3. After the reinstall, I test uploading an image and backing up/restoring the app Signed-off-by: nbenedek [sunil: Update docstrings, make uninstall fail-safe] [sunil: Fix functional tests by setting up after re-install] [sunil: Fix functional test by account for change in delete button ID] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/modules/mediawiki/__init__.py | 7 ++++++- plinth/modules/mediawiki/privileged.py | 12 ++++++++++-- plinth/modules/mediawiki/tests/test_functional.py | 10 ++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/plinth/modules/mediawiki/__init__.py b/plinth/modules/mediawiki/__init__.py index e0534c9c1..c1d1b3887 100644 --- a/plinth/modules/mediawiki/__init__.py +++ b/plinth/modules/mediawiki/__init__.py @@ -14,7 +14,7 @@ from plinth.modules.backups.components import BackupRestore from plinth.modules.firewall.components import Firewall from plinth.package import Packages -from . import manifest, privileged, forms +from . import forms, manifest, privileged _description = [ _('MediaWiki is the wiki engine that powers Wikipedia and other WikiMedia ' @@ -97,6 +97,11 @@ class MediaWikiApp(app_module.App): privileged.update() self.enable() + def uninstall(self): + """De-configure and uninstall the app.""" + super().uninstall() + privileged.uninstall() + class Shortcut(frontpage.Shortcut): """Frontpage shortcut for only logged users when in private mode.""" diff --git a/plinth/modules/mediawiki/privileged.py b/plinth/modules/mediawiki/privileged.py index f78eff76c..7b319e17c 100644 --- a/plinth/modules/mediawiki/privileged.py +++ b/plinth/modules/mediawiki/privileged.py @@ -2,6 +2,8 @@ """Configure MediaWiki.""" import os +import pathlib +import shutil import subprocess import tempfile from typing import Optional @@ -218,5 +220,11 @@ def set_default_language(language: str): # languages. rebuild_messages_script = os.path.join(MAINTENANCE_SCRIPTS_DIR, 'rebuildmessages.php') - subprocess.check_call([ - _get_php_command(), rebuild_messages_script]) + subprocess.check_call([_get_php_command(), rebuild_messages_script]) + + +@privileged +def uninstall(): + """Remove Mediawiki's database and local config file.""" + shutil.rmtree('/var/lib/mediawiki-db', ignore_errors=True) + pathlib.Path(LOCAL_SETTINGS_CONF).unlink(missing_ok=True) diff --git a/plinth/modules/mediawiki/tests/test_functional.py b/plinth/modules/mediawiki/tests/test_functional.py index 19a6a5523..b82afdc2e 100644 --- a/plinth/modules/mediawiki/tests/test_functional.py +++ b/plinth/modules/mediawiki/tests/test_functional.py @@ -100,6 +100,12 @@ class TestMediawikiApp(functional.BaseAppTests): assert _image_exists(session_browser, 'Noise.png') _verify_create_account_link(session_browser) + def test_uninstall(self, session_browser): + """Setup the app configuration again after a re-install.""" + super().test_uninstall(session_browser) + _set_domain(session_browser) + _set_admin_password(session_browser, 'whatever123') + def _enable_public_registrations(browser): """Enable public registrations in MediaWiki.""" @@ -213,6 +219,10 @@ def _delete_image(browser, username, password, image): path = f'/mediawiki/index.php?title=File:{image}&action=delete' functional.visit(browser, path) delete_button = browser.find_by_id('mw-filedelete-submit') + if not delete_button: + # On bookworm and higher + delete_button = browser.find_by_id('wpConfirmB') + functional.submit(browser, element=delete_button)