FIX: be more lenient when deleting a custom emoji
This commit is contained in:
parent
dcd60dcc8f
commit
2d48caffdf
|
@ -45,13 +45,8 @@ class Admin::EmojisController < Admin::AdminController
|
|||
def destroy
|
||||
name = params.require(:id)
|
||||
|
||||
custom_emoji = CustomEmoji.find_by(name: name)
|
||||
raise Discourse::InvalidParameters unless custom_emoji
|
||||
|
||||
CustomEmoji.transaction do
|
||||
custom_emoji.upload.destroy!
|
||||
custom_emoji.destroy!
|
||||
end
|
||||
# NOTE: the upload will automatically be removed by the 'clean_up_uploads' job
|
||||
CustomEmoji.find_by(name: name)&.destroy!
|
||||
|
||||
Emoji.clear_cache
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ module Jobs
|
|||
.where("uploads.created_at < ?", grace_period.hour.ago)
|
||||
.joins("LEFT JOIN post_uploads pu ON pu.upload_id = uploads.id")
|
||||
.joins("LEFT JOIN users u ON u.uploaded_avatar_id = uploads.id")
|
||||
.joins("LEFT JOIN user_avatars ua ON (ua.gravatar_upload_id = uploads.id OR ua.custom_upload_id = uploads.id)")
|
||||
.joins("LEFT JOIN user_avatars ua ON ua.gravatar_upload_id = uploads.id OR ua.custom_upload_id = uploads.id")
|
||||
.joins("LEFT JOIN user_profiles up ON up.profile_background = uploads.url OR up.card_background = uploads.url")
|
||||
.joins("LEFT JOIN categories c ON c.uploaded_logo_id = uploads.id OR c.uploaded_background_id = uploads.id")
|
||||
.joins("LEFT JOIN custom_emojis ce ON ce.upload_id = uploads.id")
|
||||
|
@ -45,7 +45,8 @@ module Jobs
|
|||
.where("ua.gravatar_upload_id IS NULL AND ua.custom_upload_id IS NULL")
|
||||
.where("up.profile_background IS NULL AND up.card_background IS NULL")
|
||||
.where("c.uploaded_logo_id IS NULL AND c.uploaded_background_id IS NULL")
|
||||
.where("ce.upload_id IS NULL AND tf.upload_id IS NULL")
|
||||
.where("ce.upload_id IS NULL")
|
||||
.where("tf.upload_id IS NULL")
|
||||
|
||||
result = result.where("uploads.url NOT IN (?)", ignore_urls) if ignore_urls.present?
|
||||
|
||||
|
|
|
@ -59,11 +59,9 @@ class Emoji
|
|||
end
|
||||
|
||||
def self.clear_cache
|
||||
Discourse.cache.delete(cache_key("custom_emojis"))
|
||||
Discourse.cache.delete(cache_key("standard_emojis"))
|
||||
Discourse.cache.delete(cache_key("aliases_emojis"))
|
||||
Discourse.cache.delete(cache_key("all_emojis"))
|
||||
Discourse.cache.delete(cache_key("tonable_emojis"))
|
||||
%w{custom standard aliases all tonable}.each do |key|
|
||||
Discourse.cache.delete(cache_key("#{key}_emojis"))
|
||||
end
|
||||
end
|
||||
|
||||
def self.db_file
|
||||
|
|
|
@ -67,7 +67,7 @@ RSpec.describe Admin::EmojisController do
|
|||
expect do
|
||||
delete "/admin/customize/emojis/#{custom_emoji.name}.json",
|
||||
params: { name: 'test' }
|
||||
end.to change { Upload.count }.by(-1).and change { CustomEmoji.count }.by(-1)
|
||||
end.to change { CustomEmoji.count }.by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue