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 <contact@nbenedek.me>
[sunil: Update docstrings, minor refactoring]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
nbenedek 2023-04-07 03:37:54 +02:00 committed by Sunil Mohan Adapa
parent f1d2139c2d
commit 30b0019865
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
3 changed files with 26 additions and 7 deletions

View File

@ -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."""

View File

@ -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': {

View File

@ -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)