rescue error when remapping permalinks

This commit is contained in:
Arpit Jalan 2017-08-28 20:43:40 +05:30
parent b83c0747d9
commit 4623b46b0b

View File

@ -451,22 +451,26 @@ task "import:remap_old_phpbb_permalinks" => :environment do
i = 0
# discussions.flightaware.com
Post.where("raw LIKE ?", "%discussions.flightaware.com%").each do |p|
new_raw = p.raw.dup
# \((https?:\/\/discussions\.flightaware\.com\/\S*-t\d+.html)\)
new_raw.gsub!(/\((https?:\/\/discussions\.flightaware\.com\/\S*-t\d+.html)\)/) do
normalized_url = Permalink.normalize_url($1)
permalink = Permalink.find_by_url(normalized_url) rescue nil
if permalink && permalink.target_url
"(#{permalink.target_url})"
else
"(#{$1})"
begin
new_raw = p.raw.dup
# \((https?:\/\/discussions\.flightaware\.com\/\S*-t\d+.html)\)
new_raw.gsub!(/\((https?:\/\/discussions\.flightaware\.com\/\S*-t\d+.html)\)/) do
normalized_url = Permalink.normalize_url($1)
permalink = Permalink.find_by_url(normalized_url) rescue nil
if permalink && permalink.target_url
"(#{permalink.target_url})"
else
"(#{$1})"
end
end
end
if new_raw != p.raw
p.revise(Discourse.system_user, { raw: new_raw }, bypass_bump: true, skip_revision: true)
putc "."
i += 1
if new_raw != p.raw
p.revise(Discourse.system_user, { raw: new_raw }, bypass_bump: true, skip_revision: true)
putc "."
i += 1
end
rescue
# skip
end
end
i