[php] Also patch php7.0 settings on the fly during restore

This commit is contained in:
Alexandre Aubin 2020-05-19 16:30:36 +02:00
parent b6d1bb7901
commit 73356eed75
3 changed files with 32 additions and 25 deletions

View file

@ -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 = []

View file

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

View file

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