From 30b00198652e34a2bdb18f253a6b159340be9353 Mon Sep 17 00:00:00 2001 From: nbenedek Date: Fri, 7 Apr 2023 03:37:54 +0200 Subject: [PATCH] wordpress: Completely uninstall app * When app is uninstalled, remove config files and drop the database * Declare PUBLIC_ACCESS_FILE with pathlib.Path * Add public access file to the backup manifest Tests: 1. Install and setup wordpress 2. Reinstall the app and confirm that the initial setup page is shown to the user 3. Functional tests passed Signed-off-by: nbenedek [sunil: Update docstrings, minor refactoring] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/modules/wordpress/__init__.py | 5 +++++ plinth/modules/wordpress/manifest.py | 3 ++- plinth/modules/wordpress/privileged.py | 25 +++++++++++++++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/plinth/modules/wordpress/__init__.py b/plinth/modules/wordpress/__init__.py index f63bdd238..62571537b 100644 --- a/plinth/modules/wordpress/__init__.py +++ b/plinth/modules/wordpress/__init__.py @@ -111,6 +111,11 @@ class WordPressApp(app_module.App): # Apply changes to Apache configuration from v2 to v3. service_privileged.reload('apache2') + def uninstall(self): + """De-configure and uninstall the app.""" + super().uninstall() + privileged.uninstall() + class WordPressBackupRestore(BackupRestore): """Component to backup/restore WordPress.""" diff --git a/plinth/modules/wordpress/manifest.py b/plinth/modules/wordpress/manifest.py index c46899e83..51199ce53 100644 --- a/plinth/modules/wordpress/manifest.py +++ b/plinth/modules/wordpress/manifest.py @@ -12,7 +12,8 @@ clients = [{ backup = { 'data': { - 'files': ['/var/lib/plinth/backups-data/wordpress-database.sql'], + 'files': ['/var/lib/plinth/backups-data/wordpress-database.sql', + '/etc/wordpress/is_public'], 'directories': ['/var/lib/wordpress/'] }, 'secrets': { diff --git a/plinth/modules/wordpress/privileged.py b/plinth/modules/wordpress/privileged.py index 28ec93112..73a74adbe 100644 --- a/plinth/modules/wordpress/privileged.py +++ b/plinth/modules/wordpress/privileged.py @@ -13,8 +13,7 @@ import augeas from plinth import action_utils from plinth.actions import privileged -PUBLIC_ACCESS_FILE = '/etc/wordpress/is_public' - +_public_access_file = pathlib.Path('/etc/wordpress/is_public') _config_file_path = pathlib.Path('/etc/wordpress/config-default.php') _static_config_file_path = pathlib.Path('/etc/wordpress/freedombox-static.php') _db_file_path = pathlib.Path('/etc/wordpress/database.php') @@ -127,18 +126,17 @@ def _upgrade_config_file(): @privileged def set_public(enable: bool): """Allow/disallow public access.""" - public_access_file = pathlib.Path(PUBLIC_ACCESS_FILE) if enable: - public_access_file.touch() + _public_access_file.touch() else: - public_access_file.unlink(missing_ok=True) + _public_access_file.unlink(missing_ok=True) action_utils.service_reload('apache2') def is_public() -> bool: """Return whether public access is enabled.""" - return pathlib.Path(PUBLIC_ACCESS_FILE).exists() + return _public_access_file.exists() @privileged @@ -177,3 +175,18 @@ def _load_augeas(): aug.load() return aug + + +@privileged +def uninstall(): + """Remove config files and drop database.""" + _drop_database() + for file_ in [_public_access_file, _config_file_path, _db_file_path]: + file_.unlink(missing_ok=True) + + +def _drop_database(): + """Drop the mysql database that was created during install.""" + query = f'''DROP DATABASE {DB_NAME};''' + subprocess.run(['mysql', '--user', 'root'], input=query.encode(), + check=True)