2017-05-10 18:16:57 -04:00
|
|
|
require_dependency 'upload_creator'
|
|
|
|
|
2017-02-02 04:41:57 -05:00
|
|
|
module Jobs
|
|
|
|
class MigrateCustomEmojis < Jobs::Onceoff
|
|
|
|
def execute_onceoff(args)
|
|
|
|
return if Rails.env.test?
|
|
|
|
|
2017-03-16 20:28:24 -04:00
|
|
|
Dir["#{Rails.root}/#{Emoji.base_directory}/*.{png,gif}"].each do |path|
|
|
|
|
name = File.basename(path, File.extname(path))
|
2017-02-02 04:41:57 -05:00
|
|
|
|
2017-03-16 20:28:24 -04:00
|
|
|
File.open(path) do |file|
|
2017-05-10 18:16:57 -04:00
|
|
|
upload = UploadCreator.new(
|
2017-03-16 20:28:24 -04:00
|
|
|
file,
|
|
|
|
File.basename(path),
|
2017-05-10 18:16:57 -04:00
|
|
|
type: 'custom_emoji'
|
|
|
|
).create_for(Discourse.system_user.id)
|
2017-02-02 04:41:57 -05:00
|
|
|
|
2017-03-16 20:28:24 -04:00
|
|
|
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}")
|
2017-02-02 04:41:57 -05:00
|
|
|
end
|
2017-03-16 20:28:24 -04:00
|
|
|
else
|
|
|
|
warn("Failed to create upload for '#{name}' custom emoji: #{upload.errors.full_messages}")
|
2017-02-02 04:41:57 -05:00
|
|
|
end
|
|
|
|
end
|
2017-03-16 20:28:24 -04:00
|
|
|
end
|
2017-02-02 04:41:57 -05:00
|
|
|
|
2017-03-16 20:28:24 -04:00
|
|
|
Emoji.clear_cache
|
2017-02-02 04:41:57 -05:00
|
|
|
|
2017-03-16 20:28:24 -04:00
|
|
|
Post.where("cooked LIKE '%#{Emoji.base_url}%'").find_each do |post|
|
|
|
|
post.rebake!
|
2017-02-02 04:41:57 -05:00
|
|
|
end
|
|
|
|
end
|
2017-03-16 20:28:24 -04:00
|
|
|
|
|
|
|
def warn(message)
|
|
|
|
Rails.logger.warn(message)
|
|
|
|
end
|
2017-02-02 04:41:57 -05:00
|
|
|
end
|
|
|
|
end
|