From d705a35246dc58bcbf3763a291a24e6c1755339a Mon Sep 17 00:00:00 2001 From: anmol26s Date: Mon, 8 Oct 2018 01:01:25 +0530 Subject: [PATCH] enhancement:Added mysql database --- README.md | 2 +- conf/.env | 4 ++-- manifest.json | 2 +- scripts/backup | 7 +++++++ scripts/install | 22 ++++++++++++++++++++++ scripts/remove | 9 +++++++++ scripts/restore | 9 +++++++++ scripts/upgrade | 6 ++++++ 8 files changed, 57 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8597754..8330d8c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Integration level](https://dash.yunohost.org/integration/kimai2.svg)](https://ci-apps.yunohost.org/jenkins/job/kimai2%20%28Community%29/lastBuild/consoleFull) [![Install kimai2 with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=kimai2)
-Shipped Version: **0.4 (pre-release)** +Shipped Version: **0.5 (pre-release)** **Please note that this app will install PHP 7.2** diff --git a/conf/.env b/conf/.env index 552faa8..c28ff3a 100644 --- a/conf/.env +++ b/conf/.env @@ -17,8 +17,8 @@ APP_SECRET=__RANDOM_KEY__ # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data/kimai.sqlite" # Configure your db driver and server_version in config/packages/doctrine.yaml -# DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name -DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/kimai.sqlite +DATABASE_URL=mysql://__DB_USER__:__DB_PASSWORD__@127.0.0.1:3306/__DB_NAME__ +# DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/kimai.sqlite ###< doctrine/doctrine-bundle ### ###> symfony/swiftmailer-bundle ### diff --git a/manifest.json b/manifest.json index 3a707f2..44d3e66 100644 --- a/manifest.json +++ b/manifest.json @@ -7,7 +7,7 @@ "fr": "Kimai2 de package d’application pour YunoHost.", "de": "Kimai 2 Paket für YunoHost." }, - "version": "0.4", + "version": "0.5", "url": "https://v2.kimai.org", "license": "free", "maintainer": { diff --git a/scripts/backup b/scripts/backup index 508a672..03a55a0 100755 --- a/scripts/backup +++ b/scripts/backup @@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get $app final_path) domain=$(ynh_app_setting_get $app domain) +db_name=$(ynh_app_setting_get $app db_name) #================================================= # STANDARD BACKUP STEPS @@ -50,3 +51,9 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup "/etc/php/7.2/fpm/pool.d/$app.conf" +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= + +ynh_mysql_dump_db "$db_name" > db.sql + diff --git a/scripts/install b/scripts/install index 65335a6..a5bbf31 100755 --- a/scripts/install +++ b/scripts/install @@ -26,6 +26,7 @@ admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC admin_pass=$(ynh_string_random 24) random_key=$(ynh_string_random 32) +registration="true" # This is a multi-instance app, meaning it can be installed several times independently @@ -64,6 +65,7 @@ ynh_app_setting_set $app path $path_url ynh_app_setting_set $app admin $admin ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app random_key $random_key +ynh_app_setting_set $app registration $registration #================================================= # STANDARD MODIFICATIONS @@ -73,6 +75,22 @@ ynh_app_setting_set $app random_key $random_key ynh_install_php7 +#================================================= +# CREATE A MYSQL DATABASE +#================================================= + +### Use these lines if you need a database for the application. +### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. +### The password will be stored as 'mysqlpwd' into the app settings, +### and will be available as $db_pwd +### If you're not using these lines: +### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script +### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script +### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script + +db_name=$(ynh_sanitize_dbid $app) +ynh_app_setting_set $app db_name $db_name +ynh_mysql_setup_db $db_name $db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -123,6 +141,10 @@ sudo cp ../conf/.env $final_path/.env #================================================= ynh_replace_string "__RANDOM_KEY__" "$random_key" "$final_path/.env" ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env" +ynh_replace_string "__DB_PASSWORD__" "$db_pwd" "$final_path/.env" +ynh_replace_string "__DB_USER__" "$db_name" "$final_path/.env" +ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/.env" + init_composer $final_path diff --git a/scripts/remove b/scripts/remove index 8c3f5a7..4842c46 100755 --- a/scripts/remove +++ b/scripts/remove @@ -17,6 +17,8 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) final_path=$(ynh_app_setting_get $app final_path) +db_name=$(ynh_app_setting_get $app db_name) +db_user=$db_name #================================================= # STANDARD REMOVE @@ -37,6 +39,13 @@ ynh_secure_remove "$final_path" # Remove the dedicated nginx config ynh_remove_nginx_config +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= + +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db $db_user $db_name + #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= diff --git a/scripts/restore b/scripts/restore index 67a6fb3..9946dfe 100755 --- a/scripts/restore +++ b/scripts/restore @@ -30,6 +30,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get $app final_path) +db_name=$(ynh_app_setting_get $app db_name) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -61,6 +62,14 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file "$final_path" +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= + +db_pwd=$(ynh_app_setting_get $app mysqlpwd) +ynh_mysql_setup_db $db_name $db_name $db_pwd +ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql + #================================================= # RECREATE THE DEDICATED USER #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 0781dee..e749549 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,6 +21,9 @@ admin=$(ynh_app_setting_get $app admin) is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) random_key=$(ynh_app_setting_get $app random_key) +db_name=$(ynh_app_setting_get $app db_name) +db_pwd=$(ynh_app_setting_get $app mysqlpwd) + #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -119,6 +122,9 @@ sudo cp ../conf/.env $final_path/.env #================================================= ynh_replace_string "__RANDOM_KEY__" "$random_key" "$final_path/.env" ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env" +ynh_replace_string "__DB_PASSWORD__" "$db_pwd" "$final_path/.env" +ynh_replace_string "__DB_USER__" "$db_name" "$final_path/.env" +ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/.env" init_composer $final_path (