From 73356eed75033762eb28e3aff1ff1290f01fff13 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 19 May 2020 16:30:36 +0200 Subject: [PATCH] [php] Also patch php7.0 settings on the fly during restore --- src/yunohost/app.py | 21 +++++++++++++++ src/yunohost/backup.py | 9 ++++++- .../0016_php70_to_php73_pools.py | 27 +++---------------- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index b198ab3b3..00472744f 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -2884,6 +2884,7 @@ LEGACY_PHP_VERSION_REPLACEMENTS = [ ('"$phpversion" == "7.0"', '$(bc <<< "$phpversion >= 7.3") -eq 1') # patch ynh_install_php to refuse installing/removing php <= 7.3 ] + def _patch_legacy_php_versions(app_folder): files_to_patch = [] @@ -2906,6 +2907,26 @@ def _patch_legacy_php_versions(app_folder): os.system(c) +def _patch_legacy_php_versions_in_settings(app_folder): + + settings = read_yaml(os.path.join(app_folder, 'settings.yml')) + + if settings.get("fpm_config_dir") == "/etc/php/7.0/fpm": + settings["fpm_config_dir"] = "/etc/php/7.3/fpm" + if settings.get("fpm_service") == "php7.0-fpm": + settings["fpm_service"] = "php7.3-fpm" + if settings.get("phpversion") == "7.0": + settings["phpversion"] = "7.3" + + # We delete these checksums otherwise the file will appear as manually modified + list_to_remove = ["checksum__etc_php_7.0_fpm_pool", + "checksum__etc_nginx_conf.d"] + settings = {k: v for k, v in settings.items() + if not any(k.startswith(to_remove) for to_remove in list_to_remove)} + + write_to_yaml(app_folder + '/settings.yml', settings) + + def _patch_legacy_helpers(app_folder): files_to_patch = [] diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 8ba8f2610..4b55ee83d 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -43,7 +43,13 @@ from moulinette.utils.log import getActionLogger from moulinette.utils.filesystem import read_file, mkdir, write_to_yaml, read_yaml from yunohost.app import ( - app_info, _is_installed, _parse_app_instance_name, _patch_legacy_php_versions, dump_app_log_extract_for_debugging, _patch_legacy_helpers, LEGACY_PHP_VERSION_REPLACEMENTS + app_info, _is_installed, + _parse_app_instance_name, + dump_app_log_extract_for_debugging, + _patch_legacy_helpers, + _patch_legacy_php_versions, + _patch_legacy_php_versions_in_settings, + LEGACY_PHP_VERSION_REPLACEMENTS ) from yunohost.hook import ( hook_list, hook_info, hook_callback, hook_exec, CUSTOM_HOOK_FOLDER @@ -1329,6 +1335,7 @@ class RestoreManager(): # Apply dirty patch to make php5 apps compatible with php7 _patch_legacy_php_versions(app_settings_in_archive) + _patch_legacy_php_versions_in_settings(app_settings_in_archive) # Delete _common.sh file in backup common_file = os.path.join(app_backup_in_archive, '_common.sh') diff --git a/src/yunohost/data_migrations/0016_php70_to_php73_pools.py b/src/yunohost/data_migrations/0016_php70_to_php73_pools.py index fa2e04a4a..1cdb2bc4d 100644 --- a/src/yunohost/data_migrations/0016_php70_to_php73_pools.py +++ b/src/yunohost/data_migrations/0016_php70_to_php73_pools.py @@ -4,7 +4,7 @@ from shutil import copy2 from moulinette.utils.log import getActionLogger -from yunohost.app import _is_installed, _get_app_settings, _set_app_settings +from yunohost.app import _is_installed, _get_app_settings, _set_app_settings, _patch_legacy_php_versions_in_settings from yunohost.tools import Migration from yunohost.service import _run_service_command @@ -52,7 +52,8 @@ class MyMigration(Migration): os.system(c) app_id = os.path.basename(f)[:-len(".conf")] - self.migrate_app_settings(app_id) + if _is_installed(app_id): + _patch_legacy_php_versions_in_settings("/etc/yunohost/apps/%s/" % app_id) nginx_conf_files = glob.glob("/etc/nginx/conf.d/*.d/%s.conf" % app_id) for f in nginx_conf_files: @@ -70,25 +71,3 @@ class MyMigration(Migration): # Reload nginx _run_service_command("reload", "nginx") - - def migrate_app_settings(self, app_id): - - if not _is_installed(app_id): - return - - settings = _get_app_settings(app_id) - - if settings.get("fpm_config_dir") == "/etc/php/7.0/fpm": - settings["fpm_config_dir"] = "/etc/php/7.3/fpm" - if settings.get("fpm_service") == "php7.0-fpm": - settings["fpm_service"] = "php7.3-fpm" - if settings.get("phpversion") == "7.0": - settings["phpversion"] = "7.3" - - # We delete these checksums otherwise the file will appear as manually modified - list_to_remove = ["checksum__etc_php_7.0_fpm_pool", - "checksum__etc_nginx_conf.d"] - settings = {k: v for k, v in settings.items() - if not any(k.startswith(to_remove) for to_remove in list_to_remove)} - - _set_app_settings(app_id, settings)