mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
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:
parent
f1d2139c2d
commit
30b0019865
@ -111,6 +111,11 @@ class WordPressApp(app_module.App):
|
|||||||
# Apply changes to Apache configuration from v2 to v3.
|
# Apply changes to Apache configuration from v2 to v3.
|
||||||
service_privileged.reload('apache2')
|
service_privileged.reload('apache2')
|
||||||
|
|
||||||
|
def uninstall(self):
|
||||||
|
"""De-configure and uninstall the app."""
|
||||||
|
super().uninstall()
|
||||||
|
privileged.uninstall()
|
||||||
|
|
||||||
|
|
||||||
class WordPressBackupRestore(BackupRestore):
|
class WordPressBackupRestore(BackupRestore):
|
||||||
"""Component to backup/restore WordPress."""
|
"""Component to backup/restore WordPress."""
|
||||||
|
|||||||
@ -12,7 +12,8 @@ clients = [{
|
|||||||
|
|
||||||
backup = {
|
backup = {
|
||||||
'data': {
|
'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/']
|
'directories': ['/var/lib/wordpress/']
|
||||||
},
|
},
|
||||||
'secrets': {
|
'secrets': {
|
||||||
|
|||||||
@ -13,8 +13,7 @@ import augeas
|
|||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth.actions import privileged
|
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')
|
_config_file_path = pathlib.Path('/etc/wordpress/config-default.php')
|
||||||
_static_config_file_path = pathlib.Path('/etc/wordpress/freedombox-static.php')
|
_static_config_file_path = pathlib.Path('/etc/wordpress/freedombox-static.php')
|
||||||
_db_file_path = pathlib.Path('/etc/wordpress/database.php')
|
_db_file_path = pathlib.Path('/etc/wordpress/database.php')
|
||||||
@ -127,18 +126,17 @@ def _upgrade_config_file():
|
|||||||
@privileged
|
@privileged
|
||||||
def set_public(enable: bool):
|
def set_public(enable: bool):
|
||||||
"""Allow/disallow public access."""
|
"""Allow/disallow public access."""
|
||||||
public_access_file = pathlib.Path(PUBLIC_ACCESS_FILE)
|
|
||||||
if enable:
|
if enable:
|
||||||
public_access_file.touch()
|
_public_access_file.touch()
|
||||||
else:
|
else:
|
||||||
public_access_file.unlink(missing_ok=True)
|
_public_access_file.unlink(missing_ok=True)
|
||||||
|
|
||||||
action_utils.service_reload('apache2')
|
action_utils.service_reload('apache2')
|
||||||
|
|
||||||
|
|
||||||
def is_public() -> bool:
|
def is_public() -> bool:
|
||||||
"""Return whether public access is enabled."""
|
"""Return whether public access is enabled."""
|
||||||
return pathlib.Path(PUBLIC_ACCESS_FILE).exists()
|
return _public_access_file.exists()
|
||||||
|
|
||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
@ -177,3 +175,18 @@ def _load_augeas():
|
|||||||
aug.load()
|
aug.load()
|
||||||
|
|
||||||
return aug
|
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user