FIX: Don't migrate custom emojis that are no longer valid.

* Warn about failed migration in logs.
This commit is contained in:
Guo Xiang Tan 2017-03-17 08:28:24 +08:00
parent ad8a579c79
commit 566f367fc3

View File

@ -3,33 +3,39 @@ module Jobs
def execute_onceoff(args)
return if Rails.env.test?
CustomEmoji.transaction do
Dir["#{Rails.root}/#{Emoji.base_directory}/*.{png,gif}"].each do |path|
name = File.basename(path, File.extname(path))
Dir["#{Rails.root}/#{Emoji.base_directory}/*.{png,gif}"].each do |path|
name = File.basename(path, File.extname(path))
File.open(path) do |file|
upload = Upload.create_for(
Discourse.system_user.id,
file,
File.basename(path),
file.size,
image_type: 'custom_emoji'
)
File.open(path) do |file|
upload = Upload.create_for(
Discourse.system_user.id,
file,
File.basename(path),
file.size,
image_type: 'custom_emoji'
)
if upload.persisted?
CustomEmoji.create!(name: name, upload: upload)
else
raise "Failed to create upload for '#{name}' custom emoji"
if upload.persisted?
custom_emoji = CustomEmoji.new(name: name, upload: upload)
if !custom_emoji.save
warn("Failed to create custom emoji '#{name}': #{custom_emoji.errors.full_messages}")
end
else
warn("Failed to create upload for '#{name}' custom emoji: #{upload.errors.full_messages}")
end
end
Emoji.clear_cache
Post.where("cooked LIKE '%#{Emoji.base_url}%'").find_each do |post|
post.rebake!
end
end
Emoji.clear_cache
Post.where("cooked LIKE '%#{Emoji.base_url}%'").find_each do |post|
post.rebake!
end
end
def warn(message)
Rails.logger.warn(message)
end
end
end