s4
changeset 758:369602864de8 feature-world
Clean-up code to remove orphaned blogs and articles
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Sat, 06 Jun 2020 16:33:23 +0900 |
parents | 2d45b0478d45 |
children | 3f0ef9bb1776 |
files | s4-funcs.sh |
diffstat | 1 files changed, 24 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- a/s4-funcs.sh Sat Jun 06 16:32:45 2020 +0900 1.2 +++ b/s4-funcs.sh Sat Jun 06 16:33:23 2020 +0900 1.3 @@ -3676,6 +3676,27 @@ 1.4 [ "$ddd" ] && err "----- `gdate +%FT%T.%3N` ------------666666" 1.5 } 1.6 1.7 +clean-orphaned() { 1.8 + # This shoud be done by foreign_key rules, but some db lack them 1.9 + query<<-EOF 1.10 + -- Find blogs that have no parent 1.11 + CREATE TEMPORARY VIEW IF NOT EXISTS orphanedblog AS 1.12 + SELECT blog.id,val FROM blog JOIN blog_s bs 1.13 + ON blog.id=bs.id AND key='owner' 1.14 + WHERE val NOT IN (SELECT gname FROM grp) 1.15 + AND val NOT IN (SELECT name FROM user); 1.16 + -- Remove them 1.17 + DELETE FROM blog WHERE id IN (SELECT id FROM orphanedblog); 1.18 + 1.19 + -- Find articles that have no parent blog 1.20 + CREATE TEMPORARY VIEW IF NOT EXISTS orphanedarticle AS 1.21 + SELECT id FROM article 1.22 + WHERE blogid NOT IN (SELECT id FROM blog); 1.23 + 1.24 + -- Remove them 1.25 + DELETE FROM article WHERE id IN (SELECT id FROM orphanedarticle); 1.26 + EOF 1.27 +} 1.28 par2table() ( 1.29 # copy current parameters of par into destination table 1.30 # $1=definition-file 1.31 @@ -3730,6 +3751,9 @@ 1.32 if [ x"$rm" = x"yes" ]; then 1.33 if [ x"$rm$cfm" = x"yesyes" ]; then 1.34 query "delete from $tbl where rowid=$rowid;" 1.35 + if [ x"$tbl" = x"grp" -o x"$tbl" = x"blog" ]; then 1.36 + clean-orphaned 1.37 + fi 1.38 return 4 1.39 else 1.40 echo "消去確認のチェックがないので消さなかったの..." | html p