1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/calibreweb_ynh.git synced 2024-09-03 18:16:20 +02:00
calibreweb_ynh/hooks/post_user_delete
2023-08-05 14:34:54 +02:00

40 lines
No EOL
1.1 KiB
Bash

#!/bin/bash
# Source YunoHost helpers
source /usr/share/yunohost/helpers
#pour récupérer l'app_id, on prend le nom du fichier puis on retire les 3 premiers caratères
app=`basename "$0"`
app=${app:3}
source /etc/yunohost/apps/$app/scripts/_common.sh
username=$1
install_dir=$(ynh_app_setting_get $app install_dir)
del_tables_user="book_read_link remote_auth_token downloads shelf bookmark"
del_tables_shelf="book_shelf_link"
del_id() {
#$1=table
#$2=id_type
#$3=id
sqlite3 $install_dir/app.db "DELETE FROM $1 WHERE $2='$3'"
}
user_id=$(sqlite3 $install_dir/app.db "SELECT id from user WHERE name='$username'")
shelf_id=$(sqlite3 $install_dir/app.db "SELECT id from shelf WHERE user_id='$user_id'")
ynh_print_info --message="Suppression de l'utilisateur dans calibreweb"
#Delete all entry with dependencies for user
#pas de check sur l'existence de l'utilisateur car fonctionne sans
for i in $del_tables_shelf
do
del_id "$i" "shelf" $shelf_id
done
for i in $del_tables_user
do
del_id "$i" "user_id" $user_id
done
#delete user
del_id "user" "id" $user_id