FIX: Handle BBCode in migrate_to_s3 task as well.

This commit is contained in:
Guo Xiang Tan 2019-03-22 16:21:43 +08:00
parent eec7822d7c
commit 19c3c25db1
3 changed files with 17 additions and 2 deletions

View File

@ -56,8 +56,6 @@ class DbHelper
"#{column} IS NOT NULL AND #{column} #{match} :pattern"
end.join(" OR ")
puts pattern, replacement, flags, match
DB.exec(<<~SQL, pattern: pattern, replacement: replacement, flags: flags, match: match)
UPDATE #{table}
SET #{set}

View File

@ -367,6 +367,13 @@ def migrate_to_s3
DbHelper.regexp_replace(from, to)
# BBCode images
from = "\\[img\\]/uploads/#{db}/original/(\\dX/(?:[a-f0-9]/)*[a-f0-9]{40}[a-z0-9\\.]*)\\[/img\\]"
to = "[img]#{SiteSetting.Upload.s3_base_url}/#{prefix}\\1[/img]"
DbHelper.regexp_replace(from, to)
# Legacy inline image format
Post.where("raw LIKE '%![](/uploads/default/original/%)%'").each do |post|
regexp = /!\[\](\/uploads\/#{db}\/original\/(\dX\/(?:[a-f0-9]\/)*[a-f0-9]{40}[a-z0-9\.]*))/

View File

@ -41,4 +41,14 @@ RSpec.describe DbHelper do
expect(post.reload.cooked).to eq('test')
end
end
describe ".regexp_replace" do
it "should remap columns correctly" do
post = Fabricate(:post, raw: "this is a [img]test[/img] post")
DbHelper.regexp_replace("\\[img\\]test\\[/img\\]", "[img]something[/img]")
expect(post.reload.raw).to include("[img]something[/img]")
end
end
end