s4

changeset 791:567980314463 feature-world

World and Migration structures refined
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 13 Jun 2020 17:31:27 +0900
parents 7ac852e8c216
children e086e07dfc9c
files examples/common/default/default.css examples/common/default/html.m4.html s4-funcs.sh s4-migrate.sh s4-newworld.sh s4-world.sh
diffstat 6 files changed, 81 insertions(+), 55 deletions(-) [+]
line diff
     1.1 --- a/examples/common/default/default.css	Sat Jun 13 17:04:29 2020 +0900
     1.2 +++ b/examples/common/default/default.css	Sat Jun 13 17:31:27 2020 +0900
     1.3 @@ -16,6 +16,7 @@
     1.4      box-shadow: #242 2px 3px 5px;
     1.5      text-shadow: #fff 0px 0px 10px;
     1.6  }
     1.7 +div.topmenu ul li.worldname {background: #eeeeff;}
     1.8  div.topmenu ul li:hover {background: #8fa;}
     1.9  div.topmenu ul a {text-decoration: none;}
    1.10  
     2.1 --- a/examples/common/default/html.m4.html	Sat Jun 13 17:04:29 2020 +0900
     2.2 +++ b/examples/common/default/html.m4.html	Sat Jun 13 17:31:27 2020 +0900
     2.3 @@ -25,10 +25,12 @@
     2.4  Members">参加者一覧</a></li>
     2.5   <li><a href="?grps" accesskey="3" title="Shortcut: 3
     2.6  Groups">グループ一覧</a></li>
     2.7 -ifdef(`_S4WORLD_',`',` <li><a href="?invite" accesskey="4" title="Shortcut: 4
     2.8 +ifdef(`_S4WORLDNAME_',`',
     2.9 +` <li><a href="?invite" accesskey="4" title="Shortcut: 4
    2.10  Invite">招待</a></li>')dnl
    2.11   <li><a href="?login" accesskey="5" title="Shortcut: 5
    2.12  Sign out">再ログイン</a></li>
    2.13   <!-- <li><a href="?userconf">userconf</a></li> -->
    2.14 +ifdef(`_S4WORLDNAME_',`<li class="worldname">@_S4WORLDNAME_</li>',`')dnl
    2.15  </ul>
    2.16  </div>
     3.1 --- a/s4-funcs.sh	Sat Jun 13 17:04:29 2020 +0900
     3.2 +++ b/s4-funcs.sh	Sat Jun 13 17:31:27 2020 +0900
     3.3 @@ -94,47 +94,16 @@
     3.4  esac
     3.5  
     3.6  # If S4MASTERDB is set, behave in another world
     3.7 -if [ -n "$S4MASTERDB" -a -s "$S4MASTERDB" ]; then
     3.8 +### if [ -n "$S4MASTERDB" -a -s "$S4MASTERDB" ]; then
     3.9 +# If S4WORLDLIST is set, this s4 have world!
    3.10 +if [ -n "$S4WORLDLIST" ]; then
    3.11    . ./s4-world.sh 2>> tmp/debug.out
    3.12 +  # Variables set in s4-world.sh
    3.13 +  #	$S4WORLDS, $S4WROLDNAME
    3.14 +  # Files created in s4-world.sh
    3.15 +  #	$worldlistfile, $worldoptionfile, $worldnamefile
    3.16 +  err S4WORLDS set to $S4WORLDS -----
    3.17  fi
    3.18 -case "$S4WORLDLIST" in
    3.19 -  *:*:*)
    3.20 -    worldlistfile=cache/worldlist
    3.21 -    worldoptionfile=cache/worldoption
    3.22 -    if [ ! -e $worldlistfile -o $worldlistfile -ot s4-config.sh \
    3.23 -	   -o ! -e $worldoptionfile -o $worldoptionfile -ot s4-config.sh \
    3.24 -	   -o s4-funcs.sh -nt $worldoptionfile ]
    3.25 -    then
    3.26 -      echo S4MASTERURL=$S4MASTERURL >> tmp/debug.out
    3.27 -      cat <<-EOF > $worldlistfile
    3.28 -	${touchpanel:+ : ▼}<div><table>
    3.29 -	 <tr><th>World List</th></tr>
    3.30 -	 <tr><td>&rArr; <a href="$S4MASTERURL">Base</a></td></tr>
    3.31 -	EOF
    3.32 -      true > $worldoptionfile
    3.33 -      for i in $S4WORLDLIST; do
    3.34 -	echo $i | {
    3.35 -	  IFS=: read name short d
    3.36 -	  cgi="s4-world-$short$cgiext"
    3.37 -	  conf="s4-config-$short.sh"
    3.38 -	  cat<<-EOF >>$worldlistfile
    3.39 -	    <tr><td title="$d">&rArr; <a href="$cgi">$name</a></td></tr>
    3.40 -		EOF
    3.41 -	  cat<<-EOF >>$worldoptionfile
    3.42 -	    <option title="$d" value="$conf">$name</option>
    3.43 -		EOF
    3.44 -	}
    3.45 -      done
    3.46 -      if [ -s "$worldoptionfile" ]; then
    3.47 -	echo "<option value=\"s4-config.sh\">Base</option>" >> $worldoptionfile
    3.48 -	echo "</table>$nl</div>" >> $worldlistfile
    3.49 -      else
    3.50 -	true > $worldoptionfile; true > $worldlistfile	# Remove contents
    3.51 -      fi
    3.52 -    fi
    3.53 -    [ -s "$worldlistfile" ] && S4WORLDS=": spaste(\`$worldlistfile')"
    3.54 -    ;;
    3.55 -esac
    3.56  
    3.57  
    3.58  [ -f ./s4-cgi.sh ] && . ./s4-cgi.sh
    3.59 @@ -492,7 +461,7 @@
    3.60  _m4() {
    3.61    #S4NAME=f,f,f
    3.62    m4 ${S4NAME:+"-D_S4NAME_=${S4NAME}"} ${S4CSS:+-D_S4CSS_="$S4CSS"} \
    3.63 -     ${S4WORLD:+-D_S4WORLD_="$S4WORLD"} \
    3.64 +     ${S4WORLDNAME:+-D_S4WORLDNAME_="$S4WORLDNAME"} \
    3.65       ${S4WORLDS:+-D_S4WORLDS_="$S4WORLDS"} "$@"
    3.66  }
    3.67  ismember() {
    3.68 @@ -2235,7 +2204,8 @@
    3.69  
    3.70    tf=$tmpd/title.$$ pf=$tmpd/profile.$$ bf=$tmpd/blogs.$$ sf=$tmpd/search.$$
    3.71    search_form "$search_form_args"	> $sf
    3.72 -  printf "%s さん%s" "$gecos" "${S4WORLD:+@$S4WORLD}" |htmlescape	> $tf
    3.73 +  printf "%s さん%s" "$gecos" "${S4WORLDNAME:+@$S4WORLDNAME}" \
    3.74 +    | htmlescape	> $tf
    3.75    { echo "<div class=\"noprofimg\">"
    3.76      viewtable $formdir/user.def user $1
    3.77      echo "</div>"
    3.78 @@ -2534,7 +2504,7 @@
    3.79    # Note that mtime is stored only in grp_s.
    3.80  ## err LE:sql.1="$sql"
    3.81    total=`query "with x as ($sql) select count(*) from x;"`
    3.82 -  echo "${entity} 一覧" "${S4WORLD:+@$S4WORLD}" | html h2
    3.83 +  echo "${entity} 一覧" "${S4WORLDNAME:+@$S4WORLDNAME}" | html h2
    3.84    echo '<div class="listentry">'		# List-entry div
    3.85    # Show owner/member filter button
    3.86    METHOD=GET
    3.87 @@ -3802,20 +3772,19 @@
    3.88    # This shoud be done by foreign_key rules, but some db lack them
    3.89    query<<-EOF
    3.90  	-- Find blogs that have no parent
    3.91 -	CREATE TEMPORARY VIEW IF NOT EXISTS orphanedblog AS
    3.92 -	SELECT blog.id,val FROM blog JOIN blog_s bs
    3.93 -	       ON blog.id=bs.id AND key='owner'
    3.94 -            WHERE val NOT IN (SELECT gname FROM grp)
    3.95 -              AND val NOT IN (SELECT name FROM user);
    3.96 -	-- Remove them
    3.97 +	WITH orphanedblog AS (
    3.98 +	  SELECT blog.id,val FROM blog JOIN blog_s bs
    3.99 +	         ON blog.id=bs.id AND key='owner'
   3.100 +              WHERE val NOT IN (SELECT gname FROM grp)
   3.101 +                AND val NOT IN (SELECT name FROM user);
   3.102 +	) -- Remove them
   3.103  	DELETE FROM blog WHERE id IN (SELECT id FROM orphanedblog);
   3.104  
   3.105  	-- Find articles that have no parent blog
   3.106 -	CREATE TEMPORARY VIEW IF NOT EXISTS orphanedarticle AS
   3.107 -	SELECT id FROM article
   3.108 -	WHERE  blogid NOT IN (SELECT id FROM blog);
   3.109 -
   3.110 -	-- Remove them
   3.111 +	WITH orphanedarticle AS (
   3.112 +	  SELECT id FROM article
   3.113 +	  WHERE  blogid NOT IN (SELECT id FROM blog);
   3.114 +	) -- Remove them
   3.115  	DELETE FROM article WHERE id IN (SELECT id FROM orphanedarticle);
   3.116  	EOF
   3.117  }
     4.1 --- a/s4-migrate.sh	Sat Jun 13 17:04:29 2020 +0900
     4.2 +++ b/s4-migrate.sh	Sat Jun 13 17:31:27 2020 +0900
     4.3 @@ -173,6 +173,7 @@
     4.4  	DELETE FROM main.grp WHERE rowid=$grid;
     4.5  	EOF
     4.6        query "END;"
     4.7 +      clean-orphaned
     4.8        echo "Done."
     4.9      else
    4.10        failure=-1
     5.1 --- a/s4-newworld.sh	Sat Jun 13 17:04:29 2020 +0900
     5.2 +++ b/s4-newworld.sh	Sat Jun 13 17:31:27 2020 +0900
     5.3 @@ -8,6 +8,7 @@
     5.4  . `dirname $0`/s4-config.sh
     5.5  if ! type htmlescape >/dev/null 2>&1; then
     5.6    . `dirname $0`/s4-funcs.sh ### > /dev/null 2>&1
     5.7 +  trap 'exit 1' INT QUIT
     5.8  fi
     5.9  dispname=$1
    5.10  shortname=$2
    5.11 @@ -80,5 +81,6 @@
    5.12  	wq
    5.13  EOF
    5.14  DB=db/$shortname.sq3 `dirname $0`/s4-init.sh
    5.15 +(S4MASTERDB=$db; db=db/$shortname.sq3; . ./s4-world.sh)
    5.16  (cd `dirname $0`; ln -s s4$cgiext s4-world-$shortname$cgiext)
    5.17  echo $newworld added
     6.1 --- a/s4-world.sh	Sat Jun 13 17:04:29 2020 +0900
     6.2 +++ b/s4-world.sh	Sat Jun 13 17:31:27 2020 +0900
     6.3 @@ -1,8 +1,59 @@
     6.4  #!/bin/sh
     6.5  
     6.6 +# Setup variables for running time
     6.7 +if $isCGI; then
     6.8 +  case "$S4WORLDLIST" in
     6.9 +    *:*:*)
    6.10 +      worldlistfile=cache/worldlist
    6.11 +      worldoptionfile=cache/worldoption
    6.12 +      worldnamefile=cache/worldname
    6.13 +      if [ ! -e $worldlistfile -o $worldlistfile -ot s4-config.sh \
    6.14 +	     -o ! -e $worldoptionfile -o $worldoptionfile -ot s4-config.sh \
    6.15 +	     -o s4-funcs.sh -nt $worldoptionfile ]
    6.16 +      then
    6.17 +	echo S4MASTERURL=$S4MASTERURL >> tmp/debug.out
    6.18 +	cat <<-EOF > $worldlistfile
    6.19 +	${touchpanel:+ : }<div><table>
    6.20 +	 <tr><th>World List</th></tr>
    6.21 +	 <tr><td>&rArr; <a href="${S4MASTERURL:-$URL}">Base</a></td></tr>
    6.22 +	EOF
    6.23 +	true > $worldoptionfile
    6.24 +	for i in $S4WORLDLIST; do
    6.25 +	  echo $i | {
    6.26 +	    IFS=: read name short d
    6.27 +	    cgi="s4-world-$short$cgiext"
    6.28 +	    conf="s4-config-$short.sh"
    6.29 +	    cat<<-EOF >>$worldlistfile
    6.30 +	    <tr><td title="$d">&rArr; <a href="$cgi">$name</a></td></tr>
    6.31 +		EOF
    6.32 +	    cat<<-EOF >>$worldoptionfile
    6.33 +	    <option title="$d" value="$conf">$name</option>
    6.34 +		EOF
    6.35 +	    echo "$name" > $worldnamefile.$short
    6.36 +	  }
    6.37 +	done
    6.38 +	if [ -s "$worldoptionfile" ]; then
    6.39 +	  echo "<option value=\"s4-config.sh\">Base</option>" >> $worldoptionfile
    6.40 +	  echo "</table>$nl</div>" >> $worldlistfile
    6.41 +	else
    6.42 +	  true > $worldoptionfile; true > $worldlistfile	# Remove contents
    6.43 +	  rm -f ${worldnamefile}.*
    6.44 +	fi
    6.45 +      fi
    6.46 +      if [ -s "$worldlistfile" ]; then
    6.47 +	S4WORLDS=": spaste(\`$worldlistfile')"
    6.48 +	S4WORLDNAME=${S4WORLD:+`cat $worldnamefile.$S4WORLD`}
    6.49 +      fi
    6.50 +      ;;
    6.51 +  esac
    6.52 +fi
    6.53 +
    6.54 +err "db=$db mas=$S4MASTERDB sessdb=$sessdb"
    6.55 +# If in parent world, no need to do rest of jobs
    6.56  if [ -z "$S4MASTERDB" -o ! -s "$S4MASTERDB" ]; then
    6.57    return
    6.58  fi
    6.59 +# Confim child
    6.60  if [ "$db" -ef "$S4MASTERDB" ]; then
    6.61    return		# Points to the same file
    6.62  fi
    6.63 @@ -26,7 +77,6 @@
    6.64  
    6.65  ## sqlite3 -cmd '.timer 1' -cmd '.echo 1' $db <<EOF
    6.66  err "Starting account synchronization"
    6.67 -err "db=$db mas=$S4MASTERDB sessdb=$sessdb"
    6.68  # num=$(sqlite3 -bail -cmd 'PRAGMA FOREIGN_KEYS=on' $db <<EOF
    6.69  cat > tmp/sql <<EOF
    6.70  ATTACH DATABASE "$S4MASTERDB" AS m;
    6.71 @@ -70,4 +120,5 @@
    6.72  if [ $num -eq 0 ]; then
    6.73    touch $syncflag
    6.74  fi
    6.75 +err "Account synchronization done in difference $num"
    6.76  return $num