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 2022-05-27 16:30:45 -07:00 committed by James Valleroy
parent 25cab067d7
commit 411f42edb2
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 21 additions and 2 deletions

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)

View File

@ -48,7 +48,7 @@ class WordPressApp(app_module.App):
app_id = 'wordpress'
_version = 1
_version = 2
def __init__(self):
"""Create components for the app."""
@ -126,4 +126,5 @@ def setup(helper, old_version=None):
"""Install and configure the module."""
app.setup(old_version)
helper.call('post', actions.superuser_run, 'wordpress', ['setup'])
helper.call('post', app.enable)
if not old_version:
helper.call('post', app.enable)

View File

@ -0,0 +1,4 @@
<?php
# Do not edit this file. Manage your settings on FreedomBox.
define('FS_METHOD','direct');