wordpress: Allow installing/updating plugins and themes

Based on work by Benedek Nagy at:
https://salsa.debian.org/freedombox-team/freedombox/-/merge_requests/2198

Tests:

- Install WordPress without this patch. Then switch to code with this patch.
Restart FreedomBox. WordPress setup should get executed and the setup version
should get incremented to 2. The configuration file should contain the include
line for freedombox-static.php. freedombox-static.php should be installed and
should contain the line for setting FS_METHOD to 'direct'.

- Uninstall WordPress and wipe everything. Install WordPress freshly using this
patch. The line to include freedombox-static.php should be present in the
default configuration file. freedombox-static.php should be installed and should
contain the line for setting FS_METHOD to 'direct'.

- Installing a new theme using a URL and setting the default theme to the new
theme should work.

- Installing a plugin and enabling it should work.

- Installing an older version of a plugin and then updating it should work.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2022-06-01 10:26:56 -04:00
1 parent 25cab067d7
commit 411f42edb2
3 files changed
+21 -2

No files matched your search

+14
View File
@@ -18,6 +18,7 @@ from plinth import action_utils
from plinth.modules.wordpress import PUBLIC_ACCESS_FILE
_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')
_db_backup_file = pathlib.Path(
'/var/lib/plinth/backups-data/wordpress-database.sql')
@@ -48,6 +49,9 @@ def parse_arguments():
def subcommand_setup(_):
"""Create initial configuration and database for WordPress."""
if _db_file_path.exists() or _config_file_path.exists():
if _config_file_path.exists():
_upgrade_config_file()
return
db_password = _generate_secret_key(16)
@@ -63,6 +67,7 @@ def _create_config_file(db_host, db_name, db_user, db_password):
config_contents = f'''<?php
# Created by FreedomBox
include_once('{_static_config_file_path}');
include_once('{_db_file_path}');
define('DB_NAME', $dbname);
define('DB_USER', $dbuser);
@@ -130,6 +135,15 @@ def _generate_secret_key(length=64, chars=None):
return ''.join(rand.choice(chars) for _ in range(length))
def _upgrade_config_file():
"""Upgrade existing config file to add changes."""
include_line = f"include_once('{_static_config_file_path}');"
lines = _config_file_path.read_text(encoding='utf-8').splitlines()
if include_line not in lines:
lines.insert(2, include_line) # Insert on 3rd line
_config_file_path.write_text('\n'.join(lines), encoding='utf-8')
def subcommand_set_public(arguments):
"""Allow/disallow public access."""
public_access_file = pathlib.Path(PUBLIC_ACCESS_FILE)