Mercurial > hgrepos > hgweb.cgi > s4
changeset 824:fcf485cbabc6
At migration, translate direct-link to attachment files
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Sat, 20 Jun 2020 18:18:17 +0900 |
parents | ab6bb3efd40e |
children | e9817a71f332 |
files | s4-migrate.sh |
diffstat | 1 files changed, 29 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/s4-migrate.sh Fri Jun 19 15:32:57 2020 +0900 +++ b/s4-migrate.sh Sat Jun 20 18:18:17 2020 +0900 @@ -166,9 +166,36 @@ | unhexize | sed -Ef "$sedfile2" | hexize` echo "UPDATE dst.article_s SET val=X'$newval' WHERE rowid=$arid;" >>$sql done - echo "URL rewriting done." - echo -n "Removing the group in the old world..." + # Rewrite showattc Direct-Links + attclinks=$( + query <<-EOF + SELECT group_concat(rowid, ',') FROM dst.article_s + WHERE key='text' AND val LIKE '%?showattc+article_m+%' + AND id IN (SELECT id FROM article WHERE blogid IN ($blogs)); + EOF + ) + if [ -n "$attclinks" ]; then + err attclinks=$attclinks + sedfile3=${sedfile}3 + query <<-EOF > $sedfile3 + WITH attctrans AS ( + SELECT s.rowid srcarid, d.rowid dstarid + FROM main.article_m s NATURAL JOIN dst.article_m d + WHERE d.id IN (SELECT id FROM dst.article + WHERE blogid IN ($blogs)) + ) SELECT printf('s/(\?showattc\+article_m)\+%s($|[^0-9])/\1+%s\2/g', + srcarid, dstarid) + FROM attctrans; + EOF + echo $attclinks | tr , '\n' | while read arid; do + newval=`query "SELECT hex(val) FROM dst.article_s WHERE rowid=$arid;" \ + | unhexize | sed -Ef "$sedfile3" | hexize` + echo "UPDATE dst.article_s SET val=X'$newval' WHERE rowid=$arid;" + done >> $sql + fi if [ -z "`query \".read $sql\"`" ]; then + echo "URL rewriting done." + echo -n "Removing the group in the old world..." query <<-EOF SAVEPOINT rmgroup; DELETE FROM main.article WHERE blogid IN ($blogs);