diff --git a/README.md b/README.md
index 3d118bc..97b9774 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
Online learning platform
-**Shipped version:** 3.11.2~ynh1
+**Shipped version:** 3.11.4~ynh1
**Demo:** https://sandbox.moodledemo.net/
diff --git a/README_fr.md b/README_fr.md
index e4c9a51..9abe1e1 100644
--- a/README_fr.md
+++ b/README_fr.md
@@ -13,7 +13,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour
Plateforme d'apprentissage en ligne
-**Version incluse :** 3.11.2~ynh1
+**Version incluse :** 3.11.4~ynh1
**Démo :** https://sandbox.moodledemo.net/
diff --git a/check_process b/check_process
index 671162b..c516ac6 100644
--- a/check_process
+++ b/check_process
@@ -3,6 +3,7 @@
domain="domain.tld"
path="/path"
admin="john"
+ site_name="Moodle"
is_public=1
; Checks
pkg_linter=1
@@ -12,14 +13,15 @@
setup_private=1
setup_public=1
upgrade=1
- # 3.10.2~ynh1
- upgrade=1 from_commit=499ac857a9e80bbf56c93e448086e84e09e97ac6
+ # 3.11.1~ynh1
+ upgrade=1 from_commit=b2abcd9cefa16e5c5e0e6963a92ebc961be12d1a
backup_restore=1
multi_instance=1
- change_url=0
+ change_url=1
;;; Options
Email=
Notification=none
;;; Upgrade options
- ; commit=499ac857a9e80bbf56c93e448086e84e09e97ac6
- name=3.10.2~ynh1
\ No newline at end of file
+ ; commit=b2abcd9cefa16e5c5e0e6963a92ebc961be12d1a
+ name=3.11.1~ynh1
+
\ No newline at end of file
diff --git a/conf/app.src b/conf/app.src
index 734f5be..406eb53 100644
--- a/conf/app.src
+++ b/conf/app.src
@@ -1,5 +1,5 @@
-SOURCE_URL=https://github.com/moodle/moodle/archive/v3.11.2.zip
-SOURCE_SUM=b4ad9b8243ce55fc28d592dd43d734bf7949b6a10e8b936e2a85644c087012f8
+SOURCE_URL=https://github.com/moodle/moodle/archive/v3.11.4.zip
+SOURCE_SUM=9893c7095b86de4a68c48b21a22116d09ee5040bc5582265d843119b5c8683c8
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=zip
SOURCE_IN_SUBDIR=true
diff --git a/conf/config-domain.php b/conf/config-domain.php
new file mode 100644
index 0000000..63e132d
--- /dev/null
+++ b/conf/config-domain.php
@@ -0,0 +1,29 @@
+dbtype = 'pgsql';
+$CFG->dblibrary = 'native';
+$CFG->dbhost = 'localhost';
+$CFG->dbname = '__DB_NAME__';
+$CFG->dbuser = '__DB_NAME__';
+$CFG->dbpass = '__DB_PWD__';
+$CFG->prefix = 'mdl_';
+$CFG->dboptions = array(
+ 'dbpersist' => 0,
+ 'dbsocket' => '',
+ 'dbport' => '',
+);
+
+$CFG->wwwroot = 'https://__DOMAIN__';
+$CFG->dataroot = '__DATA_PATH__';
+$CFG->admin = 'admin';
+
+$CFG->directorypermissions = 02777;
+
+require_once(__DIR__ . '/lib/setup.php'); // Do not edit
+
+// There is no php closing tag in this file,
+// it is intentional because it prevents trailing whitespace problems!
\ No newline at end of file
diff --git a/conf/config-path.php b/conf/config-path.php
new file mode 100644
index 0000000..1980bf3
--- /dev/null
+++ b/conf/config-path.php
@@ -0,0 +1,29 @@
+dbtype = 'pgsql';
+$CFG->dblibrary = 'native';
+$CFG->dbhost = 'localhost';
+$CFG->dbname = '__DB_NAME__';
+$CFG->dbuser = '__DB_NAME__';
+$CFG->dbpass = '__DB_PWD__';
+$CFG->prefix = 'mdl_';
+$CFG->dboptions = array(
+ 'dbpersist' => 0,
+ 'dbsocket' => '',
+ 'dbport' => '',
+);
+
+$CFG->wwwroot = 'https://__DOMAIN____PATH__';
+$CFG->dataroot = '__DATA_PATH__';
+$CFG->admin = 'admin';
+
+$CFG->directorypermissions = 02777;
+
+require_once(__DIR__ . '/lib/setup.php'); // Do not edit
+
+// There is no php closing tag in this file,
+// it is intentional because it prevents trailing whitespace problems!
\ No newline at end of file
diff --git a/conf/cron b/conf/cron
index 777ceb2..f8d4277 100644
--- a/conf/cron
+++ b/conf/cron
@@ -1 +1 @@
-*/15 * * * * __USER__ /usr/bin/php__PHPVERSION__ -f __FINALPATH__/admin/cli/cron.php
+*/15 * * * * __APP__ /usr/bin/php__PHPVERSION__ -f __FINALPATH__/admin/cli/cron.php >/dev/null
diff --git a/conf/nginx.conf b/conf/nginx.conf
index 4a8cbd0..bce5fb3 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -4,16 +4,12 @@ location __PATH__/ {
# Path to source
alias __FINALPATH__/ ;
- # Force usage of https
- if ($scheme = http) {
- rewrite ^ https://$server_name$request_uri? permanent;
- }
-
index index.php;
client_max_body_size 1G;
- try_files $uri $uri/ index.php;
+ try_files $uri $uri/ __PATH__/__PATH__/index.php?$query_string;
+
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock;
diff --git a/config_panel.toml b/config_panel.toml
new file mode 100644
index 0000000..d6d68fe
--- /dev/null
+++ b/config_panel.toml
@@ -0,0 +1,25 @@
+version = "1.0"
+
+[main]
+name = "Moodle configuration"
+
+ [main.php_fpm_config]
+ name = "PHP-FPM configuration"
+
+ [main.php_fpm_config.fpm_footprint]
+ ask = "Memory footprint of the service?"
+ choices = ["low", "medium", "high", "specific"]
+ default = "low"
+ help = "low <= 20Mb per pool. medium between 20Mb and 40Mb per pool. high > 40Mb per pool.
Use specific to set a value with the following option."
+
+ [main.php_fpm_config.free_footprint]
+ ask = "Memory footprint of the service?"
+ type = "number"
+ default = "0"
+ help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values."
+
+ [main.php_fpm_config.fpm_usage]
+ ask = "Expected usage of the service?"
+ choices = ["low", "medium", "high"]
+ default = "low"
+ help = "low: Personal usage, behind the sso. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding."
diff --git a/manifest.json b/manifest.json
index 74ccb14..be56902 100644
--- a/manifest.json
+++ b/manifest.json
@@ -6,7 +6,7 @@
"en": "Online learning platform",
"fr": "Plateforme d'apprentissage en ligne"
},
- "version": "3.11.2~ynh1",
+ "version": "3.11.4~ynh1",
"url": "https://moodle.org/",
"upstream": {
"license": "GPL-3.0-or-later",
@@ -21,7 +21,7 @@
"email": "anmol@datamol.org"
},
"requirements": {
- "yunohost": ">= 4.2.4"
+ "yunohost": ">= 4.3.0"
},
"multi_instance": true,
"services": [
@@ -32,8 +32,7 @@
"install" : [
{
"name": "domain",
- "type": "domain",
- "example": "example.com"
+ "type": "domain"
},
{
"name": "path",
@@ -43,9 +42,18 @@
},
{
"name": "admin",
- "type": "user",
- "example": "johndoe"
- },
+ "type": "user"
+ },
+ {
+ "name": "site_name",
+ "type": "string",
+ "ask": {
+ "en": "Choose a name for the site you want to create",
+ "fr": "Choisissez un nom pour le site que vous voulez créer"
+ },
+ "default": "moodle",
+ "example": "moodle"
+ },
{
"name": "is_public",
"type": "boolean",
diff --git a/scripts/_common.sh b/scripts/_common.sh
index 3730b16..f158759 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -9,7 +9,7 @@ pkg_dependencies="postgresql"
YNH_PHP_VERSION="7.3"
-extra_php_dependencies="php${YNH_PHP_VERSION}-common php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-xmlrpc php${YNH_PHP_VERSION}-soap php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-intl php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-pgsql php${YNH_PHP_VERSION}-ldap"
+pkg_dependencies="postgresql php${YNH_PHP_VERSION}-common php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-xmlrpc php${YNH_PHP_VERSION}-soap php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-intl php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-pgsql php${YNH_PHP_VERSION}-ldap"
#=================================================
# PERSONAL HELPERS
diff --git a/scripts/change_url b/scripts/change_url
new file mode 100644
index 0000000..8fd855b
--- /dev/null
+++ b/scripts/change_url
@@ -0,0 +1,128 @@
+#!/bin/bash
+
+#=================================================
+# GENERIC STARTING
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
+
+source _common.sh
+source /usr/share/yunohost/helpers
+
+#=================================================
+# RETRIEVE ARGUMENTS
+#=================================================
+
+old_domain=$YNH_APP_OLD_DOMAIN
+old_path=$YNH_APP_OLD_PATH
+
+new_domain=$YNH_APP_NEW_DOMAIN
+new_path=$YNH_APP_NEW_PATH
+
+app=$YNH_APP_INSTANCE_NAME
+
+#=================================================
+# LOAD SETTINGS
+#=================================================
+ynh_script_progression --message="Loading installation settings..." --weight=1
+
+final_path=$(ynh_app_setting_get --app=$app --key=final_path)
+data_path=$(ynh_app_setting_get --app=$app --key=data_path)
+db_name=$(ynh_app_setting_get --app=$app --key=db_name)
+db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
+
+#=================================================
+# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
+#=================================================
+ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
+
+# Backup the current version of the app
+ynh_backup_before_upgrade
+ynh_clean_setup () {
+ # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
+ ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
+
+ # Restore it if the upgrade fails
+ ynh_restore_upgradebackup
+}
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
+#=================================================
+# CHECK WHICH PARTS SHOULD BE CHANGED
+#=================================================
+
+change_domain=0
+if [ "$old_domain" != "$new_domain" ]
+then
+ change_domain=1
+fi
+
+change_path=0
+if [ "$old_path" != "$new_path" ]
+then
+ change_path=1
+fi
+
+#=================================================
+# MODIFY URL IN NGINX CONF
+#=================================================
+ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
+
+nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
+
+# Change the path in the NGINX config file
+if [ $change_path -eq 1 ]
+then
+ # Make a backup of the original NGINX config file if modified
+ ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
+ # Set global variables for NGINX helper
+ domain="$old_domain"
+ path_url="$new_path"
+ # Create a dedicated NGINX config
+ ynh_add_nginx_config
+fi
+
+# Change the domain for NGINX
+if [ $change_domain -eq 1 ]
+then
+ # Delete file checksum for the old conf file location
+ ynh_delete_file_checksum --file="$nginx_conf_path"
+ mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
+ # Store file checksum for the new config file location
+ ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
+fi
+
+#=================================================
+# UPGRADE A CONFIGURATION
+#=================================================
+ynh_script_progression --message="Updating a configuration file..." --weight=1
+
+domain=${new_domain%/}
+path=${new_path%/}
+dir="__DIR__"
+
+# if [ "$new_path" == "/" ]; then
+# ynh_replace_string --match_string="\$CFG->wwwroot = .*" --replace_string="\$CFG->wwwroot = \'https:\/\/${new_domain%\/}\';" --target_file="$final_path/config.php"
+# else
+# ynh_replace_string --match_string="\$CFG->wwwroot = .*" --replace_string="\$CFG->wwwroot = \'https:\/\/${new_domain}${new_path%\/}\';" --target_file="$final_path/config.php"
+# fi
+
+if [ "$new_path" == "/" ]; then
+ ynh_add_config --template="../conf/config-domain.php" --destination="$final_path/config.php"
+else
+ ynh_add_config --template="../conf/config-path.php" --destination="$final_path/config.php"
+fi
+
+#=================================================
+# RELOAD NGINX
+#=================================================
+ynh_script_progression --message="Reloading NGINX web server..." --weight=1
+
+ynh_systemd_action --service_name=nginx --action=reload
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_script_progression --message="Change of URL completed for $app" --last
diff --git a/scripts/config b/scripts/config
new file mode 100644
index 0000000..3440bd2
--- /dev/null
+++ b/scripts/config
@@ -0,0 +1,95 @@
+#!/bin/bash
+
+#=================================================
+# GENERIC STARTING
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
+
+source _common.sh
+source /usr/share/yunohost/helpers
+
+ynh_abort_if_errors
+
+#=================================================
+# RETRIEVE ARGUMENTS
+#=================================================
+
+phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
+current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
+
+#=================================================
+# SPECIFIC GETTERS FOR TOML SHORT KEY
+#=================================================
+
+get__fpm_footprint() {
+ # Free footprint value for php-fpm
+ # Check if current_fpm_footprint is an integer
+ if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null
+ then
+ echo "specific"
+ else
+ echo "$current_fpm_footprint"
+ fi
+}
+
+get__free_footprint() {
+ # Free footprint value for php-fpm
+ # Check if current_fpm_footprint is an integer
+ if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null
+ then
+ # If current_fpm_footprint is an integer, that's a numeric value for the footprint
+ echo "$current_fpm_footprint"
+ else
+ echo "0"
+ fi
+}
+
+#=================================================
+# SPECIFIC SETTERS FOR TOML SHORT KEYS
+#=================================================
+
+set__fpm_footprint() {
+ if [ "$fpm_footprint" != "specific" ]
+ then
+ ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint"
+ fi
+}
+
+set__free_footprint() {
+ if [ "$fpm_footprint" = "specific" ]
+ then
+ ynh_app_setting_set --app=$app --key=fpm_footprint --value="$free_footprint"
+ fi
+}
+
+#=================================================
+# GENERIC FINALIZATION
+#=================================================
+
+ynh_app_config_validate() {
+ _ynh_app_config_validate
+
+ if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[free_footprint]}" == "true" ]; then
+ # If fpm_footprint is set to 'specific', use $free_footprint value.
+ if [ "$fpm_footprint" = "specific" ]
+ then
+ fpm_footprint=$free_footprint
+ fi
+
+ if [ "$fpm_footprint" == "0" ]
+ then
+ ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below."
+
+ exit 0
+ fi
+ fi
+}
+
+ynh_app_config_apply() {
+ _ynh_app_config_apply
+
+ ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint
+}
+
+ynh_app_config_run $1
diff --git a/scripts/install b/scripts/install
index 1da150a..893f8d4 100644
--- a/scripts/install
+++ b/scripts/install
@@ -24,6 +24,7 @@ domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
+site_name=$YNH_APP_ARG_SITE_NAME
email=$(ynh_user_get_info --username=$admin --key=mail)
password=$(ynh_string_random --length=30)
@@ -48,6 +49,7 @@ ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
+ynh_app_setting_set --app=$app --key=site_name --value=$site_name
#=================================================
# STANDARD MODIFICATIONS
@@ -89,10 +91,6 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
-chmod 750 "$final_path"
-chmod -R o-rwx "$final_path"
-chown -R $app:www-data "$final_path"
-
#=================================================
# NGINX CONFIGURATION
#=================================================
@@ -107,7 +105,7 @@ ynh_add_nginx_config
ynh_script_progression --message="Configuring PHP-FPM..." --weight=1
# Create a dedicated php-fpm config
-ynh_add_fpm_config --package="$extra_php_dependencies"
+ynh_add_fpm_config --usage=low --footprint=low
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================
@@ -127,9 +125,9 @@ chown -R $app:www-data "$data_path"
#=================================================
# SETUP APPLICATION
#=================================================
-ynh_script_progression --message="Setting up the application..." --weight=190
+ynh_script_progression --message="Setting up the application..." --weight=19
-ynh_exec_as $app php${phpversion} "$final_path/admin/cli/install.php" --wwwroot="https://$domain${path_url%/}" --dataroot="$data_path" --dbtype='pgsql' --dbname="$db_name" --dbuser="$db_name" --dbpass="$db_pwd" --adminuser="$admin" --adminpass="$password" --adminemail="$email" --fullname="YunoHost" --shortname="YNH" --non-interactive --agree-license
+php${phpversion} "$final_path/admin/cli/install.php" --wwwroot="https://${domain}${path_url%/}" --dataroot="$data_path" --dbtype='pgsql' --dbname="$db_name" --dbuser="$db_name" --dbpass="$db_pwd" --adminuser="$admin" --adminpass="$password" --adminemail="$email" --fullname="$site_name" --shortname="$site_name" --non-interactive --agree-license
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.php"
@@ -152,7 +150,11 @@ ynh_psql_execute_as_root --database="$db_name" --sql="UPDATE public.mdl_config_p
# The admin is an ldap user
ynh_psql_execute_as_root --database="$db_name" --sql="UPDATE public.mdl_user SET auth='ldap' WHERE username='$admin';"
-ynh_exec_as $app php$phpversion "$final_path/admin/cli/purge_caches.php"
+php$phpversion "$final_path/admin/cli/purge_caches.php"
+
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:www-data "$final_path"
#=================================================
# ADD CRON JOB
diff --git a/scripts/remove b/scripts/remove
index 2c7cc30..502e9a4 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -48,6 +48,17 @@ ynh_script_progression --message="Removing Moodle main directory..." --weight=2
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
+#=================================================
+# REMOVE DATA DIR
+#=================================================
+
+# Remove the data directory if --purge option is used
+if [ "${YNH_APP_PURGE:-0}" -eq 1 ]
+then
+ ynh_script_progression --message="Removing app data directory..." --weight=1
+ ynh_secure_remove --file="$data_path"
+fi
+
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
diff --git a/scripts/restore b/scripts/restore
index 9d1d15d..7e66aaa 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -31,15 +31,15 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
+fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
+fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
+
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
-ynh_webpath_available --domain=$domain --path_url=$path_url \
- || ynh_die --message="Path not available: ${domain}${path_url}"
-test ! -d $final_path \
- || ynh_die --message="There is already a directory: $final_path "
+test ! -d $final_path || ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
@@ -90,8 +90,8 @@ ynh_script_progression --message="Restoring PHP-FPM configuration..." --weight=1
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
-# Recreate a dedicated PHP-FPM config
-ynh_add_fpm_config --package="$extra_php_dependencies"
+# Recreate a dedicated php-fpm config
+ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --phpversion=$phpversion
#=================================================
# SPECIFIC RESTORATION
@@ -120,6 +120,8 @@ ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./d
ynh_script_progression --message="Restoring the cron file..." --weight=3
ynh_restore_file --origin_path="/etc/cron.d/$app"
+chown root: "/etc/cron.d/$app"
+chmod 644 "/etc/cron.d/$app"
#=================================================
# GENERIC FINALIZATION
diff --git a/scripts/upgrade b/scripts/upgrade
index 8526cc8..c15d324 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -22,6 +22,11 @@ admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
+site_name=$(ynh_app_setting_get --app=$app --key=site_name)
+phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
+
+fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
+fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
#=================================================
# CHECK VERSION
@@ -29,6 +34,20 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name)
upgrade_type=$(ynh_check_app_version_changed)
+#=================================================
+# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
+#=================================================
+ynh_script_progression --message="Backing up Moodle before upgrading (may take a while)..." --weight=10
+
+# Backup the current version of the app
+ynh_backup_before_upgrade
+ynh_clean_setup () {
+ # restore it if the upgrade fails
+ ynh_restore_upgradebackup
+}
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@@ -39,6 +58,24 @@ if [ -z "$admin" ]; then
ynh_die --message="This app can't be upgraded from a very old version of the package. Please remove and reinstall Moodle"
fi
+# If the site_name is not defined
+if [ -z "$site_name" ]; then
+ site_name="YunoHost"
+ ynh_app_setting_set --app=$app --key=site_name --value=$site_name
+fi
+
+# If fpm_footprint doesn't exist, create it
+if [ -z "$fpm_footprint" ]; then
+ fpm_footprint=low
+ ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
+fi
+
+# If fpm_usage doesn't exist, create it
+if [ -z "$fpm_usage" ]; then
+ fpm_usage=low
+ ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
+fi
+
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
@@ -46,20 +83,6 @@ if ynh_legacy_permissions_exists; then
ynh_app_setting_delete --app=$app --key=is_public
fi
-#=================================================
-# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
-#=================================================
-ynh_script_progression --message="Backing up Moodle before upgrading (may take a while)..." --weight=30
-
-# Backup the current version of the app
-ynh_backup_before_upgrade
-ynh_clean_setup () {
- # restore it if the upgrade fails
- ynh_restore_upgradebackup
-}
-# Exit if an error occurs during the execution of the script
-ynh_abort_if_errors
-
#=================================================
# CREATE DEDICATED USER
#=================================================
@@ -78,29 +101,11 @@ if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=6
-# Create a temporary directory
- tmpdir="$(mktemp -d)"
-
- # Backup the config file in the temp dir
- cp -a "$final_path/config.php" "$tmpdir/config.php"
-
- # Remove the app directory securely
- ynh_secure_remove --file="$final_path"
-
# Download, check integrity, uncompress and patch the source from app.src
- ynh_setup_source --dest_dir="$final_path"
-
- # Copy the admin saved settings from tmp directory to final path
- cp -a "$tmpdir/config.php" "$final_path/config.php"
-
- # Remove the tmp directory securely
- ynh_secure_remove --file="$tmpdir"
+ ynh_setup_source --dest_dir="$final_path" --keep="$final_path/config.php"
+ #php${phpversion} $final_path/admin/cli/upgrade.php
fi
-chmod 750 "$final_path"
-chmod -R o-rwx "$final_path"
-chown -R $app:www-data "$final_path"
-
#=================================================
# NGINX CONFIGURATION
#=================================================
@@ -122,20 +127,7 @@ ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
# Create a dedicated PHP-FPM config
-ynh_add_fpm_config --package="$extra_php_dependencies"
-phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
-
-#=================================================
-# UPGRADING THE APPLICATION
-#=================================================
-# ynh_script_progression --message="Upgrading the application..." --weight=1
-
-# ynh_backup_if_checksum_is_different --file="$final_path/config.php"
-
-# ynh_exec_as $app php${phpversion} "$final_path/admin/cli/upgrade.php" --non-interactive
-
-# # Recalculate and store the checksum of the file for the next upgrade.
-# ynh_store_file_checksum --file="$final_path/config.php"
+ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint
#=================================================
# ACTIVATE LDAP SUPPORT
@@ -155,7 +147,11 @@ ynh_psql_execute_as_root --database="$db_name" --sql="UPDATE public.mdl_config_p
# The admin is an ldap user
ynh_psql_execute_as_root --database="$db_name" --sql="UPDATE public.mdl_user SET auth='ldap' WHERE username='$admin';"
-ynh_exec_as $app php${phpversion} "$final_path/admin/cli/purge_caches.php"
+php${phpversion} "$final_path/admin/cli/purge_caches.php"
+
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:www-data "$final_path"
#=================================================
# ADD CRON JOB
@@ -166,8 +162,6 @@ ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
-chown -R $app:www-data "$final_path"
-
#=================================================
# RELOAD NGINX
#=================================================