Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

39 lines
1.2 KiB
Ruby

# frozen_string_literal: true
module Jobs
module DiscourseNarrativeBot
class RemapOldBotImages < ::Jobs::Onceoff
def execute_onceoff(args)
paths = [
"/images/font-awesome-link.png",
"/images/unicorn.png",
"/images/font-awesome-ellipsis.png",
"/images/font-awesome-bookmark.png",
"/images/font-awesome-smile.png",
"/images/font-awesome-flag.png",
"/images/font-awesome-search.png",
"/images/capybara-eating.gif",
"/images/font-awesome-pencil.png",
"/images/font-awesome-trash.png",
"/images/font-awesome-rotate-left.png",
"/images/font-awesome-gear.png",
]
Post.raw_match("/images/").where(user_id: -2).find_each do |post|
if (matches = post.raw.scan(/(?<!\/plugins\/discourse-narrative-bot)(#{paths.join("|")})/)).present?
new_raw = post.raw
matches.each do |match|
path = match.first
new_raw = new_raw.gsub(path, "/plugins/discourse-narrative-bot#{path}")
end
post.update_columns(raw: new_raw)
post.rebake!
end
end
end
end
end
end