# HG changeset patch # User HIROSE Yuuji # Date 1592644697 -32400 # Node ID fcf485cbabc685b62cdfa2f1a9539c9ab88facc4 # Parent ab6bb3efd40e426cb659bd616268368503f99277 At migration, translate direct-link to attachment files diff -r ab6bb3efd40e -r fcf485cbabc6 s4-migrate.sh --- 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);