mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Add onceoff job to remap bot images link.
https://meta.discourse.org/t/discobot-tutorial-broken-elipsis-and-bookmark-png-images-appear-to-be-missing-on-my-site/73294/12
This commit is contained in:
parent
8970bdd4fa
commit
442d4bff85
@ -0,0 +1,36 @@
|
|||||||
|
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
|
@ -19,6 +19,7 @@ after_initialize do
|
|||||||
'../jobs/narrative_init.rb',
|
'../jobs/narrative_init.rb',
|
||||||
'../jobs/send_default_welcome_message.rb',
|
'../jobs/send_default_welcome_message.rb',
|
||||||
'../jobs/onceoff/grant_badges.rb',
|
'../jobs/onceoff/grant_badges.rb',
|
||||||
|
'../jobs/onceoff/remap_old_bot_images.rb',
|
||||||
'../lib/discourse_narrative_bot/actions.rb',
|
'../lib/discourse_narrative_bot/actions.rb',
|
||||||
'../lib/discourse_narrative_bot/base.rb',
|
'../lib/discourse_narrative_bot/base.rb',
|
||||||
'../lib/discourse_narrative_bot/new_user_narrative.rb',
|
'../lib/discourse_narrative_bot/new_user_narrative.rb',
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Jobs::DiscourseNarrativeBot::RemapOldBotImages do
|
||||||
|
context "when bot's post contains an old link" do
|
||||||
|
let(:post) do
|
||||||
|
Fabricate(:post,
|
||||||
|
user_id: -2,
|
||||||
|
raw: 'If you’d like to learn more, select <img src="/images/font-awesome-gear.png" width="16" height="16"> <img src="/images/font-awesome-ellipsis.png" width="16" height="16"> below and <img src="/images/font-awesome-bookmark.png" width="16" height="16"> **bookmark this private message**. If you do, there may be a :gift: in your future!'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
post
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should remap the links correctly' do
|
||||||
|
expected_raw = 'If you’d like to learn more, select <img src="/plugins/discourse-narrative-bot/images/font-awesome-gear.png" width="16" height="16"> <img src="/plugins/discourse-narrative-bot/images/font-awesome-ellipsis.png" width="16" height="16"> below and <img src="/plugins/discourse-narrative-bot/images/font-awesome-bookmark.png" width="16" height="16"> **bookmark this private message**. If you do, there may be a :gift: in your future!'
|
||||||
|
|
||||||
|
2.times do
|
||||||
|
described_class.new.execute_onceoff({})
|
||||||
|
expect(post.reload.raw).to eq(expected_raw)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'subfolder' do
|
||||||
|
let(:post) do
|
||||||
|
Fabricate(:post,
|
||||||
|
user_id: -2,
|
||||||
|
raw: 'If you’d like to learn more, select <img src="/community/images/font-awesome-ellipsis.png" width="16" height="16"> below and <img src="/community/images/font-awesome-bookmark.png" width="16" height="16"> **bookmark this private message**. If you do, there may be a :gift: in your future!'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should remap the links correctly' do
|
||||||
|
described_class.new.execute_onceoff({})
|
||||||
|
|
||||||
|
expect(post.reload.raw).to eq(
|
||||||
|
'If you’d like to learn more, select <img src="/community/plugins/discourse-narrative-bot/images/font-awesome-ellipsis.png" width="16" height="16"> below and <img src="/community/plugins/discourse-narrative-bot/images/font-awesome-bookmark.png" width="16" height="16"> **bookmark this private message**. If you do, there may be a :gift: in your future!'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user